Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced WMS configuration by the possibilitiy to configure supported request #835

Merged
merged 10 commits into from
Jul 6, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,24 @@

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.services.wfs.encoding;
package org.deegree.services.encoding;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.deegree.protocol.wfs.WFSRequestType;

/**
* {@link SupportedEncodings} implementation with limited encodings.
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz</a>
*/
public class LimitedSupportedEncodings implements SupportedEncodings {
public class LimitedSupportedEncodings<E extends Enum> implements SupportedEncodings<E> {

private final Map<WFSRequestType, Set<String>> enabledEncodingsPerRequestType = new HashMap<WFSRequestType, Set<String>>();
private final Map<E, Set<String>> enabledEncodingsPerRequestType = new HashMap<E, Set<String>>();

/**
* Instantiate a new {@link LimitedSupportedEncodings} instance, by default all encodings are disabled! Add enabled
* encodings by {@link LimitedSupportedEncodings#addEnabledEncodings(WFSRequestType, List)}.
* encodings by {@link LimitedSupportedEncodings#addEnabledEncodings(E, Set)}.
*/
public LimitedSupportedEncodings() {
}
Expand All @@ -67,12 +64,12 @@ public LimitedSupportedEncodings() {
* a list of encodings enabled for the request type. May be empty (all encodings are disabled), but never
* <code>null</code>.
*/
public void addEnabledEncodings( WFSRequestType requestType, Set<String> enabledEncodingsPerRequestType ) {
public void addEnabledEncodings( E requestType, Set<String> enabledEncodingsPerRequestType ) {
this.getEnabledEncodingsPerRequestType().put( requestType, enabledEncodingsPerRequestType );
}

@Override
public boolean isEncodingSupported( WFSRequestType requestType, String encoding ) {
public boolean isEncodingSupported( E requestType, String encoding ) {
if ( getEnabledEncodingsPerRequestType().containsKey( requestType ) ) {
Set<String> enabledEncodings = getEnabledEncodingsPerRequestType().get( requestType );
for ( String enabledEncoding : enabledEncodings ) {
Expand All @@ -86,7 +83,7 @@ public boolean isEncodingSupported( WFSRequestType requestType, String encoding
/**
* @return the enabled encodings, never <code>null</code>
*/
public Map<WFSRequestType, Set<String>> getEnabledEncodingsPerRequestType() {
public Map<E, Set<String>> getEnabledEncodingsPerRequestType() {
return enabledEncodingsPerRequestType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.services.wfs.encoding;

import org.deegree.protocol.wfs.WFSRequestType;
package org.deegree.services.encoding;

/**
* Encapsulates informations about supported encodings.
Expand All @@ -45,7 +43,7 @@
*
* @version $Revision: $, $Date: $
*/
public interface SupportedEncodings {
public interface SupportedEncodings<E extends Enum> {

/**
* Checks if an encoding is supported by a request type.
Expand All @@ -56,6 +54,6 @@ public interface SupportedEncodings {
* never <code>null</code>
* @return <code>true</code> if the passed encoding is supported for the request type, <code>false</code> otherwise
*/
boolean isEncodingSupported( WFSRequestType requestType, String encoding );
boolean isEncodingSupported( E requestType, String encoding );

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.services.wfs.encoding;

import org.deegree.protocol.wfs.WFSRequestType;
package org.deegree.services.encoding;

/**
* {@link SupportedEncodings} implementation supporting all encodings.
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz</a>
*/
public class UnlimitedSupportedEncodings implements SupportedEncodings {
public class UnlimitedSupportedEncodings<E extends Enum> implements SupportedEncodings<E> {

@Override
public boolean isEncodingSupported( WFSRequestType requestType, String encoding ) {
public boolean isEncodingSupported( E requestType, String encoding ) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.services.wfs.encoding;
package org.deegree.services.encoding;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.deegree.protocol.wfs.WFSRequestType.CreateStoredQuery;
import static org.deegree.protocol.wfs.WFSRequestType.DescribeFeatureType;
import static org.deegree.protocol.wfs.WFSRequestType.GetCapabilities;
import static org.deegree.protocol.wfs.WFSRequestType.GetFeatureWithLock;
import static org.deegree.services.encoding.LimitedSupportedEncodingsTest.RequestType.CreateStoredQuery;
import static org.deegree.services.encoding.LimitedSupportedEncodingsTest.RequestType.DescribeFeatureType;
import static org.deegree.services.encoding.LimitedSupportedEncodingsTest.RequestType.GetCapabilities;
import static org.deegree.services.encoding.LimitedSupportedEncodingsTest.RequestType.GetFeatureWithLock;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -86,4 +86,8 @@ private LimitedSupportedEncodings prepareLimitedSupportedEncodings() {
return limitedSupportedEncodings;
}

enum RequestType {
GetCapabilities, GetFeatureWithLock, DescribeFeatureType, CreateStoredQuery
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
import org.deegree.protocol.ows.getcapabilities.GetCapabilities;
import org.deegree.protocol.wfs.WFSRequestType;
import org.deegree.services.controller.OGCFrontController;
import org.deegree.services.encoding.SupportedEncodings;
import org.deegree.services.metadata.OWSMetadataProvider;
import org.deegree.services.ows.capabilities.OWSCapabilitiesXMLAdapter;
import org.deegree.services.wfs.encoding.SupportedEncodings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
import org.deegree.services.controller.OGCFrontController;
import org.deegree.services.controller.exception.serializer.XMLExceptionSerializer;
import org.deegree.services.controller.utils.HttpResponseBuffer;
import org.deegree.services.encoding.LimitedSupportedEncodings;
import org.deegree.services.encoding.SupportedEncodings;
import org.deegree.services.encoding.UnlimitedSupportedEncodings;
import org.deegree.services.i18n.Messages;
import org.deegree.services.jaxb.controller.DeegreeServiceControllerType;
import org.deegree.services.jaxb.metadata.DeegreeServicesMetadataType;
Expand All @@ -136,9 +139,6 @@
import org.deegree.services.ows.OWS100ExceptionReportSerializer;
import org.deegree.services.ows.OWS110ExceptionReportSerializer;
import org.deegree.services.ows.PreOWSExceptionReportSerializer;
import org.deegree.services.wfs.encoding.LimitedSupportedEncodings;
import org.deegree.services.wfs.encoding.SupportedEncodings;
import org.deegree.services.wfs.encoding.UnlimitedSupportedEncodings;
import org.deegree.services.wfs.format.Format;
import org.deegree.services.wfs.query.StoredQueryHandler;
import org.deegree.workspace.ResourceIdentifier;
Expand Down Expand Up @@ -358,7 +358,7 @@ private LimitedSupportedEncodings parseEncodings( SupportedRequests supportedReq
}

private LimitedSupportedEncodings parseEncodingWithSupportedEncodings( List<String> supportedEncodingsForAllRequestTypes ) {
LimitedSupportedEncodings limitedSupportedEncodings = new LimitedSupportedEncodings();
LimitedSupportedEncodings<WFSRequestType> limitedSupportedEncodings = new LimitedSupportedEncodings();
limitedSupportedEncodings.addEnabledEncodings( CreateStoredQuery,
collectEnabledEncodings( supportedEncodingsForAllRequestTypes ) );
limitedSupportedEncodings.addEnabledEncodings( DescribeFeatureType,
Expand Down Expand Up @@ -388,7 +388,7 @@ private LimitedSupportedEncodings parseEncodingWithSupportedEncodings( List<Stri

private LimitedSupportedEncodings parseEncodingsWithSpecifiedRequestTypes( SupportedRequests supportedRequests,
List<String> supportedEncodingsForAllRequestTypes ) {
LimitedSupportedEncodings limitedSupportedEncodings = new LimitedSupportedEncodings();
LimitedSupportedEncodings<WFSRequestType> limitedSupportedEncodings = new LimitedSupportedEncodings();
limitedSupportedEncodings.addEnabledEncodings( CreateStoredQuery,
collectEnabledEncodings( supportedRequests.getCreateStoredQuery(),
supportedEncodingsForAllRequestTypes ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
import java.util.Set;

import org.deegree.protocol.wfs.WFSRequestType;
import org.deegree.services.encoding.LimitedSupportedEncodings;
import org.deegree.services.encoding.SupportedEncodings;
import org.deegree.services.encoding.UnlimitedSupportedEncodings;
import org.deegree.services.jaxb.wfs.DeegreeWFS;
import org.deegree.services.jaxb.wfs.DeegreeWFS.SupportedRequests;
import org.deegree.services.jaxb.wfs.RequestType;
import org.deegree.services.wfs.encoding.LimitedSupportedEncodings;
import org.deegree.services.wfs.encoding.SupportedEncodings;
import org.deegree.services.wfs.encoding.UnlimitedSupportedEncodings;
import org.hamcrest.BaseMatcher;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import org.deegree.services.controller.exception.serializer.XMLExceptionSerializer;
import org.deegree.services.controller.utils.HttpResponseBuffer;
import org.deegree.services.controller.utils.StandardFeatureInfoContext;
import org.deegree.services.encoding.SupportedEncodings;
import org.deegree.services.jaxb.controller.DeegreeServiceControllerType;
import org.deegree.services.jaxb.metadata.DeegreeServicesMetadataType;
import org.deegree.services.jaxb.wms.DeegreeWMS;
Expand All @@ -161,6 +162,7 @@
import org.deegree.services.wms.controller.plugins.ImageSerializer;
import org.deegree.services.wms.controller.plugins.OutputFormatProvider;
import org.deegree.services.wms.utils.GetMapLimitChecker;
import org.deegree.services.wms.utils.SupportedEncodingsParser;
import org.deegree.style.StyleRef;
import org.deegree.style.utils.ColorQuantizer;
import org.deegree.workspace.ResourceInitException;
Expand Down Expand Up @@ -214,6 +216,8 @@ public class WMSController extends AbstractOWS {

private final GetMapLimitChecker getMapLimitChecker = new GetMapLimitChecker();

private SupportedEncodings supportedEncodings;

public WMSController( ResourceMetadata<OWS> metadata, Workspace workspace, DeegreeWMS jaxbConfig ) {
super( metadata, workspace, jaxbConfig );
capabilitiesManager = new CapabilitiesManager( isAddCapabilitiesDefaultFormatsEnabled( jaxbConfig ) );
Expand Down Expand Up @@ -319,6 +323,8 @@ public void init( DeegreeServicesMetadataType serviceMetadata, DeegreeServiceCon

String configId = getMetadata().getIdentifier().getId();
metadataProvider = workspace.getResource( OWSMetadataProviderProvider.class, configId + "_metadata" );

supportedEncodings = new SupportedEncodingsParser().parseEncodings( conf );
} catch ( Exception e ) {
throw new ResourceInitException( e.getMessage(), e );
}
Expand All @@ -336,11 +342,11 @@ public void doKVP( Map<String, String> map, HttpServletRequest request, HttpResp
Version version = v == null ? highestVersion : Version.parseVersion( v );

WMSRequestType req;
String requestName = map.get( "REQUEST" );
try {
req = (WMSRequestType) ( (ImplementationMetadata<?>) ( (OWSProvider) getMetadata().getProvider() ).getImplementationMetadata() ).getRequestTypeByName( map.get( "REQUEST" ) );
req = (WMSRequestType) ( (ImplementationMetadata<?>) ( (OWSProvider) getMetadata().getProvider() ).getImplementationMetadata() ).getRequestTypeByName( requestName );
} catch ( IllegalArgumentException e ) {
controllers.get( version ).sendException( new OWSException( get( "WMS.OPERATION_NOT_KNOWN",
map.get( "REQUEST" ) ),
controllers.get( version ).sendException( new OWSException( get( "WMS.OPERATION_NOT_KNOWN", requestName ),
OWSException.OPERATION_NOT_SUPPORTED ),
response, this );
return;
Expand All @@ -350,8 +356,11 @@ public void doKVP( Map<String, String> map, HttpServletRequest request, HttpResp
response, this );
return;
}

try {
if ( !supportedEncodings.isEncodingSupported( req, "KVP" ) ) {
throw new OWSException( "GET/KVP is not supported for " + requestName + " requests.",
OWSException.OPERATION_NOT_SUPPORTED );
}
handleRequest( req, response, map, version );
} catch ( OWSException e ) {
if ( controllers.get( version ) == null ) {
Expand Down Expand Up @@ -578,6 +587,12 @@ public void doXML( XMLStreamReader xmlStream, HttpServletRequest request, HttpRe
try {
String requestName = xmlStream.getLocalName();
WMSRequestType requestType = detectWmsRequestType( requestName );

if ( !supportedEncodings.isEncodingSupported( requestType, "XML" ) ) {
throw new OWSException( "POST/XML is not supported for " + requestName + " requests.",
OWSException.OPERATION_NOT_SUPPORTED );
}

requestVersion = parseAndCheckVersion( xmlStream );

switch ( requestType ) {
Expand Down Expand Up @@ -628,6 +643,12 @@ public void doSOAP( org.apache.axiom.soap.SOAPEnvelope soapDoc, HttpServletReque

String requestName = xmlStream.getLocalName();
WMSRequestType requestType = detectWmsRequestType( requestName );

if ( !supportedEncodings.isEncodingSupported( requestType, "SOAP" ) ) {
throw new OWSException( "POST/SOAP is not supported for " + requestName + " requests.",
OWSException.OPERATION_NOT_SUPPORTED );
}

requestVersion = parseAndCheckVersion( xmlStream );

if ( WMSRequestType.GetMap.equals( requestType ) ) {
Expand Down Expand Up @@ -754,6 +775,13 @@ public CapabilitiesManager getCapabilitiesManager() {
return capabilitiesManager;
}

/**
* @return the supported encodings configured in the DeegreeWMS, should not be <code>null</code>
*/
public SupportedEncodings getSupportedEncodings(){
return supportedEncodings;
}

public FeatureInfoManager getFeatureInfoManager() {
return featureInfoManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void writeCapability( XMLStreamWriter writer )
writer.writeEndElement();

writeExtendedCapabilities( writer );
soapExtendedCapabilitesWriter.writeSoapWmsExtendedCapabilites( writer, postUrl );
soapExtendedCapabilitesWriter.writeSoapWmsExtendedCapabilites( writer, postUrl, controller.getSupportedEncodings() );

writeThemes( writer, service.getThemes() );

Expand Down
Loading