use of org.apache.cxf.transport.jms.util.ResourceCloser in project cxf by apache.
the class SOAPJMSTestSuiteTest method twoWayTestWithCreateMessage.
public void twoWayTestWithCreateMessage(final TestCaseType testcase) throws Exception {
String address = testcase.getAddress();
EndpointInfo endpointInfo = new EndpointInfo();
endpointInfo.setAddress(JMSTestUtil.getFullAddress(address, broker.getBrokerURL()));
JMSConfiguration jmsConfig = JMSConfigFactory.createFromEndpointInfo(staticBus, endpointInfo, null);
ResourceCloser closer = new ResourceCloser();
try {
Connection connection = closer.register(JMSFactory.createConnection(jmsConfig));
connection.start();
Session session = closer.register(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
Destination targetDest = jmsConfig.getTargetDestination(session);
Destination replyToDestination = jmsConfig.getReplyToDestination(session, null);
JMSSender sender = JMSFactory.createJmsSender(jmsConfig, null);
Message jmsMessage = JMSTestUtil.buildJMSMessageFromTestCase(testcase, session, replyToDestination);
sender.sendMessage(session, targetDest, jmsMessage);
Message replyMessage = JMSUtil.receive(session, replyToDestination, jmsMessage.getJMSMessageID(), 10000, true);
checkReplyMessage(replyMessage, testcase);
} catch (JMSException e) {
throw JMSUtil.convertJmsException(e);
} finally {
closer.close();
}
}
use of org.apache.cxf.transport.jms.util.ResourceCloser in project cxf by apache.
the class JMSConduit method sendExchange.
/**
* Send the JMS message and if the MEP is not oneway receive the response.
*
* @param exchange the Exchange containing the outgoing message
* @param request the payload of the outgoing JMS message
*/
public void sendExchange(final Exchange exchange, final Object request) {
LOG.log(Level.FINE, "JMSConduit send message");
final Message outMessage = exchange.getOutMessage() == null ? exchange.getOutFaultMessage() : exchange.getOutMessage();
if (outMessage == null) {
throw new RuntimeException("Exchange to be sent has no outMessage");
}
jmsConfig.ensureProperlyConfigured();
assertIsNotTextMessageAndMtom(outMessage);
try (ResourceCloser closer = new ResourceCloser()) {
Connection c;
if (jmsConfig.isOneSessionPerConnection()) {
c = closer.register(JMSFactory.createConnection(jmsConfig));
c.start();
} else {
c = getConnection();
}
Session session = closer.register(c.createSession(false, Session.AUTO_ACKNOWLEDGE));
if (exchange.isOneWay()) {
sendMessage(request, outMessage, null, null, closer, session);
} else {
sendAndReceiveMessage(exchange, request, outMessage, closer, session);
}
} catch (JMSException e) {
// Close connection so it will be refreshed on next try
if (!jmsConfig.isOneSessionPerConnection()) {
ResourceCloser.close(connection);
this.connection = null;
jmsConfig.resetCachedReplyDestination();
}
this.staticReplyDestination = null;
if (this.jmsListener != null) {
this.jmsListener.shutdown();
}
this.jmsListener = null;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// Ignore
}
throw JMSUtil.convertJmsException(e);
}
}
Aggregations