Search in sources :

Example 1 with WsaHeader

use of org.n52.shetland.w3c.wsa.WsaHeader in project arctic-sea by 52North.

the class WsaDecoder method decode.

@Override
public List<WsaHeader> decode(List<SOAPHeaderElement> list) {
    List<WsaHeader> wsaHeaders = Lists.newArrayListWithCapacity(list.size());
    boolean to = false;
    boolean replyTo = false;
    boolean messageId = false;
    boolean action = false;
    for (SOAPHeaderElement soapHeaderElement : list) {
        if (soapHeaderElement.getLocalName().equals(WsaConstants.EN_TO)) {
            wsaHeaders.add(new WsaToHeader(soapHeaderElement.getValue()));
            to = true;
        } else if (soapHeaderElement.getLocalName().equals(WsaConstants.EN_ACTION)) {
            wsaHeaders.add(new WsaActionHeader(soapHeaderElement.getValue()));
            action = true;
        } else if (soapHeaderElement.getLocalName().equals(WsaConstants.EN_REPLY_TO)) {
            Iterator<?> iter = soapHeaderElement.getChildElements();
            while (iter.hasNext()) {
                Node node = (Node) iter.next();
                if (node.getLocalName() != null && node.getLocalName().equals(WsaConstants.EN_ADDRESS)) {
                    wsaHeaders.add(new WsaReplyToHeader(node.getValue()));
                    replyTo = true;
                }
            }
        } else if (soapHeaderElement.getLocalName().equals(WsaConstants.EN_MESSAGE_ID)) {
            wsaHeaders.add(new WsaMessageIDHeader(soapHeaderElement.getValue()));
            messageId = true;
        }
    }
    if ((to || replyTo || messageId) && !action) {
        wsaHeaders.add(new WsaActionHeader(WsaConstants.WSA_FAULT_ACTION));
    }
    return wsaHeaders;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) WsaReplyToHeader(org.n52.shetland.w3c.wsa.WsaReplyToHeader) WsaMessageIDHeader(org.n52.shetland.w3c.wsa.WsaMessageIDHeader) Node(javax.xml.soap.Node) WsaToHeader(org.n52.shetland.w3c.wsa.WsaToHeader) WsaHeader(org.n52.shetland.w3c.wsa.WsaHeader) WsaActionHeader(org.n52.shetland.w3c.wsa.WsaActionHeader)

Example 2 with WsaHeader

use of org.n52.shetland.w3c.wsa.WsaHeader 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 3 with WsaHeader

use of org.n52.shetland.w3c.wsa.WsaHeader in project arctic-sea by 52North.

the class Soap12Encoder method createSOAP12Header.

private void createSOAP12Header(Envelope envelope, List<SoapHeader> headers, String action) throws EncodingException {
    Node headerDomNode = envelope.addNewHeader().getDomNode();
    for (SoapHeader header : headers) {
        if (WsaConstants.NS_WSA.equals(header.getNamespace()) && header instanceof WsaActionHeader) {
            ((WsaHeader) header).setValue(action);
        }
        XmlObject xmObject = encodeObjectToXml(header.getNamespace(), header);
        if (xmObject != null) {
            Node ownerDoc = headerDomNode.getOwnerDocument().importNode(xmObject.getDomNode().getFirstChild(), true);
            headerDomNode.insertBefore(ownerDoc, null);
        }
    }
}
Also used : Node(org.w3c.dom.Node) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader) XmlObject(org.apache.xmlbeans.XmlObject) WsaHeader(org.n52.shetland.w3c.wsa.WsaHeader) WsaActionHeader(org.n52.shetland.w3c.wsa.WsaActionHeader)

Aggregations

WsaActionHeader (org.n52.shetland.w3c.wsa.WsaActionHeader)3 WsaHeader (org.n52.shetland.w3c.wsa.WsaHeader)3 SoapHeader (org.n52.shetland.w3c.soap.SoapHeader)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 Node (javax.xml.soap.Node)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 XmlObject (org.apache.xmlbeans.XmlObject)1 WsaMessageIDHeader (org.n52.shetland.w3c.wsa.WsaMessageIDHeader)1 WsaReplyToHeader (org.n52.shetland.w3c.wsa.WsaReplyToHeader)1 WsaToHeader (org.n52.shetland.w3c.wsa.WsaToHeader)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)1 Node (org.w3c.dom.Node)1