Search in sources :

Example 1 with ResourceCloser

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();
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(javax.jms.Destination) JMSConfiguration(org.apache.cxf.transport.jms.JMSConfiguration) Message(javax.jms.Message) Connection(javax.jms.Connection) ResourceCloser(org.apache.cxf.transport.jms.util.ResourceCloser) JMSSender(org.apache.cxf.transport.jms.util.JMSSender) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 2 with ResourceCloser

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);
    }
}
Also used : Message(org.apache.cxf.message.Message) Connection(javax.jms.Connection) ResourceCloser(org.apache.cxf.transport.jms.util.ResourceCloser) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Aggregations

Connection (javax.jms.Connection)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2 ResourceCloser (org.apache.cxf.transport.jms.util.ResourceCloser)2 Destination (javax.jms.Destination)1 Message (javax.jms.Message)1 Message (org.apache.cxf.message.Message)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 JMSConfiguration (org.apache.cxf.transport.jms.JMSConfiguration)1 JMSSender (org.apache.cxf.transport.jms.util.JMSSender)1