Search in sources :

Example 26 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class CorrelationIDProcessor method process.

static void process(Message message, Assertion policy) throws SAXException, IOException, ParserConfigurationException {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Message process for correlation ID started");
    }
    String correlationId = null;
    // get ID from SOAP header
    correlationId = CorrelationIdSoapCodec.readCorrelationId(message);
    // get ID from Http header
    if (null == correlationId) {
        correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
    }
    // get from message
    if (null == correlationId) {
        // Get ID from Message
        correlationId = (String) message.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
    }
    if ((message.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (message.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter)) {
        NodeList nodeList = ((SAAJStreamWriter) message.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId");
        if (nodeList.getLength() > 0) {
            correlationId = nodeList.item(0).getTextContent();
        }
    }
    // get from message exchange
    if (null == correlationId) {
        // Get ID from Message exchange
        Exchange ex = message.getExchange();
        if (null != ex) {
            Message reqMsg = null;
            if (MessageUtils.isOutbound(message)) {
                reqMsg = ex.getInMessage();
            } else {
                reqMsg = ex.getOutMessage();
            }
            if (null != reqMsg) {
                correlationId = (String) reqMsg.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
            }
        }
    }
    // If correlationId is null we should add it to headers
    if (null == correlationId) {
        MethodType mType = CorrelationIDAssertion.MethodType.CALLBACK;
        if (policy instanceof CorrelationIDAssertion) {
            mType = ((CorrelationIDAssertion) policy).getMethodType();
        }
        if (MethodType.XPATH.equals(mType) && !MessageUtils.isFault(message)) {
            XPathProcessor proc = new XPathProcessor(policy, message);
            correlationId = proc.getCorrelationID();
        } else if (MethodType.CALLBACK.equals(mType)) {
            CorrelationIDCallbackHandler handler = (CorrelationIDCallbackHandler) message.get(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
            if (null == handler) {
                handler = (CorrelationIDCallbackHandler) message.getContextualProperty(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
            }
            if (handler != null)
                correlationId = handler.getCorrelationId();
        }
        // request
        if (null == correlationId) {
            correlationId = ContextUtils.generateUUID();
        }
    }
    message.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, correlationId);
    if (isRestMessage(message)) {
        // Add correlationId to http header
        if (null == CorrelationIdProtocolHeaderCodec.readCorrelationId(message)) {
            CorrelationIdProtocolHeaderCodec.writeCorrelationId(message, correlationId);
        }
    } else {
        // Add correlationId to soap header
        if (null == CorrelationIdSoapCodec.readCorrelationId(message)) {
            CorrelationIdSoapCodec.writeCorrelationId(message, correlationId);
        }
    }
}
Also used : MethodType(org.talend.esb.policy.correlation.impl.CorrelationIDAssertion.MethodType) Message(org.apache.cxf.message.Message) NodeList(org.w3c.dom.NodeList) SAAJStreamWriter(org.apache.cxf.binding.soap.saaj.SAAJStreamWriter) Exchange(org.apache.cxf.message.Exchange) CorrelationIDCallbackHandler(org.talend.esb.policy.correlation.CorrelationIDCallbackHandler)

Example 27 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class XPathProcessor method getEncoding.

private String getEncoding(Message message) {
    Exchange ex = message.getExchange();
    String encoding = (String) message.get(Message.ENCODING);
    if (encoding == null && ex.getInMessage() != null) {
        encoding = (String) ex.getInMessage().get(Message.ENCODING);
        message.put(Message.ENCODING, encoding);
    }
    if (encoding == null) {
        encoding = "UTF-8";
        message.put(Message.ENCODING, encoding);
    }
    return encoding;
}
Also used : Exchange(org.apache.cxf.message.Exchange)

Example 28 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class SOAPConnectionImpl method get.

@Override
public SOAPMessage get(Object addressObject) throws SOAPException {
    checkClosed();
    String address = getAddress(addressObject);
    ConduitInitiator ci = getConduitInitiator(address);
    // create a new Message and Exchange
    EndpointInfo info = new EndpointInfo();
    info.setAddress(address);
    Message outMessage = new MessageImpl();
    Exchange exch = new ExchangeImpl();
    outMessage.setExchange(exch);
    // sent GET request
    try {
        // TODO verify bus
        final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false));
        if (c instanceof HTTPConduit) {
            ((HTTPConduit) c).getClient().setAutoRedirect(true);
        }
        outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
        c.prepare(outMessage);
        c.setMessageObserver(createMessageObserver(c));
        c.close(outMessage);
    } catch (Exception ex) {
        throw MESSAGES.getRequestCouldNotBeSent(ex);
    }
    // read SOAPMessage
    return readSoapMessage(exch);
}
Also used : Exchange(org.apache.cxf.message.Exchange) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException)

Example 29 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class HandlerChainSortInterceptor method handleMessage.

@Override
@SuppressWarnings("rawtypes")
public void handleMessage(Message message) throws Fault {
    if (binding != null) {
        Exchange ex = message.getExchange();
        if (ex.get(HandlerChainInvoker.class) == null) {
            List<Handler> hc = binding.getHandlerChain();
            if (hc.size() > 1) {
                // no need to sort etc if the chain is empty or has one handler only
                Collections.sort(hc, comparator);
                // install a new HandlerChainInvoker using the sorted handler chain;
                // the AbstractJAXWSHandlerInterceptor will be using this invoker
                // instead of creating a new one
                ex.put(HandlerChainInvoker.class, new HandlerChainInvoker(hc, isOutbound(message, ex)));
            }
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) Handler(javax.xml.ws.handler.Handler)

Example 30 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class JBossWSInvokerTest method getTestExchange.

// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
    Exchange exchange = new ExchangeImpl();
    Message message = new MessageImpl();
    message.setExchange(exchange);
    exchange.setInMessage(message);
    exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
    Service service = new ServiceImpl();
    MethodDispatcher md = new MethodDispatcher() {

        @Override
        public Method getMethod(BindingOperationInfo op) {
            return this.getClass().getMethods()[0];
        }

        @Override
        public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
            return null;
        }

        @Override
        public void bind(OperationInfo o, Method... methods) {
        }
    };
    service.put(MethodDispatcher.class.getName(), md);
    exchange.put(Service.class, service);
    return exchange;
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Method(java.lang.reflect.Method) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

Exchange (org.apache.cxf.message.Exchange)338 Message (org.apache.cxf.message.Message)196 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)159 MessageImpl (org.apache.cxf.message.MessageImpl)144 Test (org.junit.Test)119 Endpoint (org.apache.cxf.endpoint.Endpoint)75 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)62 QName (javax.xml.namespace.QName)51 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)43 Bus (org.apache.cxf.Bus)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Conduit (org.apache.cxf.transport.Conduit)31 Fault (org.apache.cxf.interceptor.Fault)30 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)28 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)28 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Service (org.apache.cxf.service.Service)22 SOAPMessage (javax.xml.soap.SOAPMessage)21 List (java.util.List)19