Search in sources :

Example 16 with Decoder

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

the class JSONDecoder method decodeJsonToObjectList.

protected <T> List<T> decodeJsonToObjectList(JsonNode node, Class<T> type) throws DecodingException {
    Decoder<T, JsonNode> decoder = getDecoder(type);
    if (node.isArray()) {
        CompositeException exceptions = new CompositeException();
        List<T> list = Streams.stream(node).filter(JsonNode::isObject).map(exceptions.wrapFunction(decoder::decode)).filter(Optional::isPresent).map(Optional::get).collect(toList());
        exceptions.throwIfNotEmpty(DecodingException::new);
        return list;
    } else if (node.isObject()) {
        return Collections.singletonList(decoder.decode(node));
    } else {
        return Collections.emptyList();
    }
}
Also used : Optional(java.util.Optional) CompositeException(org.n52.janmayen.exception.CompositeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 17 with Decoder

use of org.n52.svalbard.decode.Decoder 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)

Example 18 with Decoder

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

the class EXIBinding method parseRequest.

/**
 * Parse and decode the incoming EXI encoded {@link InputStream}
 *
 * @param request
 *            {@link HttpServletRequest} with EXI encoded
 *            {@link InputStream}
 * @return {@link OwsServiceRequest} from EXI encoded {@link InputStream}
 * @throws OwsExceptionReport
 *             If an error occurs during parsing
 */
protected OwsServiceRequest parseRequest(HttpServletRequest request) throws OwsExceptionReport {
    XmlObject doc = decode(request);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("EXI-REQUEST: {}", doc.xmlText());
    }
    Decoder<OwsServiceRequest, XmlObject> decoder = getDecoder(CodingHelper.getDecoderKey(doc));
    try {
        return decoder.decode(doc).setRequestContext(getRequestContext(request));
    } catch (OwsDecodingException ex) {
        throw ex.getCause();
    } catch (DecodingException ex) {
        throw new InvalidParameterValueException().withMessage(ex.getMessage()).causedBy(ex).at(ex.getLocation().orElse(null));
    }
}
Also used : OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest)

Example 19 with Decoder

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

the class SoapBinding method createSoapResponse.

// private void parseBodyRequest(SoapChain chain) throws OwsExceptionReport,
// OwsExceptionReport {
// 
// final XmlObject xmlObject = chain.getSoapRequest().getSoapBodyContent();
// DecoderKey key = CodingHelper.getDecoderKey(xmlObject);
// final Decoder<?, XmlObject> bodyDecoder = getDecoder(key);
// if (bodyDecoder == null) {
// throw new NoDecoderForKeyException(key).setStatus(BAD_REQUEST);
// }
// final Object aBodyRequest = bodyDecoder.decode(xmlObject);
// if (!(aBodyRequest instanceof AbstractServiceRequest)) {
// throw new NoApplicableCodeException().withMessage(
// "The returned object is not an AbstractServiceRequest implementation").setStatus(BAD_REQUEST);
// }
// AbstractServiceRequest bodyRequest = (AbstractServiceRequest)
// aBodyRequest;
// bodyRequest.setRequestContext(getRequestContext(chain.getHttpRequest()));
// if (bodyRequest instanceof CommunicationObjectWithSoapHeader) {
// ((CommunicationObjectWithSoapHeader)
// bodyRequest).setSoapHeader(chain.getSoapRequest().getSoapHeader());
// }
// chain.setBodyRequest(bodyRequest);
// }
private void createSoapResponse(SoapChain chain) {
    SoapResponse soapResponse = new SoapResponse();
    soapResponse.setSoapVersion(chain.getSoapRequest().getSoapVersion());
    soapResponse.setSoapNamespace(chain.getSoapRequest().getSoapNamespace());
    soapResponse.setHeader(checkSoapHeaders(chain.getSoapRequest().getSoapHeader()));
    chain.setSoapResponse(soapResponse);
}
Also used : SoapResponse(org.n52.shetland.w3c.soap.SoapResponse)

Example 20 with Decoder

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

the class InsertObservationRequestDecoderTest method before.

@Before
public void before() {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new InsertObservationRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    ObservationDecoder observationDecoder = new ObservationDecoder();
    observationDecoder.setDecoderRepository(decoderRepository);
    decoderRepository.setDecoders(Arrays.asList(decoder, observationDecoder));
    decoderRepository.init();
}
Also used : ObservationDecoder(org.n52.svalbard.decode.json.ObservationDecoder) InsertObservationRequestDecoder(org.n52.svalbard.decode.json.InsertObservationRequestDecoder) 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