Search in sources :

Example 1 with Decoder

use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.

the class JSONBinding method parseRequest.

private OwsServiceRequest parseRequest(HttpServletRequest request) throws OwsExceptionReport {
    try {
        JsonNode json = Json.loadReader(request.getReader());
        if (LOG.isDebugEnabled()) {
            LOG.debug("JSON-REQUEST: {}", Json.print(json));
        }
        OperationDecoderKey key = new OperationDecoderKey(json.path(SERVICE).textValue(), json.path(VERSION).textValue(), json.path(REQUEST).textValue(), MediaTypes.APPLICATION_JSON);
        Decoder<OwsServiceRequest, JsonNode> decoder = getDecoder(key);
        if (decoder == null) {
            NoDecoderForKeyException cause = new NoDecoderForKeyException(key);
            throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
        }
        OwsServiceRequest sosRequest;
        try {
            sosRequest = decoder.decode(json);
        } catch (OwsDecodingException ex) {
            throw ex.getCause();
        } catch (DecodingException ex) {
            throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
        sosRequest.setRequestContext(getRequestContext(request));
        return sosRequest;
    } catch (IOException ioe) {
        throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while reading request! Message: %s", ioe.getMessage());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) IOException(java.io.IOException) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey)

Example 2 with Decoder

use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.

the class KvpBinding method parseRequest.

protected OwsServiceRequest parseRequest(HttpServletRequest req) throws OwsExceptionReport {
    if (req.getParameterMap() == null || req.getParameterMap().isEmpty()) {
        throw new MissingRequestParameterException();
    }
    Map<String, String> parameters = Streams.stream(req.getParameterNames()).collect(toMap(name -> name.replace("amp;", "").toLowerCase(Locale.ROOT), req::getParameter));
    String service = parameters.get(RequestParams.service.name());
    String version = parameters.get(RequestParams.version.name());
    String operation = parameters.get(RequestParams.request.name());
    if (Strings.isNullOrEmpty(service)) {
        throw new MissingServiceParameterException();
    }
    if (!isServiceSupported(service)) {
        throw new InvalidServiceParameterException(service);
    }
    if (Strings.isNullOrEmpty(operation)) {
        throw new MissingRequestParameterException();
    }
    if (version != null && !isVersionSupported(service, version)) {
        throw new VersionNotSupportedException();
    }
    Decoder<OwsServiceRequest, Map<String, String>> decoder = getDecoder(new OperationDecoderKey(service, version, operation, MediaTypes.APPLICATION_KVP));
    if (decoder == null) {
        throw new OperationNotSupportedException(operation);
    }
    OwsServiceRequest request;
    try {
        request = decoder.decode(parameters);
    } catch (OwsDecodingException ex) {
        throw ex.getCause();
    } catch (DecodingException ex) {
        throw toOwsExceptionReport(ex);
    }
    if (this.includeOriginalRequest) {
        request.setOriginalRequest(String.join("?", req.getRequestURL(), req.getQueryString()));
    }
    return request;
}
Also used : MediaTypes(org.n52.janmayen.http.MediaTypes) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) Decoder(org.n52.svalbard.decode.Decoder) HTTPException(org.n52.iceland.exception.HTTPException) LoggerFactory(org.slf4j.LoggerFactory) MediaType(org.n52.janmayen.http.MediaType) SosConstants(org.n52.shetland.ogc.sos.SosConstants) LocationHintException(org.n52.janmayen.exception.LocationHintException) Strings(com.google.common.base.Strings) HttpServletRequest(javax.servlet.http.HttpServletRequest) Collectors.toMap(java.util.stream.Collectors.toMap) Locale(java.util.Locale) Map(java.util.Map) Collector(java.util.stream.Collector) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse) MediaTypeBindingKey(org.n52.iceland.binding.MediaTypeBindingKey) SimpleBinding(org.n52.iceland.binding.SimpleBinding) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) CompositeException(org.n52.janmayen.exception.CompositeException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) OperationNotSupportedException(org.n52.shetland.ogc.ows.exception.OperationNotSupportedException) Set(java.util.Set) Setting(org.n52.faroe.annotation.Setting) IOException(java.io.IOException) MiscSettings(org.n52.iceland.service.MiscSettings) BindingKey(org.n52.iceland.binding.BindingKey) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) MissingRequestParameterException(org.n52.iceland.exception.ows.concrete.MissingRequestParameterException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) InvalidServiceParameterException(org.n52.iceland.exception.ows.concrete.InvalidServiceParameterException) ConformanceClasses(org.n52.svalbard.ConformanceClasses) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) Streams(org.n52.janmayen.stream.Streams) VersionNotSupportedException(org.n52.iceland.exception.ows.concrete.VersionNotSupportedException) Configurable(org.n52.faroe.annotation.Configurable) CompositeOwsException(org.n52.shetland.ogc.ows.exception.CompositeOwsException) Collections(java.util.Collections) RequestParams(org.n52.shetland.ogc.ows.OWSConstants.RequestParams) MissingServiceParameterException(org.n52.shetland.ogc.ows.exception.MissingServiceParameterException) OperationNotSupportedException(org.n52.shetland.ogc.ows.exception.OperationNotSupportedException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) InvalidServiceParameterException(org.n52.iceland.exception.ows.concrete.InvalidServiceParameterException) MissingRequestParameterException(org.n52.iceland.exception.ows.concrete.MissingRequestParameterException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) VersionNotSupportedException(org.n52.iceland.exception.ows.concrete.VersionNotSupportedException) MissingServiceParameterException(org.n52.shetland.ogc.ows.exception.MissingServiceParameterException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey)

