Search in sources :

Example 11 with CodedException

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

the class AbstractXmlBindingTest method test_SoapPrefix.

@Test
public void test_SoapPrefix() throws CodedException {
    DecoderKey decoderKey = binding.getDecoderKey(xmlStringSoapPrefix, characterEncoding);
    assertTrue(decoderKey instanceof XmlNamespaceOperationDecoderKey);
    assertTrue(SoapConstants.NS_SOAP_12.equals(((XmlNamespaceOperationDecoderKey) decoderKey).getNamespace()));
}
Also used : XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) OperationDecoderKey(org.n52.svalbard.decode.OperationDecoderKey) XmlNamespaceOperationDecoderKey(org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey) DecoderKey(org.n52.svalbard.decode.DecoderKey) Test(org.junit.Test)

Example 12 with CodedException

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

the class OwsExceptionReportDecoder method decode.

private OwsExceptionReport decode(ExceptionReport report) {
    String version = report.getVersion();
    ExceptionType[] exceptionTypes = report.getExceptionArray();
    List<CodedException> exceptions = Streams.stream(exceptionTypes).map(this::decode).collect(toList());
    return new CompositeOwsException(exceptions).setVersion(version);
}
Also used : ExceptionType(net.opengis.ows.x11.ExceptionType) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) CompositeOwsException(org.n52.shetland.ogc.ows.exception.CompositeOwsException)

Example 13 with CodedException

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

the class OwsEncoderv110 method encodeOwsException.

