org.apache.cxf.binding.soap.SoapHeader Java Examples

The following examples show how to use org.apache.cxf.binding.soap.SoapHeader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #2
Source File: MustUnderstandInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(SoapMessage soapMessage) throws Fault {
    SoapVersion soapVersion = soapMessage.getVersion();
    Set<QName> notFound = new HashSet<>();
    List<Header> heads = soapMessage.getHeaders();

    for (Header header : heads) {
        if (header instanceof SoapHeader
            && ((SoapHeader)header).isMustUnderstand()
            && header.getDirection() == Header.Direction.DIRECTION_IN
            && !knownHeaders.contains(header.getName())
            && (StringUtils.isEmpty(((SoapHeader)header).getActor())
                || soapVersion.getUltimateReceiverRole()
                    .equals(((SoapHeader)header).getActor()))) {

            notFound.add(header.getName());
        }
    }


    if (!notFound.isEmpty()) {
        soapMessage.remove(UNKNOWNS);
        throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
                        soapVersion.getMustUnderstand());
    }
}
 
Example #3
Source File: AbstractTokenInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if ("Security".equals(n.getLocalPart())
            && (n.getNamespaceURI().equals(WSS4JConstants.WSSE_NS)
                || n.getNamespaceURI().equals(WSS4JConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.getEmptyDocument();
    Element el = doc.createElementNS(WSS4JConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns:wsse", WSS4JConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSS4JConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #4
Source File: IntFaultClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void assertSoapHeader(BindingProvider serviceProxy) {
    List<?> headers = (List<?>) serviceProxy.getResponseContext().get(Header.HEADER_LIST);
    QName testQName = new QName("http://test", "test");
    if (headers != null) {
        for (Object o : headers) {
            if (o instanceof SoapHeader) {
                SoapHeader soapHeader = (SoapHeader) o;
                QName qName = soapHeader.getName();
                if (testQName.getNamespaceURI().equals(qName.getNamespaceURI())
                        && testQName.getLocalPart().equals(qName.getLocalPart())) {
                    Node returnedContent = (Node) soapHeader.getObject();
                    assertEquals("test", returnedContent.getTextContent());
                    return;
                }
            }
        }
    }
    fail("Header not found");
}
 
Example #5
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #6
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #7
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #8
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #9
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #10
Source File: SamlTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #11
Source File: UsernameTokenInterceptor.java    From steady with Apache License 2.0 6 votes vote down vote up
private Header findSecurityHeader(SoapMessage message, boolean create) {
    for (Header h : message.getHeaders()) {
        QName n = h.getName();
        if (n.getLocalPart().equals("Security")
            && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) 
                || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) {
            return h;
        }
    }
    if (!create) {
        return null;
    }
    Document doc = DOMUtils.createDocument();
    Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security");
    el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
    SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el);
    sh.setMustUnderstand(true);
    message.getHeaders().add(sh);
    return sh;
}
 
Example #12
Source File: CXFWSProducerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCxfSoapHeader() throws Exception {
    deployer.deploy(SIMPLE_WAR);
    try {
        CamelContext camelctx = new DefaultCamelContext();
        camelctx.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        List<SoapHeader> soapHeaders = new ArrayList<SoapHeader>();

                        String headerXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><input xmlns=\"http://wildfly.camel.test.cxf\">Kermit</input>";

                        SoapHeader soapHeader = new SoapHeader(new QName("http://wildfly.camel.test.cxf", "input"), getSoapHeaderElement(headerXml));
                        soapHeader.setDirection(Header.Direction.DIRECTION_IN);
                        soapHeaders.add(soapHeader);

                        exchange.getOut().setHeader(Header.HEADER_LIST, soapHeaders);
                    }
                })
                .to("cxf://" + getEndpointAddress("/simple") + "?serviceClass=" + Endpoint.class.getName());
            }
        });

        camelctx.start();
        try {
            ProducerTemplate producer = camelctx.createProducerTemplate();
            String result = producer.requestBody("direct:start", null, String.class);
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            camelctx.close();
        }
    } finally {
        deployer.undeploy(SIMPLE_WAR);
    }
}
 
