Search in sources :

Example 1 with TestReceiver

use of org.apache.cxf.transport.jms.util.TestReceiver in project cxf by apache.

the class MessageIdAsCorrelationIdJMSConduitTest method sendAndReceive.

public void sendAndReceive(boolean synchronous, String replyDestination) throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    EndpointReferenceType target = new EndpointReferenceType();
    connectionFactory = new PooledConnectionFactory(BROKER_URI);
    TestReceiver receiver = new TestReceiver(connectionFactory, SERVICE_QUEUE, true);
    receiver.runAsync();
    JMSConfiguration jmsConfig = new JMSConfiguration();
    jmsConfig.setTargetDestination(SERVICE_QUEUE);
    jmsConfig.setConnectionFactory(connectionFactory);
    jmsConfig.setUseConduitIdSelector(false);
    jmsConfig.setReplyDestination(replyDestination);
    JMSConduit conduit = new JMSConduit(target, jmsConfig, bus);
    Exchange exchange = new ExchangeImpl();
    exchange.setSynchronous(synchronous);
    Message message = new MessageImpl();
    exchange.setOutMessage(message);
    conduit.sendExchange(exchange, "Request");
    waitForAsyncReply(exchange);
    receiver.close();
    if (exchange.getInMessage() == null) {
        throw new RuntimeException("No reply received within 2 seconds");
    }
    JMSMessageHeadersType inHeaders = (JMSMessageHeadersType) exchange.getInMessage().get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    Assert.assertEquals(receiver.getRequestMessageId(), inHeaders.getJMSCorrelationID());
    conduit.close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.message.Message) BusFactory(org.apache.cxf.BusFactory) TestReceiver(org.apache.cxf.transport.jms.util.TestReceiver) Exchange(org.apache.cxf.message.Exchange) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 2 with TestReceiver

use of org.apache.cxf.transport.jms.util.TestReceiver in project cxf by apache.

the class URIConfiguredConduitTest method sendAndReceive.

public void sendAndReceive(SyncType syncType, String address) throws Exception {
    // Register bean locator for cf lookup
    TestReceiver receiver = new TestReceiver(cf, SERVICE_QUEUE, false);
    receiver.runAsync();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(address);
    Bus bus = BusFactory.getDefaultBus();
    JMSConfiguration jmsConfig = JMSConfigFactory.createFromEndpointInfo(bus, ei, null);
    jmsConfig.setConnectionFactory(cf);
    JMSConduit conduit = new JMSConduit(new EndpointReferenceType(), jmsConfig, bus);
    Exchange exchange = new ExchangeImpl();
    exchange.setSynchronous(syncType == SyncType.sync);
    Message message = new MessageImpl();
    exchange.setOutMessage(message);
    conduit.sendExchange(exchange, "Request");
    waitForAsyncReply(exchange);
    receiver.close();
    if (exchange.getInMessage() == null) {
        throw new RuntimeException("No reply received within 2 seconds");
    }
    JMSMessageHeadersType inHeaders = (JMSMessageHeadersType) exchange.getInMessage().get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    Assert.assertEquals(receiver.getRequestMessageId(), inHeaders.getJMSCorrelationID());
    conduit.close();
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Bus(org.apache.cxf.Bus) JMSConfiguration(org.apache.cxf.transport.jms.JMSConfiguration) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) JMSConduit(org.apache.cxf.transport.jms.JMSConduit) Message(org.apache.cxf.message.Message) JMSMessageHeadersType(org.apache.cxf.transport.jms.JMSMessageHeadersType) TestReceiver(org.apache.cxf.transport.jms.util.TestReceiver) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 3 with TestReceiver

use of org.apache.cxf.transport.jms.util.TestReceiver in project cxf by apache.

the class JMSClientServerTest method testReplyToConfig.

@Test
public void testReplyToConfig() throws Exception {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(broker.getBrokerURL());
    TestReceiver receiver = new TestReceiver(cf, "SoapService7.replyto.queue", false);
    receiver.setStaticReplyQueue("SoapService7.reply.queue");
    receiver.runAsync();
    QName serviceName = new QName("http://apache.org/hello_world_doc_lit", "SOAPService7");
    QName portName = new QName("http://apache.org/hello_world_doc_lit", "SoapPort7");
    URL wsdl = getWSDLURL("/wsdl/hello_world_doc_lit.wsdl");
    SOAPService7 service = new SOAPService7(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    String name = "FooBar";
    String reply = greeter.greetMe(name);
    Assert.assertEquals("Hello " + name, reply);
    ((Closeable) greeter).close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_doc_lit.Greeter) Closeable(java.io.Closeable) TestReceiver(org.apache.cxf.transport.jms.util.TestReceiver) URL(java.net.URL) SOAPService7(org.apache.hello_world_doc_lit.SOAPService7) Test(org.junit.Test)

Aggregations

TestReceiver (org.apache.cxf.transport.jms.util.TestReceiver)3 Bus (org.apache.cxf.Bus)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 Message (org.apache.cxf.message.Message)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)2 Closeable (java.io.Closeable)1 URL (java.net.URL)1 QName (javax.xml.namespace.QName)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)1 BusFactory (org.apache.cxf.BusFactory)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 JMSConduit (org.apache.cxf.transport.jms.JMSConduit)1 JMSConfiguration (org.apache.cxf.transport.jms.JMSConfiguration)1 JMSMessageHeadersType (org.apache.cxf.transport.jms.JMSMessageHeadersType)1 Greeter (org.apache.hello_world_doc_lit.Greeter)1 SOAPService7 (org.apache.hello_world_doc_lit.SOAPService7)1 Test (org.junit.Test)1