1 17 package org.apache.servicemix.jms; 18 19 import java.util.List ; 20 21 import javax.jbi.messaging.ExchangeStatus; 22 import javax.jbi.messaging.InOnly; 23 import javax.jbi.messaging.MessageExchange; 24 import javax.jbi.messaging.NormalizedMessage; 25 import javax.jbi.servicedesc.ServiceEndpoint; 26 27 import junit.framework.TestCase; 28 29 import org.apache.activemq.ActiveMQConnectionFactory; 30 import org.apache.activemq.broker.BrokerService; 31 import org.apache.activemq.xbean.BrokerFactoryBean; 32 import org.apache.servicemix.client.DefaultServiceMixClient; 33 import org.apache.servicemix.jbi.container.JBIContainer; 34 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 35 import org.apache.servicemix.jbi.jaxp.StringSource; 36 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport; 37 import org.apache.servicemix.jbi.resolver.URIResolver; 38 import org.apache.servicemix.tck.ReceiverComponent; 39 import org.springframework.core.io.ClassPathResource; 40 import org.w3c.dom.DocumentFragment ; 41 import org.w3c.dom.Element ; 42 43 public class JmsURITest extends TestCase { 44 45 protected JBIContainer container; 46 protected BrokerService broker; 47 protected ActiveMQConnectionFactory connectionFactory; 48 49 protected void setUp() throws Exception { 50 BrokerFactoryBean bfb = new BrokerFactoryBean(new ClassPathResource("org/apache/servicemix/jms/activemq.xml")); 51 bfb.afterPropertiesSet(); 52 broker = bfb.getBroker(); 53 broker.start(); 54 55 container = new JBIContainer(); 56 container.setUseMBeanServer(true); 57 container.setCreateMBeanServer(true); 58 container.setMonitorInstallationDirectory(false); 59 container.init(); 60 container.start(); 61 62 connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61216"); 63 } 64 65 protected void tearDown() throws Exception { 66 if (container != null) { 67 container.shutDown(); 68 } 69 if (broker != null) { 70 broker.stop(); 71 } 72 } 73 74 public void testResolveEndpoint() throws Exception { 75 JmsSpringComponent jms = new JmsSpringComponent(); 76 ((JmsLifeCycle) jms.getLifeCycle()).getConfiguration().setConnectionFactory(connectionFactory); 77 JmsEndpoint ep = new JmsEndpoint(); 78 ep.setRole(MessageExchange.Role.CONSUMER); 79 ep.setService(ReceiverComponent.SERVICE); 80 ep.setEndpoint(ReceiverComponent.ENDPOINT); 81 ep.setDefaultMep(MessageExchangeSupport.IN_ONLY); 82 ep.setJmsProviderDestinationName("foo.bar.myqueue"); 83 ep.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); 84 jms.setEndpoints(new JmsEndpoint[] { ep }); 85 container.activateComponent(jms, "servicemix-jms"); 86 87 ReceiverComponent receiver = new ReceiverComponent(); 88 container.activateComponent(receiver, "receiver"); 89 90 DefaultServiceMixClient client = new DefaultServiceMixClient(container); 91 DocumentFragment epr = URIResolver.createWSAEPR("jms://queue/foo.bar.myqueue?jms.soap=true"); 92 ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); 93 assertNotNull(se); 94 95 InOnly inonly = client.createInOnlyExchange(); 96 inonly.setEndpoint(se); 97 inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); 98 client.sendSync(inonly); 99 100 assertEquals(ExchangeStatus.DONE, inonly.getStatus()); 101 receiver.getMessageList().assertMessagesReceived(1); 102 List msgs = receiver.getMessageList().flushMessages(); 103 NormalizedMessage msg = (NormalizedMessage) msgs.get(0); 104 Element elem = new SourceTransformer().toDOMElement(msg); 105 assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); 106 assertEquals("env:Envelope", elem.getNodeName()); 107 System.out.println(new SourceTransformer().contentToString(msg)); 108 109 Thread.sleep(50); 111 } 112 113 } 114 | Popular Tags |