Example #13
Source File: MustUnderstandInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void buildMustUnderstandHeaders(Set<Header> mustUnderstandHeaders,
                                        SoapMessage soapMessage,
                                        Set<URI> serviceRoles,
                                        Set<Header> ultimateReceiverHeaders) {
    for (Header header : soapMessage.getHeaders()) {
        if (header instanceof SoapHeader && ((SoapHeader)header).isMustUnderstand()) {
            String role = ((SoapHeader)header).getActor();
            if (!StringUtils.isEmpty(role)) {
                role = role.trim();
                if (role.equals(soapMessage.getVersion().getNextRole())) {
                    mustUnderstandHeaders.add(header);
                } else if (role.equals(soapMessage.getVersion().getUltimateReceiverRole())) {
                    ultimateReceiverHeaders.add(header);
                } else {
                    for (URI roleFromBinding : serviceRoles) {
                        if (role.equals(roleFromBinding.toString())) {
                            mustUnderstandHeaders.add(header);
                        }
                    }
                }
            } else {
                // if role omitted, the soap node is ultimate receiver,
                // needs to understand
                ultimateReceiverHeaders.add(header);
            }
        }
    }
}
 
Example #14
Source File: SoapOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public SOAPHeaderWriter(XMLStreamWriter writer,
                        SoapHeader header,
                        SoapVersion version,
                        String pfx) {
    super(writer);
    soapHeader = header;
    soapVersion = version;
    soapPrefix = pfx;
}
 
Example #15
Source File: EncoderDecoder10AImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement> acks,
    Collection<AckRequestedType> reqs, boolean last, List<Header> headers) throws JAXBException {
   
    if (null != seq) {
        LOG.log(Level.FINE, "encoding sequence into RM header");
        org.apache.cxf.ws.rm.v200502wsa15.SequenceType toseq = VersionTransformer.convert200502wsa15(seq);
        if (last) {
            toseq.setLastMessage(new org.apache.cxf.ws.rm.v200502wsa15.SequenceType.LastMessage());
        }
        JAXBElement<org.apache.cxf.ws.rm.v200502wsa15.SequenceType> element
            = RMUtils.getWSRM200502WSA200508Factory().createSequence(toseq);
        headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true));
    }
    if (null != acks) {
        LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header");
        for (SequenceAcknowledgement ack : acks) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.SEQUENCE_ACK_NAME),
                                       VersionTransformer.convert200502wsa15(ack), getDataBinding()));
        }
    }
    if (null != reqs) {
        LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header");
        for (AckRequestedType req : reqs) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.ACK_REQUESTED_NAME),
                                       RMUtils.getWSRM200502WSA200508Factory()
                                           .createAckRequested(VersionTransformer.convert200502wsa15(req)),
                                       getDataBinding()));
        }
    }
}
 
Example #16
Source File: EncoderDecoder10Impl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement> acks,
    Collection<AckRequestedType> reqs, boolean last, List<Header> headers) throws JAXBException {       
    if (null != seq) {
        LOG.log(Level.FINE, "encoding sequence into RM header");
        org.apache.cxf.ws.rm.v200502.SequenceType toseq = VersionTransformer.convert200502(seq);
        if (last) {
            toseq.setLastMessage(new org.apache.cxf.ws.rm.v200502.SequenceType.LastMessage());
        }
        JAXBElement<?> element = RMUtils.getWSRM200502Factory().createSequence(toseq);
        headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true));
    }
    if (null != acks) {
        LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header");
        for (SequenceAcknowledgement ack : acks) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.SEQUENCE_ACK_NAME),
                                       VersionTransformer.convert200502(ack),
                                       getDataBinding()));
        }
    }
    if (null != reqs) {
        LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header");
        for (AckRequestedType req : reqs) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.ACK_REQUESTED_NAME),
                                       RMUtils.getWSRM200502Factory()
                                           .createAckRequested(VersionTransformer.convert200502(req)),
                                       getDataBinding()));
        }
    }
    
}
 
