1 17 package org.apache.servicemix.http; 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.servicemix.client.DefaultServiceMixClient; 30 import org.apache.servicemix.jbi.container.JBIContainer; 31 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 32 import org.apache.servicemix.jbi.jaxp.StringSource; 33 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport; 34 import org.apache.servicemix.jbi.resolver.URIResolver; 35 import org.apache.servicemix.tck.ReceiverComponent; 36 import org.w3c.dom.DocumentFragment ; 37 import org.w3c.dom.Element ; 38 39 public class HttpURITest extends TestCase { 40 41 private JBIContainer jbi; 42 43 protected void setUp() throws Exception { 44 jbi = new JBIContainer(); 45 jbi.setEmbedded(true); 46 jbi.setUseMBeanServer(false); 47 jbi.init(); 48 jbi.start(); 49 } 50 51 protected void tearDown() throws Exception { 52 jbi.shutDown(); 53 } 54 55 public void testResolveEndpoint() throws Exception { 56 HttpSpringComponent http = new HttpSpringComponent(); 57 HttpEndpoint ep = new HttpEndpoint(); 58 ep.setRole(MessageExchange.Role.CONSUMER); 59 ep.setService(ReceiverComponent.SERVICE); 60 ep.setEndpoint(ReceiverComponent.ENDPOINT); 61 ep.setLocationURI("http://localhost:8192/"); 62 ep.setDefaultMep(MessageExchangeSupport.IN_ONLY); 63 http.setEndpoints(new HttpEndpoint[] { ep }); 64 jbi.activateComponent(http, "servicemix-http"); 65 66 ReceiverComponent receiver = new ReceiverComponent(); 67 jbi.activateComponent(receiver, "receiver"); 68 69 DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); 70 DocumentFragment epr = URIResolver.createWSAEPR("http://localhost:8192?http.soap=true"); 71 ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); 72 assertNotNull(se); 73 74 InOnly inonly = client.createInOnlyExchange(); 75 inonly.setEndpoint(se); 76 inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); 77 client.sendSync(inonly); 78 79 assertEquals(ExchangeStatus.DONE, inonly.getStatus()); 80 receiver.getMessageList().assertMessagesReceived(1); 81 List msgs = receiver.getMessageList().flushMessages(); 82 NormalizedMessage msg = (NormalizedMessage) msgs.get(0); 83 Element elem = new SourceTransformer().toDOMElement(msg); 84 assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); 85 assertEquals("env:Envelope", elem.getNodeName()); 86 System.out.println(new SourceTransformer().contentToString(msg)); 87 } 88 89 } 90 | Popular Tags |