Search in sources :

Example 6 with HTTPException

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);
    }
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) HTTPException(org.n52.iceland.exception.HTTPException) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 7 with HTTPException

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);
    }
}
Also used : MediaType(org.n52.janmayen.http.MediaType)

Example 8 with HTTPException

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);
}
Also used : Binding(org.n52.iceland.binding.Binding) HTTPException(org.n52.iceland.exception.HTTPException) MediaType(org.n52.janmayen.http.MediaType) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException)

Example 9 with HTTPException

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);
    }
}
Also used : HTTPException(org.n52.iceland.exception.HTTPException) Stopwatch(com.google.common.base.Stopwatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with HTTPException

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);
    }
}
Also used : Binding(org.n52.iceland.binding.Binding) HTTPException(org.n52.iceland.exception.HTTPException) Stopwatch(com.google.common.base.Stopwatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HTTPException (org.n52.iceland.exception.HTTPException)10 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)8 Stopwatch (com.google.common.base.Stopwatch)5 MediaType (org.n52.janmayen.http.MediaType)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ExceptionEvent (org.n52.iceland.event.events.ExceptionEvent)4 OwsServiceRequest (org.n52.shetland.ogc.ows.service.OwsServiceRequest)4 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)4 Binding (org.n52.iceland.binding.Binding)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)1 ResponseProxy (org.n52.iceland.coding.encode.ResponseProxy)1 CountingOutputStreamEvent (org.n52.iceland.event.events.CountingOutputStreamEvent)1 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)1 SoapChain (org.n52.shetland.w3c.soap.SoapChain)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1