Search in sources :

Example 1 with SoapResponse

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

Example 2 with SoapResponse

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

the class SoapBinding method checkSoapInjection.

/**
 * Check if SoapHeader information is contained in the body response and add the header information to the
 * {@link SoapResponse}
 *
 * @param chain SoapChain to check
 */
private void checkSoapInjection(SoapChain chain) {
    if (chain.getBodyResponse() instanceof CommunicationObjectWithSoapHeader) {
        CommunicationObjectWithSoapHeader soapHeaderObject = (CommunicationObjectWithSoapHeader) chain.getBodyResponse();
        if (soapHeaderObject.isSetSoapHeader()) {
            List<SoapHeader> headers = ((CommunicationObjectWithSoapHeader) chain.getSoapRequest()).getSoapHeader();
            // TODO do things
            chain.getSoapResponse().setHeader(checkSoapHeaders(headers));
        }
    }
}
Also used : CommunicationObjectWithSoapHeader(org.n52.iceland.service.CommunicationObjectWithSoapHeader) CommunicationObjectWithSoapHeader(org.n52.iceland.service.CommunicationObjectWithSoapHeader) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader)

Example 3 with SoapResponse

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

the class SoapChainResponseWriter method write.

private void write(SoapChain chain, OutputStream out) throws EncodingException, IOException {
    String namespace = chain.getSoapResponse().getSoapNamespace();
    EncoderKey key = CodingHelper.getEncoderKey(namespace, chain.getSoapResponse());
    Encoder<?, SoapResponse> encoder = getEncoder(key);
    if (encoder == null) {
        throw new NoEncoderForKeyException(key);
    }
    write(encoder, chain, out);
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) EncoderKey(org.n52.svalbard.encode.EncoderKey)

Example 4 with SoapResponse

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

the class Soap11Encoder method encode.

@Override
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public SOAPMessage encode(SoapResponse soapResponse, EncodingContext additionalValues) throws EncodingException {
    if (soapResponse == null) {
        throw new UnsupportedEncoderInputException(this, soapResponse);
    }
    String soapVersion = soapResponse.getSoapVersion();
    SOAPMessage soapResponseMessage;
    String action = null;
    try {
        soapResponseMessage = SoapHelper.getSoapMessageForProtocol(soapVersion);
        if (soapResponse.getSoapFault() != null) {
            createSOAPFault(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getSoapFault());
        } else {
            if (soapResponse.getException() != null) {
                action = createSOAPFaultFromExceptionResponse(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getException());
                addSchemaLocationForExceptionToSOAPMessage(soapResponseMessage);
            } else {
                action = createSOAPBody(soapResponseMessage, soapResponse, soapResponse.getSoapAction());
            }
        }
        if (soapResponse.getHeader() != null) {
            List<SoapHeader> headers = soapResponse.getHeader();
            for (SoapHeader header : headers) {
                if (WsaConstants.NS_WSA.equals(header.getNamespace()) && header instanceof WsaActionHeader) {
                    ((WsaHeader) header).setValue(action);
                }
                Encoder<Map<QName, String>, SoapHeader> encoder = getEncoder(CodingHelper.getEncoderKey(header.getNamespace(), header));
                if (encoder != null) {
                    Map<QName, String> headerElements = encoder.encode(header);
                    for (Entry<QName, String> entry : headerElements.entrySet()) {
                        QName qName = entry.getKey();
                        soapResponseMessage.getSOAPHeader().addChildElement(qName).setTextContent(headerElements.get(qName));
                    }
                }
            }
        } else {
            soapResponseMessage.getSOAPHeader().detachNode();
        }
        soapResponseMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, String.valueOf(true));
        return soapResponseMessage;
    } catch (SOAPException soape) {
        throw new EncodingException("Error while encoding SOAPMessage!", soape);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) QName(javax.xml.namespace.QName) SOAPMessage(javax.xml.soap.SOAPMessage) WsaHeader(org.n52.shetland.w3c.wsa.WsaHeader) WsaActionHeader(org.n52.shetland.w3c.wsa.WsaActionHeader) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SOAPException(javax.xml.soap.SOAPException) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader) Map(java.util.Map) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with SoapResponse

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

the class Soap12Encoder method encode.

@Override
public void encode(Object element, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
    if (element instanceof SoapResponse) {
        try {
            EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
            new Soap12XmlStreamWriter(context, outputStream, (SoapResponse) element).write();
        } catch (XMLStreamException ex) {
            throw new EncodingException(ex);
        }
    } else {
        try {
            encode(element, ctx).save(outputStream, getXmlOptions());
        } catch (IOException ioe) {
            throw new EncodingException("Error while writing element to stream!", ioe);
        }
    }
}
Also used : Soap12XmlStreamWriter(org.n52.svalbard.write.Soap12XmlStreamWriter) SoapResponse(org.n52.shetland.w3c.soap.SoapResponse) XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) Supplier(java.util.function.Supplier) IOException(java.io.IOException)

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