You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2008/11/07 14:44:55 UTC
svn commit: r712124 - in
/servicemix/components/bindings/servicemix-jms/trunk/src:
main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java
test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java
Author: ffang
Date: Fri Nov 7 05:44:49 2008
New Revision: 712124
URL: http://svn.apache.org/viewvc?rev=712124&view=rev
Log:
[SM-1621]New JMS in/out provider should support temporary queues/topics (as reply destinations)
Modified:
servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java
servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java
Modified: servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java?rev=712124&r1=712123&r2=712124&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/JmsProviderEndpoint.java Fri Nov 7 05:44:49 2008
@@ -747,14 +747,6 @@
(String) dest,
isPubSubDomain());
}
- //create temp queue/topic if no destination explicitly set
- if (dest == null) {
- if (destination instanceof Queue) {
- return session.createTemporaryQueue();
- } else {
- return session.createTemporaryTopic();
- }
- }
throw new IllegalStateException("Unable to choose a destination for exchange " + exchange);
}
@@ -789,10 +781,8 @@
});
}
// create the listener container
- if (replyDestination != null) {
- listenerContainer = createListenerContainer();
- listenerContainer.start();
- }
+ listenerContainer = createListenerContainer();
+ listenerContainer.start();
}
/**
@@ -879,7 +869,12 @@
cont = new DefaultMessageListenerContainer();
}
cont.setConnectionFactory(getConnectionFactory());
- cont.setDestination(getReplyDestination());
+ Destination replyDest = getReplyDestination();
+ if (replyDest == null) {
+ replyDest = resolveOrCreateDestination(template, replyDestinationName, isPubSubDomain());
+ setReplyDestination(replyDest);
+ }
+ cont.setDestination(replyDest);
cont.setPubSubDomain(isPubSubDomain());
cont.setPubSubNoLocal(isPubSubNoLocal());
cont.setMessageListener(new MessageListener() {
@@ -891,4 +886,32 @@
cont.afterPropertiesSet();
return cont;
}
+
+ /**
+ * If the destinationName given is null then a temporary destination is created else the destination name
+ * is resolved using the resolver from the jmsConfig
+ *
+ * @param jmsTemplate template to use for session and resolver
+ * @param replyToDestinationName null for temporary destination or a destination name
+ * @param pubSubDomain true=pubSub, false=Queues
+ * @return resolved destination
+ */
+ private Destination resolveOrCreateDestination(final JmsTemplate jmsTemplate,
+ final String replyToDestinationName,
+ final boolean pubSubDomain) {
+ return (Destination)jmsTemplate.execute(new SessionCallback() {
+ public Object doInJms(Session session) throws JMSException {
+ if (replyToDestinationName == null) {
+ if (destination instanceof Queue) {
+ return session.createTemporaryQueue();
+ } else {
+ return session.createTemporaryTopic();
+ }
+ }
+ DestinationResolver resolv = jmsTemplate.getDestinationResolver();
+ return resolv.resolveDestinationName(session, replyToDestinationName, pubSubDomain);
+ }
+ });
+ }
+
}
Modified: servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java?rev=712124&r1=712123&r2=712124&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java (original)
+++ servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsProviderEndpointTest.java Fri Nov 7 05:44:49 2008
@@ -30,6 +30,7 @@
import javax.jms.TextMessage;
import javax.xml.namespace.QName;
+import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.util.FileUtil;
@@ -166,6 +167,54 @@
}
+ public void testSoapProviderInOutWithoutReplyDest() throws Exception {
+ JmsComponent component = new JmsComponent();
+
+ JmsSoapProviderEndpoint endpoint = new JmsSoapProviderEndpoint();
+ endpoint.setService(new QName("uri:HelloWorld", "HelloService"));
+ endpoint.setEndpoint("HelloPort");
+ endpoint.setConnectionFactory(new PooledConnectionFactory(connectionFactory));
+ endpoint.setDestinationName("destination");
+ endpoint.setWsdl(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC.wsdl"));
+ component.setEndpoints(new JmsProviderEndpoint[] {endpoint});
+ container.activateComponent(component, "servicemix-jms");
+
+ Thread th = new Thread() {
+ public void run() {
+ try {
+ final Message msg = jmsTemplate.receive("destination");
+ assertNotNull(msg);
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Output.xml")
+ .getInputStream(), baos);
+ jmsTemplate.send(msg.getJMSReplyTo(), new MessageCreator() {
+ public Message createMessage(Session session) throws JMSException {
+ TextMessage rep = session.createTextMessage(baos.toString());
+ rep.setJMSCorrelationID(msg.getJMSCorrelationID() != null ? msg.getJMSCorrelationID() : msg.getJMSMessageID());
+ return rep;
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ th.start();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Input-Hello.xml").getInputStream(), baos);
+ InOut me = client.createInOutExchange();
+ me.getInMessage().setContent(new StringSource(baos.toString()));
+ me.setOperation(new QName("uri:HelloWorld", "Hello"));
+ me.setService(new QName("uri:HelloWorld", "HelloService"));
+ client.sendSync(me);
+ assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
+ assertNotNull(me.getOutMessage());
+ assertNotNull(me.getOutMessage().getContent());
+ System.err.println(new SourceTransformer().contentToString(me.getOutMessage()));
+ client.done(me);
+
+ }
// Helper methods
private JmsComponent createEndpoint() {