Example 3 with Decoder

use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.

the class AbstractXmlBinding method decode.

protected T decode(HttpServletRequest request) throws OwsExceptionReport {
    String characterEncoding = getCharacterEncoding(request);
    String xmlString = xmlToString(request, characterEncoding);
    LOGGER.debug("XML-REQUEST: {}", xmlString);
    DecoderKey key = getDecoderKey(xmlString, characterEncoding);
    LOGGER.trace("Found decoder key: {}", key);
    Decoder<T, String> decoder = getDecoder(key);
    if (decoder == null) {
        // if this a GetCapabilities request, then the service is not supported
        String opOrType = null;
        Optional<String> service = Optional.empty();
        if (key instanceof XmlNamespaceOperationDecoderKey) {
            XmlNamespaceOperationDecoderKey xmlNamespaceKey = (XmlNamespaceOperationDecoderKey) key;
            opOrType = xmlNamespaceKey.getType();
        } else if (key instanceof XmlStringOperationDecoderKey) {
            XmlStringOperationDecoderKey xmlStringKey = (XmlStringOperationDecoderKey) key;
            opOrType = xmlStringKey.getOperation();
            service = Optional.of(xmlStringKey.getService());
        }
        if (OWSConstants.Operations.GetCapabilities.toString().equalsIgnoreCase(opOrType)) {
            if (service.isPresent()) {
                throw new InvalidParameterValueException(OWSConstants.GetCapabilitiesParams.service, service.get()).withMessage("The service '%s' is not supported.", service);
            } else {
                throw new MissingParameterValueException(OWSConstants.GetCapabilitiesParams.service).withMessage("The parameter '%s' is missing.", OWSConstants.GetCapabilitiesParams.service);
            }
        } else {
            throw new InvalidParameterValueException().withMessage("No decoder found for incoming message " + "based on derived decoder key: %s\nMessage: %s", key, xmlString);
        }
    } else {
        LOGGER.trace("Using decoder: {}", decoder);
    }
    try {
        return decoder.decode(xmlString);
    } catch (OwsDecodingException ex) {
        throw ex.getCause();
    } catch (DecodingException ex) {
        throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
    }
}
Also used : XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) MissingParameterValueException(org.n52.shetland.ogc.ows.exception.MissingParameterValueException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DecoderKey(org.n52.svalbard.decode.DecoderKey) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey) XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey)

Example 4 with Decoder

use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.

the class BatchRequestDecodingTest method before.

