use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport 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.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class KvpBinding method toOwsExceptionReport.
private OwsExceptionReport toOwsExceptionReport(Throwable ex) {
if (ex instanceof OwsExceptionReport) {
return (OwsExceptionReport) ex;
}
Throwable cause = ex.getCause();
if (cause instanceof OwsExceptionReport) {
return (OwsExceptionReport) cause;
}
if (ex instanceof CompositeException) {
return toOwsExceptionReport((CompositeException) ex);
}
if (cause instanceof CompositeException) {
return toOwsExceptionReport((CompositeException) cause);
}
String location = null;
if (ex instanceof LocationHintException) {
location = ((LocationHintException) ex).getLocation().orElse(null);
} else if (cause instanceof LocationHintException) {
location = ((LocationHintException) cause).getLocation().orElse(null);
}
return new InvalidParameterValueException().withMessage(ex.getMessage()).causedBy(ex).at(location);
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class PoxBinding method doPostOperation.
@Override
public void doPostOperation(HttpServletRequest req, HttpServletResponse res) throws HTTPException, IOException {
OwsServiceRequest request = null;
try {
request = parseRequest(req);
OwsServiceResponse response = getServiceOperator(request).receiveRequest(request);
writeResponse(req, res, response);
} catch (OwsExceptionReport oer) {
oer.setVersion(request != null ? request.getVersion() : null);
LOG.warn("Unexpected error", oer);
writeOwsExceptionReport(req, res, oer);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class AbstractXmlBinding method decode.
protected T decode(HttpServletRequest request) throws OwsExceptionReport {
String characterEncoding = getCharacterEncoding(request);
String xmlString = xmlToString(request, characterEncoding);
LOGGER.debug("XML-REQUEST: {}", xmlString);
DecoderKey key = getDecoderKey(xmlString, characterEncoding);
LOGGER.trace("Found decoder key: {}", key);
Decoder<T, String> decoder = getDecoder(key);
if (decoder == null) {
// if this a GetCapabilities request, then the service is not supported
String opOrType = null;
Optional<String> service = Optional.empty();
if (key instanceof XmlNamespaceOperationDecoderKey) {
XmlNamespaceOperationDecoderKey xmlNamespaceKey = (XmlNamespaceOperationDecoderKey) key;
opOrType = xmlNamespaceKey.getType();
} else if (key instanceof XmlStringOperationDecoderKey) {
XmlStringOperationDecoderKey xmlStringKey = (XmlStringOperationDecoderKey) key;
opOrType = xmlStringKey.getOperation();
service = Optional.of(xmlStringKey.getService());
}
if (OWSConstants.Operations.GetCapabilities.toString().equalsIgnoreCase(opOrType)) {
if (service.isPresent()) {
throw new InvalidParameterValueException(OWSConstants.GetCapabilitiesParams.service, service.get()).withMessage("The service '%s' is not supported.", service);
} else {
throw new MissingParameterValueException(OWSConstants.GetCapabilitiesParams.service).withMessage("The parameter '%s' is missing.", OWSConstants.GetCapabilitiesParams.service);
}
} else {
throw new InvalidParameterValueException().withMessage("No decoder found for incoming message " + "based on derived decoder key: %s\nMessage: %s", key, xmlString);
}
} else {
LOGGER.trace("Using decoder: {}", decoder);
}
try {
return decoder.decode(xmlString);
} catch (OwsDecodingException ex) {
throw ex.getCause();
} catch (DecodingException ex) {
throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
}
use of org.n52.shetland.ogc.ows.exception.OwsExceptionReport in project arctic-sea by 52North.
the class SoapBinding method doPostOperation.
@Override
public void doPostOperation(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws HTTPException, IOException {
final SoapChain chain = new SoapChain(httpRequest, httpResponse);
try {
parseSoapRequest(chain);
checkForContext(chain, getRequestContext(httpRequest));
createSoapResponse(chain);
if (!chain.getSoapRequest().hasSoapFault()) {
// parseBodyRequest(chain);
createBodyResponse(chain);
}
writeResponse(chain);
} catch (OwsExceptionReport t) {
writeOwsExceptionReport(chain, t);
}
}
Aggregations