use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class SoapBindingSelectionTest method testMultipleSoapBindings.
@Test
public void testMultipleSoapBindings() throws Exception {
ServerFactoryBean svrBean1 = new ServerFactoryBean();
svrBean1.setAddress("http://localhost/Hello");
svrBean1.setServiceClass(HelloService.class);
svrBean1.setServiceBean(new HelloServiceImpl());
svrBean1.setBus(getBus());
svrBean1.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service1Invoked = true;
}
});
svrBean1.create();
ServerFactoryBean svrBean2 = new ServerFactoryBean();
svrBean2.setAddress("http://localhost/Hello");
svrBean2.setServiceClass(HelloService.class);
svrBean2.setServiceBean(new HelloServiceImpl());
svrBean2.setBus(getBus());
svrBean2.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service2Invoked = true;
}
});
SoapBindingConfiguration config = new SoapBindingConfiguration();
config.setVersion(Soap12.getInstance());
svrBean2.setBindingConfig(config);
ServerImpl server2 = (ServerImpl) svrBean2.create();
Destination d = server2.getDestination();
MessageObserver mo = d.getMessageObserver();
assertTrue(mo instanceof MultipleEndpointObserver);
MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
assertEquals(2, meo.getEndpoints().size());
Node nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap11.xml");
assertEquals("http://schemas.xmlsoap.org/soap/envelope/", getNs(nd));
assertTrue(service1Invoked);
assertFalse(service2Invoked);
service1Invoked = false;
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
server2.stop();
server2.start();
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class JMSDestinationTest method testMessageObserverExceptionHandling.
@Test
public void testMessageObserverExceptionHandling() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
EndpointInfo ei = setupServiceInfo("HelloWorldPubSubService", "HelloWorldPubSubPort");
JMSConduit conduit = setupJMSConduitWithObserver(ei);
JMSDestination destination = setupJMSDestination(ei);
destination.setMessageObserver(new MessageObserver() {
@Override
public void onMessage(Message message) {
try {
throw new RuntimeException("Error!");
} finally {
latch.countDown();
}
}
});
final Message outMessage = createMessage();
Thread.sleep(500L);
sendOneWayMessage(conduit, outMessage);
latch.await(5, TimeUnit.SECONDS);
conduit.close();
destination.shutdown();
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class JMSDestinationTest method testProperty.
@Test
public void testProperty() throws Exception {
EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
final String customPropertyName = "THIS_PROPERTY_WILL_NOT_BE_AUTO_COPIED";
// set up the conduit send to be true
JMSConduit conduit = setupJMSConduitWithObserver(ei);
final Message outMessage = createMessage();
JMSMessageHeadersType headers = (JMSMessageHeadersType) outMessage.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
headers.putProperty(customPropertyName, customPropertyName);
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();
// copy the message encoding
replyMessage.put(Message.ENCODING, m.get(Message.ENCODING));
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
Message inMessage = waitForReceiveInMessage();
verifyReceivedMessage(inMessage);
verifyRequestResponseHeaders(inMessage, outMessage);
JMSMessageHeadersType inHeader = (JMSMessageHeadersType) inMessage.get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
assertNotNull("The inHeader should not be null", inHeader);
// TODO we need to check the SOAP JMS transport properties here
// wait for a while for the jms session recycling
// Thread.sleep(1000L);
conduit.close();
destination.shutdown();
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class RequestResponseTest method sendAndReceiveMessages.
private void sendAndReceiveMessages(EndpointInfo ei, boolean synchronous) throws IOException, InterruptedException {
// set up the conduit send to be true
JMSConduit conduit = setupJMSConduitWithObserver(ei);
final Message outMessage = createMessage();
final JMSDestination destination = setupJMSDestination(ei);
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
try {
Conduit 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);
try {
sendMessage(conduit, outMessage, synchronous);
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
verifyReceivedMessage(waitForReceiveInMessage());
} finally {
conduit.close();
destination.shutdown();
}
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class JMSDestinationTest method testTemporaryQueueDeletionUponReset.
@Test
public void testTemporaryQueueDeletionUponReset() throws Exception {
EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
// set up the conduit send to be true
JMSConduit conduit = setupJMSConduitWithObserver(ei);
assertNull(conduit.getJmsConfig().getReplyDestination());
// Store the connection so we could check temporary queues
final AtomicReference<DestinationSource> destinationSource = new AtomicReference<>();
final Message outMessage = createMessage();
// Capture the DestinationSource instance associated with the connection
final JMSDestination destination = setupJMSDestination(ei, c -> new ConnectionFactory() {
@Override
public Connection createConnection() throws JMSException {
final Connection connection = c.createConnection();
destinationSource.set(((EnhancedConnection) connection).getDestinationSource());
return connection;
}
@Override
public Connection createConnection(String userName, String password) throws JMSException {
final Connection connection = c.createConnection(userName, password);
destinationSource.set(((EnhancedConnection) connection).getDestinationSource());
return connection;
}
});
// set up MessageObserver for handling the conduit message
final MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
final Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
try {
final Conduit backConduit = destination.getBackChannel(m);
sendOneWayMessage(backConduit, new MessageImpl());
} 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
Message inMessage = waitForReceiveInMessage();
verifyReceivedMessage(inMessage);
final DestinationSource ds = destinationSource.get();
assertThat(ds.getTemporaryQueues().size(), equalTo(1));
// Force manual temporary queue deletion by resetting the reply destination
conduit.getJmsConfig().resetCachedReplyDestination();
// The queue deletion events (as well as others) are propagated asynchronously
await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ds.getTemporaryQueues().size(), equalTo(0)));
conduit.close();
destination.shutdown();
}
Aggregations