Search in sources :

Example 11 with HTTPException

use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.

the class Service method onHttpException.

protected void onHttpException(HttpServletRequest request, HttpServletResponse response, HTTPException exception) throws IOException {
    this.serviceEventBus.submit(new ExceptionEvent(exception));
    response.sendError(exception.getStatus().getCode(), exception.getMessage());
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent)

Example 12 with HTTPException

use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.

the class Service method delete.

@RequestMapping(method = RequestMethod.DELETE)
public void delete(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    try {
        getBinding(request).doDeleteOperation(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 13 with HTTPException

use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.

the class HttpUtils method writeObject.

private void writeObject(HttpServletRequest request, HttpServletResponse response, MediaType contentType, Writable writable, EncodingExceptionHandler owserHandler) throws IOException, HTTPException {
    OutputStream out = null;
    response.setContentType(writable.getEncodedContentType().toString());
    try {
        out = response.getOutputStream();
        if (HTTPHeaders.supportsGzipEncoding(request) && writable.supportsGZip()) {
            out = new GZIPOutputStream(out);
            response.setHeader(HTTPHeaders.CONTENT_ENCODING, HTTPConstants.GZIP_ENCODING);
        }
        if (isCountingOutputStream) {
            out = new CountingOutputStream(out);
        }
        if (writable.hasForcedHttpStatus()) {
            response.setStatus(writable.getForcedHttpStatus().getCode());
        }
        writable.write(out, new ResponseProxy(response));
        out.flush();
    } catch (EncodingException e) {
        Object writeOwsExceptionReport = owserHandler.handleEncodingException(request, response, e);
        if (writeOwsExceptionReport != null) {
            Writable owserWritable = getWritable(writeOwsExceptionReport, contentType);
            try {
                owserWritable.write(out, new ResponseProxy(response));
                if (out != null) {
                    out.flush();
                }
            } catch (EncodingException ex) {
                throw new HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, ex);
            }
        }
    } finally {
        if (out instanceof CountingOutputStream) {
            Long bytesWritten = ((CountingOutputStream) out).getCount();
            eventBus.submit(new CountingOutputStreamEvent(bytesWritten));
        }
        if (out != null) {
            LOGGER.debug("Response status = " + response.getStatus());
            out.close();
        }
    }
}
Also used : ResponseProxy(org.n52.iceland.coding.encode.ResponseProxy) CountingOutputStream(com.google.common.io.CountingOutputStream) HTTPException(org.n52.iceland.exception.HTTPException) GZIPOutputStream(java.util.zip.GZIPOutputStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) CountingOutputStreamEvent(org.n52.iceland.event.events.CountingOutputStreamEvent) CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream)

Example 14 with HTTPException

use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.

the class Service method get.

@RequestMapping(method = RequestMethod.GET)
public void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    try {
        getBinding(request).doGetOperation(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 15 with HTTPException

use of org.n52.iceland.exception.HTTPException in project arctic-sea by 52North.

the class Service method post.

@RequestMapping(method = RequestMethod.POST)
public void post(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    try {
        getBinding(request).doPostOperation(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)

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