@SuppressFBWarnings("DM_DEFAULT_ENCODING")
private ExceptionDocument encodeOwsException(CodedException owsException) {
    ExceptionDocument exceptionDoc = ExceptionDocument.Factory.newInstance(getXmlOptions());
    ExceptionType exceptionType = exceptionDoc.addNewException();
    String exceptionCode;
    if (owsException.getCode() == null) {
        exceptionCode = OwsExceptionCode.NoApplicableCode.toString();
    } else {
        exceptionCode = owsException.getCode().toString();
    }
    exceptionType.setExceptionCode(exceptionCode);
    if (owsException.getLocator() != null) {
        exceptionType.setLocator(owsException.getLocator());
    }
    final StringBuilder exceptionText = new StringBuilder();
    if (owsException.getMessage() != null) {
        exceptionText.append(owsException.getMessage());
        exceptionText.append("\n");
    }
    if (owsException.getCause() != null) {
        exceptionText.append("[EXEPTION]: \n");
        final String localizedMessage = owsException.getCause().getLocalizedMessage();
        final String message = owsException.getCause().getMessage();
        if (localizedMessage != null && message != null) {
            if (!message.equals(localizedMessage)) {
                exceptionText.append(message).append('\n');
            }
            exceptionText.append(localizedMessage).append('\n');
        } else if (localizedMessage != null) {
            exceptionText.append(localizedMessage).append('\n');
        } else if (message != null) {
            exceptionText.append(message).append('\n');
        }
        if (includeStackTraceInExceptionReport) {
            final ByteArrayOutputStream os = new ByteArrayOutputStream();
            owsException.getCause().printStackTrace(new PrintStream(os));
            exceptionText.append(os.toString());
        }
    }
    exceptionType.addExceptionText(exceptionText.toString());
    return exceptionDoc;
}
Also used : ExceptionType(net.opengis.ows.x11.ExceptionType) PrintStream(java.io.PrintStream) ExceptionDocument(net.opengis.ows.x11.ExceptionDocument) LocalizedString(org.n52.janmayen.i18n.LocalizedString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) OwsLanguageString(org.n52.shetland.ogc.ows.OwsLanguageString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with CodedException

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

the class OwsExceptionReportEncoder method encodeJSON.

@Override
public JsonNode encodeJSON(OwsExceptionReport t) throws JSONEncodingException {
    final ObjectNode exceptionReport = Json.nodeFactory().objectNode();
    exceptionReport.put(JSONConstants.VERSION, t.getVersion());
    final ArrayNode exceptions = exceptionReport.putArray(JSONConstants.EXCEPTIONS);
    for (CodedException ce : t.getExceptions()) {
        final ObjectNode exception = exceptions.addObject();
        exception.put(JSONConstants.CODE, ce.getCode() != null ? ce.getCode().toString() : OwsExceptionCode.NoApplicableCode.toString());
        if (ce.getLocator() != null && !ce.getLocator().isEmpty()) {
            exception.put(JSONConstants.LOCATOR, ce.getLocator());
        }
        final String message = getExceptionText(ce);
        if (message != null && !message.isEmpty()) {
            exception.put(JSONConstants.TEXT, message);
        }
        if (log.isDebugEnabled()) {
            exception.set(STACK_TRACE, encodeStackTrace(ce));
        }
    }
    return exceptionReport;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 15 with CodedException

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

the class Soap12Encoder method createSOAP12Envelope.

private XmlObject createSOAP12Envelope(SoapResponse response, EncodingContext additionalValues) throws EncodingException {
    String action = null;
    final EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
    final Envelope envelope = envelopeDoc.addNewEnvelope();
    final Body body = envelope.addNewBody();
    if (response.getSoapFault() != null) {
        body.set(createSOAP12Fault(response.getSoapFault()));
    } else {
        if (response.getException() != null) {
            if (!response.getException().getExceptions().isEmpty()) {
                final CodedException firstException = response.getException().getExceptions().get(0);
                action = getExceptionActionURI(firstException.getCode());
            }
            body.set(createSOAP12FaultFromExceptionResponse(response.getException()));
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOAP12(), N52XmlHelper.getSchemaLocationForOWS110Exception()));
        } else {
            action = response.getSoapAction();
            final XmlObject bodyContent = getBodyContent(response);
            String value = null;
            Node nodeToRemove = null;
            final NamedNodeMap attributeMap = bodyContent.getDomNode().getFirstChild().getAttributes();
            for (int i = 0; i < attributeMap.getLength(); i++) {
                final Node node = attributeMap.item(i);
                if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
                    value = node.getNodeValue();
                    nodeToRemove = node;
                }
            }
            if (nodeToRemove != null) {
                attributeMap.removeNamedItem(nodeToRemove.getNodeName());
            }
            final Set<SchemaLocation> schemaLocations = Sets.newHashSet();
            schemaLocations.add(N52XmlHelper.getSchemaLocationForSOAP12());
            if (value != null && !value.isEmpty()) {
                String[] split = value.split(" ");
                for (int i = 0; i < split.length; i += 2) {
                    schemaLocations.add(new SchemaLocation(split[i], split[i + 1]));
                }
            }
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, schemaLocations);
            body.set(bodyContent);
        }
    }
    if (response.getHeader() != null) {
        createSOAP12Header(envelope, response.getHeader(), action);
    } else {
        envelope.addNewHeader();
    }
    // checkAndValidateSoapMessage(envelopeDoc);
    return envelopeDoc;
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) EnvelopeDocument(org.w3.x2003.x05.soapEnvelope.EnvelopeDocument) NamedNodeMap(org.w3c.dom.NamedNodeMap) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) Node(org.w3c.dom.Node) XmlObject(org.apache.xmlbeans.XmlObject) XmlString(org.apache.xmlbeans.XmlString) Envelope(org.w3.x2003.x05.soapEnvelope.Envelope) Body(org.w3.x2003.x05.soapEnvelope.Body)

Aggregations

CodedException (org.n52.shetland.ogc.ows.exception.CodedException)6 Test (org.junit.Test)5 DecoderKey (org.n52.svalbard.decode.DecoderKey)4 OperationDecoderKey (org.n52.svalbard.decode.OperationDecoderKey)4 XmlNamespaceOperationDecoderKey (org.n52.svalbard.decode.XmlNamespaceOperationDecoderKey)4 QName (javax.xml.namespace.QName)2 ExceptionType (net.opengis.ows.x11.ExceptionType)2 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 MeasurementTimeseriesDocument (net.opengis.waterml.x20.MeasurementTimeseriesDocument)2 MeasurementTimeseriesType (net.opengis.waterml.x20.MeasurementTimeseriesType)2 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)2 TVPMeasurementMetadataType (net.opengis.waterml.x20.TVPMeasurementMetadataType)2 MeasurementTimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.MeasurementTimeseriesMetadata)2 TimeseriesMetadata (org.n52.shetland.ogc.om.series.wml.TimeseriesMetadata)2 InterpolationType (org.n52.shetland.ogc.om.series.wml.WaterMLConstants.InterpolationType)2 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 SoapFault (org.n52.shetland.w3c.soap.SoapFault)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1