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