use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SimpleBinding method getServiceOperator.
protected ServiceOperator getServiceOperator(OwsServiceRequest request) throws OwsExceptionReport {
checkServiceOperatorKeyTypes(request);
String service = request.getService();
String version = request.getVersion();
if (request instanceof GetCapabilitiesRequest) {
GetCapabilitiesRequest gcr = (GetCapabilitiesRequest) request;
if (gcr.isSetAcceptVersions()) {
return gcr.getAcceptVersions().stream().map(v -> new OwsServiceKey(service, v)).map(this::getServiceOperator).filter(Objects::nonNull).findFirst().orElseThrow(() -> new InvalidServiceOrVersionException(service, version));
} else {
Set<String> supportedVersions = serviceOperatorRepository.getSupportedVersions(service);
String newest = supportedVersions.stream().max(Comparables.version()).orElseThrow(() -> new InvalidServiceParameterException(service));
return getServiceOperator(new OwsServiceKey(service, newest));
}
} else {
return getServiceOperator(new OwsServiceKey(service, version));
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SimpleBinding method checkServiceOperatorKeyTypes.
protected void checkServiceOperatorKeyTypes(OwsServiceRequest request) throws OwsExceptionReport {
String service = request.getService();
String version = request.getVersion();
if (service == null || service.isEmpty()) {
throw new MissingServiceParameterException();
} else if (!getServiceOperatorRepository().isServiceSupported(service)) {
throw new InvalidServiceParameterException(service);
} else if (request instanceof GetCapabilitiesRequest) {
GetCapabilitiesRequest gcr = (GetCapabilitiesRequest) request;
if (gcr.isSetAcceptVersions() && !gcr.getAcceptVersions().stream().anyMatch(v -> isVersionSupported(service, v))) {
throw new InvalidAcceptVersionsParameterException(gcr.getAcceptVersions());
}
} else if (version == null || version.isEmpty()) {
throw new MissingVersionParameterException();
} else if (!isVersionSupported(service, version)) {
throw new VersionNotSupportedException();
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SimpleBinding method handleEncodingException.
@Override
public Object handleEncodingException(HttpServletRequest request, HttpServletResponse response, EncodingException ex) throws HTTPException {
try {
OwsExceptionReport oer;
if (ex instanceof OwsEncodingException) {
oer = ((OwsEncodingException) ex).getCause();
} else if (ex.getCause() instanceof OwsExceptionReport) {
oer = (OwsExceptionReport) ex.getCause();
} else {
oer = new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
eventBus.submit(new ExceptionEvent(oer));
MediaType contentType = chooseResponseContentTypeForExceptionReport(HTTPHeaders.getAcceptHeader(request), getDefaultContentType());
Object encoded = encodeOwsExceptionReport(oer, contentType);
if (isUseHttpResponseCodes() && oer.hasStatus()) {
response.setStatus(oer.getStatus().getCode());
}
return encoded;
} catch (OwsExceptionReport e) {
throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, e);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class EXIBinding method doPostOperation.
@Override
public void doPostOperation(HttpServletRequest req, HttpServletResponse res) throws HTTPException, IOException {
OwsServiceRequest sosRequest = null;
try {
sosRequest = parseRequest(req);
OwsServiceResponse sosResponse = getServiceOperator(sosRequest).receiveRequest(sosRequest);
writeResponse(req, res, sosResponse);
} catch (OwsExceptionReport oer) {
oer.setVersion(sosRequest != null ? sosRequest.getVersion() : null);
writeOwsExceptionReport(req, res, oer);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport 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());
}
}
Aggregations