Search in sources :

Example 96 with Exchange

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

the class BackChannelConduit method prepare.

/**
 * Send an outbound message, assumed to contain all the name-value mappings of the corresponding input
 * message (if any).
 *
 * @param message the message to be sent.
 */
public void prepare(final Message message) throws IOException {
    // setup the message to be sent back
    javax.jms.Message jmsMessage = (javax.jms.Message) inMessage.get(JMSConstants.JMS_REQUEST_MESSAGE);
    message.put(JMSConstants.JMS_REQUEST_MESSAGE, jmsMessage);
    if (!message.containsKey(JMSConstants.JMS_SERVER_RESPONSE_HEADERS) && inMessage.containsKey(JMSConstants.JMS_SERVER_RESPONSE_HEADERS)) {
        message.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, inMessage.get(JMSConstants.JMS_SERVER_RESPONSE_HEADERS));
    }
    Exchange exchange = inMessage.getExchange();
    exchange.setOutMessage(message);
    boolean isTextMessage = (jmsMessage instanceof TextMessage) && !JMSMessageUtils.isMtomEnabled(message);
    MessageStreamUtil.prepareStream(message, isTextMessage, this);
}
Also used : Exchange(org.apache.cxf.message.Exchange) TextMessage(javax.jms.TextMessage) Message(org.apache.cxf.message.Message) TextMessage(javax.jms.TextMessage)

Example 97 with Exchange

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

the class JMSConduit method getExchange.

/**
 *  Try to correlate the incoming message with some timeout as it may have been
 *  added to the map after the message was sent
 *
 * @param correlationId
 * @return exchange for correlationId or null if none was found
 */
private Exchange getExchange(String correlationId) {
    int count = 0;
    Exchange exchange = null;
    while (exchange == null && count < 100) {
        exchange = correlationMap.remove(correlationId);
        if (exchange == null) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException("Interrupted while correlating", e);
            }
        }
        count++;
    }
    return exchange;
}
Also used : Exchange(org.apache.cxf.message.Exchange)

Example 98 with Exchange

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

the class AbstractJMSTester method createMessageObserver.

protected MessageObserver createMessageObserver() {
    return new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            destMessage = m;
        }
    };
}
Also used : Exchange(org.apache.cxf.message.Exchange) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 99 with Exchange

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

the class JMSDestinationTest method testRoundTripDestination.

private Message testRoundTripDestination(boolean createSecurityContext) throws Exception {
    EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    conduit.getJmsConfig().setCreateSecurityContext(createSecurityContext);
    final Message outMessage = new MessageImpl();
    setupMessageHeader(outMessage, null);
    final JMSDestination destination = setupJMSDestination(ei);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            verifyReceivedMessage(m);
            verifyHeaders(m, outMessage);
            // setup the message for
            Conduit backConduit;
            try {
                backConduit = destination.getBackChannel(m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                sendOneWayMessage(backConduit, replyMessage);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    destination.setMessageObserver(observer);
    sendMessageSync(conduit, outMessage);
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    // wait for a while for the jms session recycling
    inMessage = null;
    // Send a second message to check for an issue
    // Where the session was closed the second time
    sendMessageSync(conduit, outMessage);
    waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    // wait for a while for the jms session recycling
    Thread.sleep(1000);
    conduit.close();
    destination.shutdown();
    return inMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) IOException(java.io.IOException) InvalidClientIDException(javax.jms.InvalidClientIDException) JMSException(javax.jms.JMSException)

Example 100 with Exchange

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

the class JMSContinuationTest method setUp.

@Before
public void setUp() {
    m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    m.setInterceptorChain(EasyMock.createMock(InterceptorChain.class));
    exchange.setInMessage(m);
    b = BusFactory.getDefaultBus();
    observer = EasyMock.createMock(MessageObserver.class);
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) MessageObserver(org.apache.cxf.transport.MessageObserver) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Aggregations

Exchange (org.apache.cxf.message.Exchange)272 Message (org.apache.cxf.message.Message)151 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)131 MessageImpl (org.apache.cxf.message.MessageImpl)118 Test (org.junit.Test)93 Endpoint (org.apache.cxf.endpoint.Endpoint)66 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)50 QName (javax.xml.namespace.QName)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Bus (org.apache.cxf.Bus)30 Fault (org.apache.cxf.interceptor.Fault)27 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)26 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)25 Conduit (org.apache.cxf.transport.Conduit)25 MessageContentsList (org.apache.cxf.message.MessageContentsList)22 SOAPMessage (javax.xml.soap.SOAPMessage)19 XMLStreamReader (javax.xml.stream.XMLStreamReader)19 ServerProviderFactory (org.apache.cxf.jaxrs.provider.ServerProviderFactory)19