Search in sources :

Example 41 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 42 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 43 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 44 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)

Example 45 with Header

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

the class MAPCodecTest method setUpHeaderDecode.

private <T> void setUpHeaderDecode(List<Header> headers, String uri, String name, Class<?> clz, int index, Unmarshaller unmarshaller) throws Exception {
    Element headerElement = control.createMock(Element.class);
    headers.add(new Header(new QName(uri, name), headerElement));
    headerElement.getNamespaceURI();
    EasyMock.expectLastCall().andReturn(uri);
    headerElement.getLocalName();
    EasyMock.expectLastCall().andReturn(name);
    Object v = expectedValues[index];
    @SuppressWarnings("unchecked") JAXBElement<?> jaxbElement = new JAXBElement<Object>(new QName(uri, name), (Class<Object>) clz, clz.cast(v));
    unmarshaller.unmarshal(headerElement, clz);
    EasyMock.expectLastCall().andReturn(jaxbElement);
}
Also used : Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

Header (org.apache.cxf.headers.Header)56 Element (org.w3c.dom.Element)25 ArrayList (java.util.ArrayList)19 JAXBException (javax.xml.bind.JAXBException)19 QName (javax.xml.namespace.QName)19 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)18 JAXBElement (javax.xml.bind.JAXBElement)14 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)13 Node (org.w3c.dom.Node)11 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)10 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)10 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 List (java.util.List)7 MessageContext (javax.xml.ws.handler.MessageContext)7 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)7 Fault (org.apache.cxf.interceptor.Fault)6 Message (org.apache.cxf.message.Message)6 Test (org.junit.Test)6 Exchange (org.apache.cxf.message.Exchange)5 MessageContentsList (org.apache.cxf.message.MessageContentsList)5