1 17 package org.apache.servicemix.http; 18 19 import java.net.URI ; 20 21 import javax.jbi.messaging.InOut; 22 import javax.transaction.TransactionManager ; 23 import javax.xml.namespace.QName ; 24 25 import junit.framework.TestCase; 26 27 import org.apache.activemq.broker.BrokerService; 28 import org.apache.geronimo.transaction.context.GeronimoTransactionManager; 29 import org.apache.geronimo.transaction.context.TransactionContextManager; 30 import org.apache.geronimo.transaction.manager.TransactionManagerImpl; 31 import org.apache.geronimo.transaction.manager.XidFactoryImpl; 32 import org.apache.servicemix.client.DefaultServiceMixClient; 33 import org.apache.servicemix.client.Destination; 34 import org.apache.servicemix.components.util.EchoComponent; 35 import org.apache.servicemix.jbi.container.JBIContainer; 36 import org.apache.servicemix.jbi.jaxp.StringSource; 37 import org.apache.servicemix.jbi.nmr.flow.Flow; 38 import org.apache.servicemix.jbi.nmr.flow.jca.JCAFlow; 39 import org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow; 40 import org.apache.servicemix.tck.ExchangeCompletedListener; 41 42 public class HttpTxTest extends TestCase { 43 44 private ExchangeCompletedListener listener; 45 private JBIContainer jbi; 46 private TransactionManager tm; 47 private BrokerService broker; 48 49 protected void setUp() throws Exception { 50 broker = new BrokerService(); 51 broker.setUseJmx(false); 52 broker.setPersistent(false); 53 broker.addConnector("tcp://localhost:61616"); 54 broker.start(); 55 56 TransactionManagerImpl exTransactionManager = new TransactionManagerImpl(600, new XidFactoryImpl(), null, null); 57 TransactionContextManager transactionContextManager = new TransactionContextManager(exTransactionManager, exTransactionManager); 58 tm = (TransactionManager ) new GeronimoTransactionManager(transactionContextManager); 59 60 JCAFlow jcaFlow = new JCAFlow(); 61 jcaFlow.setTransactionContextManager(transactionContextManager); 62 63 jbi = new JBIContainer(); 64 jbi.setFlows(new Flow[] { new SedaFlow(), jcaFlow }); 65 jbi.setEmbedded(true); 66 jbi.setUseMBeanServer(false); 67 jbi.setCreateMBeanServer(false); 68 jbi.setTransactionManager(tm); 69 jbi.setAutoEnlistInTransaction(true); 70 listener = new ExchangeCompletedListener(); 71 jbi.addListener(listener); 72 jbi.init(); 73 jbi.start(); 74 } 75 76 protected void tearDown() throws Exception { 77 listener.assertExchangeCompleted(); 78 jbi.shutDown(); 79 broker.stop(); 80 } 81 82 public void testSync() throws Exception { 83 EchoComponent echo = new EchoComponent(); 84 echo.setService(new QName ("urn:test", "echo")); 85 echo.setEndpoint("echo"); 86 jbi.activateComponent(echo, "echo"); 87 88 HttpEndpoint ep0 = new HttpEndpoint(); 89 ep0.setService(new QName ("urn:test", "s0")); 90 ep0.setEndpoint("ep0"); 91 ep0.setLocationURI("http://localhost:8192/ep1/"); 92 ep0.setRoleAsString("provider"); 93 ep0.setSoap(true); 94 95 HttpEndpoint ep1 = new HttpEndpoint(); 96 ep1.setService(new QName ("urn:test", "s1")); 97 ep1.setEndpoint("ep1"); 98 ep1.setTargetService(new QName ("urn:test", "echo")); 99 ep1.setLocationURI("http://localhost:8192/ep1/"); 100 ep1.setRoleAsString("consumer"); 101 ep1.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out")); 102 ep1.setSoap(true); 103 104 HttpSpringComponent http = new HttpSpringComponent(); 105 http.setEndpoints(new HttpEndpoint[] { ep0, ep1 }); 106 jbi.activateComponent(http, "http"); 107 108 DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); 109 Destination d = client.createDestination("service:urn:test:s0"); 110 InOut me = d.createInOutExchange(); 111 me.getInMessage().setContent(new StringSource("<hello>world</hello>")); 112 113 tm.begin(); 114 boolean ok = client.sendSync(me); 115 assertTrue(ok); 116 client.done(me); 117 tm.commit(); 118 } 119 120 public void testAsync() throws Exception { 121 EchoComponent echo = new EchoComponent(); 122 echo.setService(new QName ("urn:test", "echo")); 123 echo.setEndpoint("echo"); 124 jbi.activateComponent(echo, "echo"); 125 126 HttpEndpoint ep0 = new HttpEndpoint(); 127 ep0.setService(new QName ("urn:test", "s0")); 128 ep0.setEndpoint("ep0"); 129 ep0.setLocationURI("http://localhost:8192/ep1/"); 130 ep0.setRoleAsString("provider"); 131 ep0.setSoap(true); 132 133 HttpEndpoint ep1 = new HttpEndpoint(); 134 ep1.setService(new QName ("urn:test", "s1")); 135 ep1.setEndpoint("ep1"); 136 ep1.setTargetService(new QName ("urn:test", "echo")); 137 ep1.setLocationURI("http://localhost:8192/ep1/"); 138 ep1.setRoleAsString("consumer"); 139 ep1.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out")); 140 ep1.setSoap(true); 141 142 HttpSpringComponent http = new HttpSpringComponent(); 143 http.setEndpoints(new HttpEndpoint[] { ep0, ep1 }); 144 jbi.activateComponent(http, "http"); 145 146 DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); 147 Destination d = client.createDestination("service:urn:test:s0"); 148 InOut me = d.createInOutExchange(); 149 me.getInMessage().setContent(new StringSource("<hello>world</hello>")); 150 151 tm.begin(); 152 client.send(me); 153 tm.commit(); 154 me = (InOut) client.receive(); 155 client.done(me); 156 } 157 158 } 159 | Popular Tags |