Search in sources :

Example 61 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class RMSoapOutInterceptorTest method verifyHeaders.

private void verifyHeaders(SoapMessage message, String... names) {
    List<Header> headers = new ArrayList<Header>(message.getHeaders());
    for (String name : names) {
        boolean found = false;
        Iterator<Header> iter = headers.iterator();
        while (iter.hasNext()) {
            Header header = iter.next();
            Object obj = header.getObject();
            String namespace = header.getName().getNamespaceURI();
            String localName = header.getName().getLocalPart();
            if (obj instanceof Element) {
                Element elem = (Element) obj;
                namespace = elem.getNamespaceURI();
                localName = elem.getLocalName();
            }
            if (RM10Constants.NAMESPACE_URI.equals(namespace) && localName.equals(name)) {
                found = true;
                iter.remove();
                break;
            } else if (Names.WSA_NAMESPACE_NAME.equals(namespace) && localName.equals(name)) {
                found = true;
                iter.remove();
                break;
            }
        }
        assertTrue("Could not find header element " + name, found);
    }
    // no other headers should be present
    if (!headers.isEmpty()) {
        assertTrue("Unexpected header element " + headers.get(0).getName(), false);
    }
}
Also used : Header(org.apache.cxf.headers.Header) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 62 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class RMSoapInInterceptor method decodeHeaders.

