Search in sources :

Example 1 with SoapHeader

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

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

the class AbstractSoapDecoder method getSoapHeader.

protected List<SoapHeader> getSoapHeader(SOAPHeader soapHeader) {
    Map<String, List<SOAPHeaderElement>> headersByNamespace = new HashMap<>();
    Iterator<?> headerElements = soapHeader.extractAllHeaderElements();
    while (headerElements.hasNext()) {
        SOAPHeaderElement element = (SOAPHeaderElement) headerElements.next();
        headersByNamespace.computeIfAbsent(element.getNamespaceURI(), Functions.forSupplier(LinkedList::new)).add(element);
    }
    List<SoapHeader> soapHeaders = Lists.newArrayList();
    for (Entry<String, List<SOAPHeaderElement>> key : headersByNamespace.entrySet()) {
        String namespace = key.getKey();
        try {
            Decoder<?, List<SOAPHeaderElement>> decoder = getDecoder(new XmlNamespaceDecoderKey(namespace, SOAPHeaderElement.class));
            if (decoder != null) {
                Object object = decoder.decode(headersByNamespace.get(namespace));
                if (object instanceof SoapHeader) {
                    soapHeaders.add((SoapHeader) object);
                } else if (object instanceof List<?>) {
                    for (Object o : (List<?>) object) {
                        if (o instanceof SoapHeader) {
                            soapHeaders.add((SoapHeader) o);
                        }
                    }
                }
            } else {
                LOGGER.info("The SOAP-Header elements for namespace '{}' are not supported by this server!", namespace);
            }
        } catch (DecodingException owse) {
            LOGGER.debug("Requested SOAPHeader element is not supported", owse);
        }
    }
    return soapHeaders;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) HashMap(java.util.HashMap) DecodingException(org.n52.svalbard.decode.exception.DecodingException) LinkedList(java.util.LinkedList) SoapHeader(org.n52.shetland.w3c.soap.SoapHeader) LinkedList(java.util.LinkedList) List(java.util.List) XmlObject(org.apache.xmlbeans.XmlObject)

Example 3 with SoapHeader

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

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

SoapHeader (org.n52.shetland.w3c.soap.SoapHeader)4 XmlObject (org.apache.xmlbeans.XmlObject)2 WsaActionHeader (org.n52.shetland.w3c.wsa.WsaActionHeader)2 WsaHeader (org.n52.shetland.w3c.wsa.WsaHeader)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 CommunicationObjectWithSoapHeader (org.n52.iceland.service.CommunicationObjectWithSoapHeader)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)1 Node (org.w3c.dom.Node)1