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();
}
}
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;
}
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));
}
}
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);
}
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();
}
Aggregations