use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.
the class SoapBinding method writeOwsExceptionReport.
private void writeOwsExceptionReport(SoapChain chain, OwsExceptionReport owse) throws HTTPException, IOException {
try {
String version = chain.hasBodyRequest() ? chain.getBodyRequest().getVersion() : null;
getEventBus().submit(new ExceptionEvent(owse));
chain.getSoapResponse().setException(owse.setVersion(version));
if (!chain.getSoapResponse().hasSoapVersion()) {
chain.getSoapResponse().setSoapVersion(SOAPConstants.SOAP_1_2_PROTOCOL);
}
if (!chain.getSoapResponse().hasSoapNamespace()) {
chain.getSoapResponse().setSoapNamespace(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
}
if (chain.getSoapResponse().hasException() && chain.getSoapResponse().getException().hasStatus()) {
chain.getHttpResponse().setStatus(chain.getSoapResponse().getException().getStatus().getCode());
}
checkSoapInjection(chain);
httpUtils.writeObject(chain.getHttpRequest(), chain.getHttpResponse(), checkMediaType(chain), encodeSoapResponse(chain), this);
} catch (OwsExceptionReport | NoEncoderForKeyException t) {
throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, t);
}
}
use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.
the class SoapBinding method writeResponse.
private void writeResponse(SoapChain chain) throws IOException, HTTPException {
MediaType contentType = chooseResponseContentType(chain.getBodyResponse(), HTTPHeaders.getAcceptHeader(chain.getHttpRequest()), getDefaultContentType());
// TODO allow other bindings to encode response as soap messages
if (contentType.isCompatible(getDefaultContentType())) {
checkSoapInjection(chain);
httpUtils.writeObject(chain.getHttpRequest(), chain.getHttpResponse(), checkMediaType(chain), chain, this);
} else {
httpUtils.writeObject(chain.getHttpRequest(), chain.getHttpResponse(), contentType, chain.getBodyResponse(), this);
}
}
use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.
the class Service method getBinding.
/**
* Get the implementation of {@link Binding} that is registered for the given <code>request</code>.
*
* @param request URL pattern from request URL
*
* @return The implementation of {@link Binding} that is registered for the given <code>urlPattern</code>.
*
* @throws HTTPException If the URL pattern or ContentType is not supported by this service.
*/
private Binding getBinding(HttpServletRequest request) throws HTTPException {
final String requestURI = request.getPathInfo();
if (requestURI == null || requestURI.isEmpty() || requestURI.equals("/")) {
MediaType contentType = getContentType(request);
// strip of the parameters to get rid of things like encoding
Binding binding = this.bindingRepository.getBinding(contentType.withoutParameters());
if (binding == null) {
if (contentType.equals(MediaTypes.APPLICATION_KVP)) {
throw new HTTPException(HTTPStatus.METHOD_NOT_ALLOWED);
} else {
throw new HTTPException(HTTPStatus.UNSUPPORTED_MEDIA_TYPE);
}
} else {
if (requestTimeout > 0) {
try {
return TIME_LIMITER.newProxy(binding, Binding.class, requestTimeout, TimeUnit.SECONDS);
} catch (UncheckedTimeoutException ute) {
HTTPException httpException = new HTTPException(HTTPStatus.GATEWAY_TIME_OUT);
httpException.addSuppressed(ute);
throw httpException;
}
}
return binding;
}
}
throw new HTTPException(HTTPStatus.NOT_FOUND);
}
use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.
the class Service method put.
@RequestMapping(method = RequestMethod.PUT)
public void put(HttpServletRequest request, HttpServletResponse response) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();
long currentCount = logRequest(request);
try {
getBinding(request).doPutOperation(request, response);
} catch (HTTPException exception) {
onHttpException(request, response, exception);
} finally {
logResponse(request, response, currentCount, stopwatch);
}
}
use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.
the class Service method options.
@RequestMapping(method = RequestMethod.OPTIONS)
private void options(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Stopwatch stopwatch = Stopwatch.createStarted();
long currentCount = logRequest(request);
Binding binding = null;
try {
binding = getBinding(request);
binding.doOptionsOperation(request, response);
} catch (HTTPException exception) {
if (exception.getStatus() == HTTPStatus.METHOD_NOT_ALLOWED && binding != null) {
doDefaultOptions(binding, request, response);
} else {
onHttpException(request, response, exception);
}
} finally {
logResponse(request, response, currentCount, stopwatch);
}
}
Aggregations