Search in sources :

Example 1 with NoDecoderForKeyException

use of org.n52.svalbard.decode.exception.NoDecoderForKeyException 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 NoDecoderForKeyException

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

the class GetResultTemplateResponseEncoder method encodeResultStructure.

private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
    SweAbstractDataComponent structure;
    SosResultStructure rs = t.getResultStructure();
    if (rs.isDecoded()) {
        structure = t.getResultStructure().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
            Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (structure instanceof SweDataRecord) {
        encodeSweDataRecord(structure, jrs);
    } else {
        LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 3 with NoDecoderForKeyException

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

the class AbstractStringRequestDecoder method decode.

@Override
public OwsServiceCommunicationObject decode(String string) throws DecodingException {
    XmlObject xml = CodingHelper.readXML(string);
    DecoderKey key = CodingHelper.getDecoderKey(xml);
    Decoder<OwsServiceCommunicationObject, XmlObject> decoder = decoderRepository.getDecoder(key);
    if (decoder == null) {
        throw new NoDecoderForKeyException(key);
    }
    return decoder.decode(xml);
}
Also used : OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 4 with NoDecoderForKeyException

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

the class BatchRequestDecoder method getDecoder.

private Decoder<OwsServiceRequest, JsonNode> getDecoder(JsonNode n) throws DecodingException {
    String service = n.path(JSONConstants.SERVICE).textValue();
    String version = n.path(JSONConstants.VERSION).textValue();
    String request = n.path(JSONConstants.REQUEST).textValue();
    OperationDecoderKey k = new OperationDecoderKey(service, version, request, MediaTypes.APPLICATION_JSON);
    Decoder<OwsServiceRequest, JsonNode> decoder = getDecoder(k);
    if (decoder == null) {
        // TODO other exception?
        throw new NoDecoderForKeyException(k);
    }
    return decoder;
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) JsonNode(com.fasterxml.jackson.databind.JsonNode) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey)

Example 5 with NoDecoderForKeyException

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

the class JSONDecoder method getDecoder.

private <T> Decoder<T, JsonNode> getDecoder(Class<T> type) throws DecodingException {
    JsonDecoderKey key = new JsonDecoderKey(type);
    Decoder<T, JsonNode> decoder = getDecoder(key);
    if (decoder == null) {
        throw new NoDecoderForKeyException(key);
    }
    return decoder;
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) JsonDecoderKey(org.n52.svalbard.decode.JsonDecoderKey) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

NoDecoderForKeyException (org.n52.svalbard.decode.exception.NoDecoderForKeyException)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 XmlObject (org.apache.xmlbeans.XmlObject)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 XmlException (org.apache.xmlbeans.XmlException)2 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)2 OperationDecoderKey (org.n52.svalbard.decode.OperationDecoderKey)2 XmlNamespaceDecoderKey (org.n52.svalbard.decode.XmlNamespaceDecoderKey)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 IOException (java.io.IOException)1 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 SosResultEncoding (org.n52.shetland.ogc.sos.SosResultEncoding)1 SosResultStructure (org.n52.shetland.ogc.sos.SosResultStructure)1 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1 SweAbstractEncoding (org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding)1 SweTextEncoding (org.n52.shetland.ogc.swe.encoding.SweTextEncoding)1