@Before
public void before() throws DecodingException {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new BatchRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    InsertSensorRequestDecoder insertSensorRequestDecoder = new InsertSensorRequestDecoder();
    insertSensorRequestDecoder.setDecoderRepository(decoderRepository);
    InsertObservationRequestDecoder insertObservationRequestDecoder = new InsertObservationRequestDecoder();
    insertObservationRequestDecoder.setDecoderRepository(decoderRepository);
    SensorMLDecoderV101 sensorMLDecoder = new SensorMLDecoderV101();
    sensorMLDecoder.setXmlOptions(XmlOptions::new);
    sensorMLDecoder.setDecoderRepository(decoderRepository);
    SweCommonDecoderV101 sweCommonDecoder = new SweCommonDecoderV101();
    sweCommonDecoder.setXmlOptions(XmlOptions::new);
    sweCommonDecoder.setDecoderRepository(decoderRepository);
    GmlDecoderv311 gmlDecoderv311 = new GmlDecoderv311();
    ObservationDecoder observationDecoder = new ObservationDecoder();
    observationDecoder.setDecoderRepository(decoderRepository);
    InsertResultTemplateRequestDecoder insertResultTemplateRequestDecoder = new InsertResultTemplateRequestDecoder();
    insertResultTemplateRequestDecoder.setDecoderRepository(decoderRepository);
    InsertResultRequestDecoder insertResultRequestDecoder = new InsertResultRequestDecoder();
    insertResultRequestDecoder.setDecoderRepository(decoderRepository);
    FieldDecoder fieldDecoder = new FieldDecoder();
    fieldDecoder.setDecoderRepository(decoderRepository);
    decoderRepository.setDecoders(Arrays.asList(decoder, insertSensorRequestDecoder, insertObservationRequestDecoder, insertResultTemplateRequestDecoder, insertResultRequestDecoder, sensorMLDecoder, sweCommonDecoder, observationDecoder, fieldDecoder, gmlDecoderv311));
    decoderRepository.init();
    this.request = decoder.decodeJSON(json, true);
}
Also used : InsertResultTemplateRequestDecoder(org.n52.svalbard.decode.json.InsertResultTemplateRequestDecoder) SensorMLDecoderV101(org.n52.svalbard.decode.SensorMLDecoderV101) BatchRequestDecoder(org.n52.svalbard.decode.json.BatchRequestDecoder) SweCommonDecoderV101(org.n52.svalbard.decode.SweCommonDecoderV101) InsertResultRequestDecoder(org.n52.svalbard.decode.json.InsertResultRequestDecoder) XmlOptions(org.apache.xmlbeans.XmlOptions) ObservationDecoder(org.n52.svalbard.decode.json.ObservationDecoder) InsertSensorRequestDecoder(org.n52.svalbard.decode.json.InsertSensorRequestDecoder) InsertObservationRequestDecoder(org.n52.svalbard.decode.json.InsertObservationRequestDecoder) DecoderRepository(org.n52.svalbard.decode.DecoderRepository) FieldDecoder(org.n52.svalbard.decode.json.FieldDecoder) GmlDecoderv311(org.n52.svalbard.decode.GmlDecoderv311) Before(org.junit.Before)

Example 5 with Decoder

use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.

the class GetObservationRequestDecoderTest method before.

@Before
public void before() {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new GetObservationRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    SpatialFilterDecoder spatialFilterDecoder = new SpatialFilterDecoder();
    spatialFilterDecoder.setDecoderRepository(decoderRepository);
    TemporalFilterDecoder temporalFilterDecoder = new TemporalFilterDecoder();
    temporalFilterDecoder.setDecoderRepository(decoderRepository);
    GeoJSONDecoder geoJSONDecoder = new GeoJSONDecoder();
    geoJSONDecoder.setDecoderRepository(decoderRepository);
    decoderRepository.setDecoders(Arrays.asList(decoder, spatialFilterDecoder, temporalFilterDecoder, geoJSONDecoder));
    decoderRepository.init();
}
Also used : TemporalFilterDecoder(org.n52.svalbard.decode.json.TemporalFilterDecoder) GeoJSONDecoder(org.n52.svalbard.decode.json.GeoJSONDecoder) GetObservationRequestDecoder(org.n52.svalbard.decode.json.GetObservationRequestDecoder) SpatialFilterDecoder(org.n52.svalbard.decode.json.SpatialFilterDecoder) DecoderRepository(org.n52.svalbard.decode.DecoderRepository) Before(org.junit.Before)

Aggregations

DecodingException (org.n52.svalbard.decode.exception.DecodingException)13 XmlObject (org.apache.xmlbeans.XmlObject)11 XmlException (org.apache.xmlbeans.XmlException)7 NoDecoderForKeyException (org.n52.svalbard.decode.exception.NoDecoderForKeyException)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Before (org.junit.Before)4 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)4 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)4 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)4 DecoderRepository (org.n52.svalbard.decode.DecoderRepository)4 InvalidParameterValueException (org.n52.shetland.ogc.ows.exception.InvalidParameterValueException)3 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)3 OperationDecoderKey (org.n52.svalbard.decode.OperationDecoderKey)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 Test (org.junit.Test)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 XmlNamespaceDecoderKey (org.n52.svalbard.decode.XmlNamespaceDecoderKey)2