Search in sources :

Example 1 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException 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 2 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class JSONBinding method parseRequest.

private OwsServiceRequest parseRequest(HttpServletRequest request) throws OwsExceptionReport {
    try {
        JsonNode json = Json.loadReader(request.getReader());
        if (LOG.isDebugEnabled()) {
            LOG.debug("JSON-REQUEST: {}", Json.print(json));
        }
        OperationDecoderKey key = new OperationDecoderKey(json.path(SERVICE).textValue(), json.path(VERSION).textValue(), json.path(REQUEST).textValue(), MediaTypes.APPLICATION_JSON);
        Decoder<OwsServiceRequest, JsonNode> decoder = getDecoder(key);
        if (decoder == null) {
            NoDecoderForKeyException cause = new NoDecoderForKeyException(key);
            throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
        }
        OwsServiceRequest sosRequest;
        try {
            sosRequest = decoder.decode(json);
        } catch (OwsDecodingException ex) {
            throw ex.getCause();
        } catch (DecodingException ex) {
            throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
        sosRequest.setRequestContext(getRequestContext(request));
        return sosRequest;
    } catch (IOException ioe) {
        throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while reading request! Message: %s", ioe.getMessage());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) IOException(java.io.IOException) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey)

Example 3 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException 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);
    }
}
Also used : XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) MissingParameterValueException(org.n52.shetland.ogc.ows.exception.MissingParameterValueException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DecoderKey(org.n52.svalbard.decode.DecoderKey) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey) XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey)

Example 4 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class AbstractXmlBinding method getDecoderKey.

@VisibleForTesting
protected DecoderKey getDecoderKey(String xmlContent, String characterEncoding) throws CodedException {
    try (ByteArrayInputStream stream = new ByteArrayInputStream(xmlContent.getBytes(characterEncoding))) {
        // FIXME do not parse the complete request, if we only need the first element
        Document document = documentFactory.newDocumentBuilder().parse(stream);
        Element element = document.getDocumentElement();
        // TODO is this REALLY needed!?
        element.normalize();
        if (element.hasAttributes() && element.hasAttribute(OWSConstants.RequestParams.service.name())) {
            OwsOperationKey operationKey = getOperationKey(element);
            XmlStringOperationDecoderKey decoderKey = new XmlStringOperationDecoderKey(operationKey, getDefaultContentType());
            return decoderKey;
        } else {
            return getNamespaceOperationDecoderKey(element);
        }
    } catch (SAXException | IOException | ParserConfigurationException e) {
        throw new NoApplicableCodeException().causedBy(e).withMessage("An error occured when parsing the request! Message: %s", e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) Element(org.w3c.dom.Element) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) SAXException(org.xml.sax.SAXException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class SoapBinding method encodeSoapResponse.

private Object encodeSoapResponse(SoapChain chain) throws OwsExceptionReport, NoEncoderForKeyException {
    EncoderKey key = new XmlEncoderKey(chain.getSoapResponse().getSoapNamespace(), chain.getSoapResponse().getClass());
    Encoder<?, SoapResponse> encoder = getEncoder(key);
    if (encoder != null) {
        try {
            return encoder.encode(chain.getSoapResponse());
        } catch (OwsEncodingException ex) {
            throw ex.getCause();
        } catch (EncodingException ex) {
            throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
        }
    } else {
        NoEncoderForKeyException cause = new NoEncoderForKeyException(key);
        throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) EncoderKey(org.n52.svalbard.encode.EncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException)

Aggregations

NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)11 IOException (java.io.IOException)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)3 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 SOAPException (javax.xml.soap.SOAPException)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)2 SoapRequest (org.n52.shetland.w3c.soap.SoapRequest)2 SoapResponse (org.n52.shetland.w3c.soap.SoapResponse)2 XmlStringOperationDecoderKey (org.n52.svalbard.decode.XmlStringOperationDecoderKey)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 EXIFactory (com.siemens.ct.exi.EXIFactory)1 EXISource (com.siemens.ct.exi.api.sax.EXISource)1 EXIException (com.siemens.ct.exi.exceptions.EXIException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1