Example #17
Source File: EncoderDecoder11Impl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement> acks,
    Collection<AckRequestedType> reqs, boolean last, List<Header> headers) throws JAXBException {

    if (null != seq) {
        LOG.log(Level.FINE, "encoding sequence into RM header");
        JAXBElement<SequenceType> element = RMUtils.getWSRMFactory().createSequence(seq);
        headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true));
    }
    if (null != acks) {
        LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header");
        for (SequenceAcknowledgement ack : acks) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.SEQUENCE_ACK_NAME),
                                       ack, getDataBinding()));
        }
    }
    if (null != reqs) {
        LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header");
        for (AckRequestedType req : reqs) {
            headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), 
                                                 RMConstants.ACK_REQUESTED_NAME),
                                       RMUtils.getWSRMFactory().createAckRequested(req),
                                       getDataBinding()));
        }
    }
}
 
Example #18
Source File: MAPCodec.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Encodes an MAP as a SOAP header.
 *
 * @param message the message to store the headers on
 * @param value the value to encode
 * @param qname the QName for the header
 * @param clz the class
 * @param ctx the JAXBContent
 * @param mustUnderstand
 */
protected <T> void encodeMAP(SoapMessage message,
                             T value,
                             QName qname,
                             Class<T> clz,
                             JAXBContext ctx,
                             boolean mustUnderstand) throws JAXBException {
    JAXBDataBinding jaxbDataBinding = new JAXBDataBinding(ctx);
    SoapHeader h = new SoapHeader(qname, new JAXBElement<T>(qname, clz, value),
                                  jaxbDataBinding);
    h.setMustUnderstand(mustUnderstand);
    message.getHeaders().add(h);
}
 
Example #19
Source File: PolicyBasedSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void runInInterceptorAndValidateWss(Document document, AssertionInfoMap aim,
                                              List<CoverageType> types) throws Exception {

    PolicyBasedWSS4JInInterceptor inHandler =
        this.getInInterceptor(types);

    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);

    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(),
                                                             securityHeaderElem.getLocalName()),
                                                   securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }

    // Necessary because the Bearer Assertion does not have an internal signature
    SamlAssertionValidator assertionValidator = new SamlAssertionValidator();
    assertionValidator.setRequireBearerSignature(false);
    inmsg.put(SecurityConstants.SAML2_TOKEN_VALIDATOR, assertionValidator);
    inmsg.put(SecurityConstants.SAML1_TOKEN_VALIDATOR, assertionValidator);
    inHandler.handleMessage(inmsg);

    for (CoverageType type : types) {
        switch(type) {
        case SIGNED:
            this.verifyWss4jSigResults(inmsg);
            break;
        case ENCRYPTED:
            this.verifyWss4jEncResults(inmsg);
            break;
        default:
            fail("Unsupported coverage type.");
        }
    }
}
 
Example #20
Source File: AbstractPolicySecurityTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void runInInterceptorAndValidateWss(Document document, AssertionInfoMap aim,
        List<CoverageType> types) throws Exception {

    PolicyBasedWSS4JInInterceptor inHandler = this.getInInterceptor(types);

    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);

    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(),
                                                             securityHeaderElem.getLocalName()),
                                                   securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }

    final Endpoint endpoint = inmsg.getExchange().getEndpoint();
    if (endpoint != null && endpoint.getEndpointInfo().getProperty(TokenStore.class.getName()) == null) {
        inmsg.put(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, new MemoryTokenStore());
    }
    inHandler.handleMessage(inmsg);

    for (CoverageType type : types) {
        switch(type) {
        case SIGNED:
            this.verifyWss4jSigResults(inmsg);
            break;
        case ENCRYPTED:
            this.verifyWss4jEncResults(inmsg);
            break;
        default:
            fail("Unsupported coverage type.");
        }
    }
}
 
Example #21
Source File: PluggablePolicyValidatorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void runInInterceptorAndValidateWss(
    Document document, AssertionInfoMap aim, List<CoverageType> types,
    Map<QName, SecurityPolicyValidator> validators
) throws Exception {

    PolicyBasedWSS4JInInterceptor inHandler = this.getInInterceptor(types);

    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);

    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(),
                                                             securityHeaderElem.getLocalName()),
                                                   securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }

    if (validators != null) {
        inmsg.put(SecurityConstants.POLICY_VALIDATOR_MAP, validators);
    }

    inHandler.handleMessage(inmsg);

    for (CoverageType type : types) {
        switch(type) {
        case SIGNED:
            this.verifyWss4jSigResults(inmsg);
            break;
        case ENCRYPTED:
            this.verifyWss4jEncResults(inmsg);
            break;
        default:
            fail("Unsupported coverage type.");
        }
    }
}
 
