use of org.n52.svalbard.decode.OperationDecoderKey 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.OperationDecoderKey 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;
}
use of org.n52.svalbard.decode.OperationDecoderKey in project arctic-sea by 52North.
the class CodingHelper method xmlDecoderKeysForOperation.
public static Set<DecoderKey> xmlDecoderKeysForOperation(String service, String version, String... operations) {
HashSet<DecoderKey> set = new HashSet<>(operations.length);
for (String o : operations) {
set.add(new OperationDecoderKey(service, version, o, MediaTypes.TEXT_XML));
set.add(new OperationDecoderKey(service, version, o, MediaTypes.APPLICATION_XML));
}
return set;
}
use of org.n52.svalbard.decode.OperationDecoderKey in project arctic-sea by 52North.
the class CodingHelper method xmlDecoderKeysForOperation.
public static Set<DecoderKey> xmlDecoderKeysForOperation(String service, String version, Enum<?>... operations) {
HashSet<DecoderKey> set = new HashSet<>(operations.length);
for (Enum<?> o : operations) {
set.add(new OperationDecoderKey(service, version, o.name(), MediaTypes.TEXT_XML));
set.add(new OperationDecoderKey(service, version, o.name(), MediaTypes.APPLICATION_XML));
}
return set;
}
use of org.n52.svalbard.decode.OperationDecoderKey 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;
}
Aggregations