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);
}
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;
}
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;
}
};
}
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;
}
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);
}
Aggregations