public void decodeHeaders(SoapMessage message, List<Header> headers, RMProperties rmps) {
    try {
        Collection<SequenceAcknowledgement> acks = new ArrayList<>();
        Collection<AckRequestedType> requested = new ArrayList<>();
        String rmUri = null;
        EncoderDecoder codec = null;
        Iterator<Header> iter = headers.iterator();
        while (iter.hasNext()) {
            Object node = iter.next().getObject();
            if (node instanceof Element) {
                Element elem = (Element) node;
                if (Node.ELEMENT_NODE != elem.getNodeType()) {
                    continue;
                }
                String ns = elem.getNamespaceURI();
                if (rmUri == null && (RM10Constants.NAMESPACE_URI.equals(ns) || RM11Constants.NAMESPACE_URI.equals(ns))) {
                    LOG.log(Level.FINE, "set RM namespace {0}", ns);
                    rmUri = ns;
                    rmps.exposeAs(rmUri);
                }
                if (rmUri != null && rmUri.equals(ns)) {
                    if (codec == null) {
                        String wsauri = null;
                        AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
                        if (maps == null) {
                            RMConfiguration config = getManager(message).getEffectiveConfiguration(message);
                            wsauri = config.getAddressingNamespace();
                        } else {
                            wsauri = maps.getNamespaceURI();
                        }
                        ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, wsauri);
                        if (protocol == null) {
                            LOG.log(Level.WARNING, "NAMESPACE_ERROR_MSG", wsauri);
                            break;
                        }
                        codec = protocol.getCodec();
                    }
                    String localName = elem.getLocalName();
                    LOG.log(Level.FINE, "decoding RM header {0}", localName);
                    if (RMConstants.SEQUENCE_NAME.equals(localName)) {
                        rmps.setSequence(codec.decodeSequenceType(elem));
                        rmps.setCloseSequence(codec.decodeSequenceTypeCloseSequence(elem));
                    } else if (RMConstants.SEQUENCE_ACK_NAME.equals(localName)) {
                        acks.add(codec.decodeSequenceAcknowledgement(elem));
                    } else if (RMConstants.ACK_REQUESTED_NAME.equals(localName)) {
                        requested.add(codec.decodeAckRequestedType(elem));
                    }
                }
            }
        }
        if (!acks.isEmpty()) {
            rmps.setAcks(acks);
        }
        if (!requested.isEmpty()) {
            rmps.setAcksRequested(requested);
        }
    } catch (JAXBException ex) {
        LOG.log(Level.WARNING, "SOAP_HEADER_DECODE_FAILURE_MSG", ex);
    }
}
Also used : EncoderDecoder(org.apache.cxf.ws.rm.EncoderDecoder) Element(org.w3c.dom.Element) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) Header(org.apache.cxf.headers.Header) AckRequestedType(org.apache.cxf.ws.rm.v200702.AckRequestedType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Example 63 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class DecoupledFaultHandler method handleFault.

// Ideally, this code will instead be executed as part of the Fault chain
// but at the moment PhaseInterceptorChain needs to be tricked that this is
// a two way request for a fault chain be invoked
public void handleFault(SoapMessage message) {
    if (!ContextUtils.isRequestor(message)) {
        Exchange exchange = message.getExchange();
        Message inMessage = exchange.getInMessage();
        final AddressingProperties maps = ContextUtils.retrieveMAPs(inMessage, false, false, true);
        if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) {
            // Just keep the wsa headers to remove the not understand headers
            if (exchange.getOutMessage() != null) {
                message = (SoapMessage) exchange.getOutMessage();
            }
            Iterator<Header> iterator = message.getHeaders().iterator();
            while (iterator.hasNext()) {
                Header header = iterator.next();
                if (!isWSAHeader(header)) {
                    iterator.remove();
                }
            }
            exchange.setOneWay(false);
            exchange.setOutMessage(message);
            // manually set the action
            message.put(ContextUtils.ACTION, WSA_ACTION);
            Destination destination = createDecoupledDestination(exchange, maps.getFaultTo());
            exchange.setDestination(destination);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Destination(org.apache.cxf.transport.Destination) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) Header(org.apache.cxf.headers.Header) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 64 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class MAPCodec method encode.

/**
 * Encode the current MAPs in protocol-specific headers.
 *
 * @param message the messsage message
 * @param maps the MAPs to encode
 */
private void encode(SoapMessage message, AddressingProperties maps) {
    if (maps != null) {
        cacheExchange(message, maps);
        LOG.log(Level.FINE, "Outbound WS-Addressing headers");
        try {
            List<Header> header = message.getHeaders();
            discardMAPs(header, maps);
            JAXBContext jaxbContext = org.apache.cxf.ws.addressing.VersionTransformer.getExposedJAXBContext(maps.getNamespaceURI());
            QName duplicate = maps.getDuplicate();
            encodeAsExposed(maps, message, maps.getAction(), Names.WSA_ACTION_QNAME, AttributedURIType.class, jaxbContext);
            if (Names.WSA_ACTION_QNAME.equals(duplicate)) {
                encodeAsExposed(maps, message, maps.getAction(), Names.WSA_ACTION_QNAME, AttributedURIType.class, jaxbContext);
            }
            encodeAsExposed(maps, message, maps.getMessageID(), Names.WSA_MESSAGEID_QNAME, AttributedURIType.class, jaxbContext);
            if (Names.WSA_MESSAGEID_QNAME.equals(duplicate)) {
                encodeAsExposed(maps, message, maps.getMessageID(), Names.WSA_MESSAGEID_QNAME, AttributedURIType.class, jaxbContext);
            }
            encodeAsExposed(maps, message, maps.getTo(), Names.WSA_TO_QNAME, AttributedURIType.class, jaxbContext);
            if (Names.WSA_TO_QNAME.equals(duplicate)) {
                encodeAsExposed(maps, message, maps.getTo(), Names.WSA_TO_QNAME, AttributedURIType.class, jaxbContext);
            }
            if (needsReplyTo(maps, message)) {
                encodeAsExposed(maps, message, maps.getReplyTo(), Names.WSA_REPLYTO_QNAME, EndpointReferenceType.class, jaxbContext);
                if (Names.WSA_REPLYTO_QNAME.equals(duplicate)) {
                    encodeAsExposed(maps, message, maps.getReplyTo(), Names.WSA_REPLYTO_QNAME, EndpointReferenceType.class, jaxbContext);
                }
            }
            encodeAsExposed(maps, message, maps.getRelatesTo(), Names.WSA_RELATESTO_QNAME, RelatesToType.class, jaxbContext);
            if (Names.WSA_RELATESTO_QNAME.equals(duplicate)) {
                encodeAsExposed(maps, message, maps.getRelatesTo(), Names.WSA_RELATESTO_QNAME, RelatesToType.class, jaxbContext);
            }
            encodeAsExposed(maps, message, maps.getFrom(), Names.WSA_FROM_QNAME, EndpointReferenceType.class, jaxbContext);
            if (Names.WSA_FROM_QNAME.equals(duplicate)) {
                encodeAsExposed(maps, message, maps.getFrom(), Names.WSA_FROM_QNAME, EndpointReferenceType.class, jaxbContext);
            }
            if (needsFaultTo(maps)) {
                encodeAsExposed(maps, message, maps.getFaultTo(), Names.WSA_FAULTTO_QNAME, EndpointReferenceType.class, jaxbContext);
                if (Names.WSA_FAULTTO_QNAME.equals(duplicate)) {
                    encodeAsExposed(maps, message, maps.getFaultTo(), Names.WSA_FAULTTO_QNAME, EndpointReferenceType.class, jaxbContext);
                }
            }
            encodeReferenceParameters(maps, message, jaxbContext);
            maps.setDuplicate(null);
            propogateAction(maps.getAction(), message);
            applyMAPValidation(message);
        } catch (JAXBException je) {
            LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
        }
    }
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 65 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class MAPCodecTest method setUpMessage.

private SoapMessage setUpMessage(boolean requestor, boolean outbound, boolean invalidMAP, boolean preExistingSOAPAction, Boolean generateRelatesTo, String exposeAs) throws Exception {
    SoapMessage message = new SoapMessage(new MessageImpl());
    setUpOutbound(message, outbound);
    expectRelatesTo = generateRelatesTo != null ? generateRelatesTo : (requestor && !outbound) || (!requestor && outbound);
    message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
    String mapProperty = getMAPProperty(requestor, outbound);
    AddressingProperties maps = getMAPs(requestor, outbound, exposeAs);
    final Element header = control.createMock(Element.class);
    codec.setHeaderFactory(new MAPCodec.HeaderFactory() {

        public Element getHeader(SoapVersion version) {
            return header;
        }
    });
    List<Header> headers = message.getHeaders();
    JAXBContext jaxbContext = control.createMock(JAXBContext.class);
    ContextUtils.setJAXBContext(jaxbContext);
    Names200408.setJAXBContext(jaxbContext);
    Names200403.setJAXBContext(jaxbContext);
    if (outbound) {
        setUpEncode(requestor, message, header, maps, mapProperty, invalidMAP, preExistingSOAPAction);
    } else {
        setUpDecode(message, headers, maps, mapProperty, requestor);
    }
    control.replay();
    return message;
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) Header(org.apache.cxf.headers.Header) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) JAXBContext(javax.xml.bind.JAXBContext) MessageImpl(org.apache.cxf.message.MessageImpl) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Aggregations

Header (org.apache.cxf.headers.Header)78 QName (javax.xml.namespace.QName)29 Element (org.w3c.dom.Element)27 ArrayList (java.util.ArrayList)25 JAXBException (javax.xml.bind.JAXBException)24 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)18 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)17 Node (org.w3c.dom.Node)16 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)15 JAXBElement (javax.xml.bind.JAXBElement)14 List (java.util.List)13 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)13 MessageContext (javax.xml.ws.handler.MessageContext)9 Test (org.junit.Test)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)7 Message (org.apache.cxf.message.Message)7 HashMap (java.util.HashMap)6 Fault (org.apache.cxf.interceptor.Fault)6 Exchange (org.apache.cxf.message.Exchange)6