Example #22
Source File: HeaderProcessor.java    From container with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a SoapHeader
 *
 * @param key     of the header
 * @param content of the header
 * @return SoapHeader
 */
private SoapHeader getSoapHeader(final String key, final String content) {
    final String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><" + key + ">" + content + "</" + key + ">";
    try {
        return new SoapHeader(new QName(key), readXml(new StringReader(xml)).getDocumentElement());
    } catch (final SAXException | IOException | ParserConfigurationException e) {
        LOG.warn("Failed to read SOAP Header {} -> {} with exception", key, content, e);
    }
    return null;
}
 
Example #23
Source File: HeaderProcessor.java    From container with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {
    final CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);

    final Map<String, Object> headers = exchange.getIn().getHeaders();
    if (!headers.containsKey("SOAPEndpoint")) {
        headers.put("SOAPEndpoint", headers.get("endpoint"));
    }
    for (final Map.Entry<String, Object> entry : headers.entrySet()) {

        if (entry.getKey().equalsIgnoreCase("ReplyTo")) {

            final String xml1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ReplyTo "
                + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"><wsa:Address>" + entry.getValue().toString()
                + "</wsa:Address></ReplyTo>";
            final SoapHeader replyToSoapHeader =
                new SoapHeader(new QName("http://www.w3.org/2005/08/addressing", "ReplyTo"),
                    readXml(new StringReader(xml1)).getDocumentElement());
            payload.getHeaders().add(replyToSoapHeader);
        } else if (entry.getKey().equalsIgnoreCase("MessageID")) {
            final String xml2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MessageID "
                + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + entry.getValue().toString()
                + "</MessageID>";
            final SoapHeader messageIdSoapHeader =
                new SoapHeader(new QName("http://www.w3.org/2005/08/addressing", "MessageID"),
                    readXml(new StringReader(xml2)).getDocumentElement());
            payload.getHeaders().add(messageIdSoapHeader);
        } else {
            payload.getHeaders().add(this.getSoapHeader(entry.getKey(), entry.getValue().toString()));
        }
    }
    exchange.getIn().setBody(payload);
}
 
Example #24
Source File: CxfProcessLaunchHandler.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Assumes a 'MasterRequestID' SOAP header element.  Override for something different.
 */
@SuppressWarnings("unchecked")
@Override
public String getMasterRequestId(Message request) {
    List<SoapHeader> headers = (List<SoapHeader>) ((CxfPayload<?>)request.getBody()).getHeaders();
    for (SoapHeader header : headers) {
        if (header.getName().getLocalPart().equals("MasterRequestID")) {
            Node headerNode = (Node) header.getObject();
            return headerNode.getTextContent();
        }
    }
    return null;
}
 
Example #25
Source File: AbstractSecurityTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected SoapMessage makeInvocation(
    Map<String, Object> outProperties,
    List<String> xpaths,
    Map<String, Object> inProperties
) throws Exception {
    Document doc = readDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = getSoapMessageForDom(doc);

    for (String key : outProperties.keySet()) {
        msg.put(key, outProperties.get(key));
    }

    handler.handleMessage(msg);

    SOAPMessage saajMsg = msg.getContent(SOAPMessage.class);
    doc = saajMsg.getSOAPPart();

    for (String xpath : xpaths) {
        assertValid(xpath, doc);
    }

    byte[] docbytes = getMessageBytes(doc);
    doc = StaxUtils.read(new ByteArrayInputStream(docbytes));

    WSS4JInInterceptor inHandler = new WSS4JInInterceptor(inProperties);

    SoapMessage inmsg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(inmsg);
    inmsg.setContent(SOAPMessage.class, saajMsg);

    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(doc, "");
    SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(),
                                                         securityHeaderElem.getLocalName()), securityHeaderElem);
    inmsg.getHeaders().add(securityHeader);

    inHandler.handleMessage(inmsg);

    return inmsg;
}