Search in sources :

Example 6 with SoapResponse

use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.

the class SoapBinding method createSoapResponse.

// private void parseBodyRequest(SoapChain chain) throws OwsExceptionReport,
// OwsExceptionReport {
// 
// final XmlObject xmlObject = chain.getSoapRequest().getSoapBodyContent();
// DecoderKey key = CodingHelper.getDecoderKey(xmlObject);
// final Decoder<?, XmlObject> bodyDecoder = getDecoder(key);
// if (bodyDecoder == null) {
// throw new NoDecoderForKeyException(key).setStatus(BAD_REQUEST);
// }
// final Object aBodyRequest = bodyDecoder.decode(xmlObject);
// if (!(aBodyRequest instanceof AbstractServiceRequest)) {
// throw new NoApplicableCodeException().withMessage(
// "The returned object is not an AbstractServiceRequest implementation").setStatus(BAD_REQUEST);
// }
// AbstractServiceRequest bodyRequest = (AbstractServiceRequest)
// aBodyRequest;
// bodyRequest.setRequestContext(getRequestContext(chain.getHttpRequest()));
// if (bodyRequest instanceof CommunicationObjectWithSoapHeader) {
// ((CommunicationObjectWithSoapHeader)
// bodyRequest).setSoapHeader(chain.getSoapRequest().getSoapHeader());
// }
// chain.setBodyRequest(bodyRequest);
// }
private void createSoapResponse(SoapChain chain) {
    SoapResponse soapResponse = new SoapResponse();
    soapResponse.setSoapVersion(chain.getSoapRequest().getSoapVersion());
    soapResponse.setSoapNamespace(chain.getSoapRequest().getSoapNamespace());
    soapResponse.setHeader(checkSoapHeaders(chain.getSoapRequest().getSoapHeader()));
    chain.setSoapResponse(soapResponse);
}
Also used : SoapResponse(org.n52.shetland.w3c.soap.SoapResponse)

Example 7 with SoapResponse

use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.

the class AbstractSoapEncoder method getBodyContent.

/**
 * Get the content for the SOAPBody as {@link XmlObject}
 *
 * @param response SOAP response
 *
 * @return SOAPBody content as {@link XmlObject}
 *
 * @throws EncodingException If no encoder is available, the object to encode is not supported or an error occurs
 *                           during the encoding
 */
protected XmlObject getBodyContent(SoapResponse response) throws EncodingException {
    OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response.getBodyContent()), MediaTypes.APPLICATION_XML);
    Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
    if (encoder == null) {
        throw new NoEncoderForKeyException(key);
    }
    return (XmlObject) encoder.encode(response.getBodyContent());
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 8 with SoapResponse

use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.

the class Soap12XmlStreamWriter method writeSoapBody.

/**
 * Write the SOAP 1.2 body element
 *
 * @throws XMLStreamException If an error occurs when writing to {@link OutputStream}
 * @throws EncodingException  If an encoding error occurs
 */
protected void writeSoapBody() throws XMLStreamException, EncodingException {
    start(SoapConstants.SOAP_12_BODY);
    SoapResponse response = getElement();
    if (response != null) {
        if (response.isSetSoapFault()) {
            writeSoapFault(response.getSoapFault());
        } else if (response.hasException()) {
            writeSoapFaultFromException(response.getException());
        } else if (response.isSetBodyContent()) {
            writeBodyContent(response.getBodyContent());
        }
    }
    end(SoapConstants.SOAP_12_BODY);
}
Also used : SoapResponse(org.n52.shetland.w3c.soap.SoapResponse)

Example 9 with SoapResponse

use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.

the class Soap12XmlStreamWriter method getSchemaLocation.

protected Set<SchemaLocation> getSchemaLocation() throws EncodingException, XMLStreamException {
    SoapResponse response = getElement();
    Set<SchemaLocation> schemaLocations = Sets.newHashSet();
    schemaLocations.add(SoapConstants.SOAP_12_SCHEMA_LOCATION);
    if (response.isSetBodyContent()) {
        Encoder<Object, OwsServiceResponse> encoder = getEncoder(response.getBodyContent());
        if (encoder != null && encoder instanceof SchemaAwareEncoder) {
            schemaLocations.addAll(((SchemaAwareEncoder<?, ?>) encoder).getSchemaLocations());
        }
    }
    return schemaLocations;
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) SchemaAwareEncoder(org.n52.svalbard.encode.SchemaAwareEncoder) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 10 with SoapResponse

use of org.n52.shetland.w3c.soap.SoapResponse 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

SoapResponse (org.n52.shetland.w3c.soap.SoapResponse)6 XmlObject (org.apache.xmlbeans.XmlObject)3 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)3 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)2 SchemaLocation (org.n52.shetland.w3c.SchemaLocation)2 SoapHeader (org.n52.shetland.w3c.soap.SoapHeader)2 EncoderKey (org.n52.svalbard.encode.EncoderKey)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 QName (javax.xml.namespace.QName)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlString (org.apache.xmlbeans.XmlString)1 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)1 CommunicationObjectWithSoapHeader (org.n52.iceland.service.CommunicationObjectWithSoapHeader)1 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1