Search in sources :

Example 1 with HTTPException

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

the class SimpleBinding method writeResponse.

protected void writeResponse(HttpServletRequest request, HttpServletResponse response, OwsServiceResponse serviceResponse) throws HTTPException, IOException {
    try {
        MediaType contentType = chooseResponseContentType(serviceResponse, HTTPHeaders.getAcceptHeader(request), getDefaultContentType());
        if (!serviceResponse.isSetContentType()) {
            serviceResponse.setContentType(contentType);
        }
        httpUtils.writeObject(request, response, contentType, serviceResponse, this);
    } finally {
        serviceResponse.close();
    }
}
Also used : MediaType(org.n52.janmayen.http.MediaType)

Example 2 with HTTPException

use of org.n52.iceland.exception.HTTPException 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);
    }
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) HTTPException(org.n52.iceland.exception.HTTPException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) MediaType(org.n52.janmayen.http.MediaType) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 3 with HTTPException

use of org.n52.iceland.exception.HTTPException 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);
    }
}
Also used : OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 4 with HTTPException

use of org.n52.iceland.exception.HTTPException 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);
    }
}
Also used : OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 5 with HTTPException

use of org.n52.iceland.exception.HTTPException 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);
    }
}
Also used : SoapChain(org.n52.shetland.w3c.soap.SoapChain) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

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