1 17 package org.apache.servicemix.http; 18 19 import java.io.File ; 20 import java.net.URI ; 21 import java.net.URL ; 22 23 import javax.jbi.messaging.ExchangeStatus; 24 import javax.jbi.messaging.InOut; 25 import javax.jbi.servicedesc.ServiceEndpoint; 26 import javax.wsdl.Binding; 27 import javax.wsdl.Definition; 28 import javax.wsdl.Port; 29 import javax.wsdl.PortType; 30 import javax.wsdl.Service; 31 import javax.wsdl.factory.WSDLFactory; 32 import javax.xml.namespace.QName ; 33 34 import junit.framework.TestCase; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.servicemix.client.DefaultServiceMixClient; 39 import org.apache.servicemix.components.util.EchoComponent; 40 import org.apache.servicemix.jbi.container.ActivationSpec; 41 import org.apache.servicemix.jbi.container.JBIContainer; 42 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 43 import org.apache.servicemix.jbi.jaxp.StringSource; 44 import org.w3c.dom.Document ; 45 46 public class HttpXBeanDeployerTest extends TestCase { 47 48 private static Log logger = LogFactory.getLog(HttpXBeanDeployerTest.class); 49 50 protected JBIContainer container; 51 52 protected void setUp() throws Exception { 53 container = new JBIContainer(); 54 container.setUseMBeanServer(false); 55 container.setCreateMBeanServer(false); 56 container.setEmbedded(true); 57 container.init(); 58 } 59 60 protected void tearDown() throws Exception { 61 if (container != null) { 62 container.shutDown(); 63 } 64 } 65 66 public void test() throws Exception { 67 HttpComponent component = new HttpComponent(); 69 container.activateComponent(component, "HTTPComponent"); 70 71 ActivationSpec asEcho = new ActivationSpec("echo", new EchoComponent() { 73 public Document getServiceDescription(ServiceEndpoint endpoint) { 74 try { 75 Definition def = WSDLFactory.newInstance().newDefinition(); 76 PortType type = def.createPortType(); 77 type.setUndefined(false); 78 type.setQName(new QName ("http://test", "MyConsumerInterface")); 79 Binding binding = def.createBinding(); 80 binding.setQName(new QName ("http://test", "MyConsumerBinding")); 81 binding.setUndefined(false); 82 binding.setPortType(type); 83 Service svc = def.createService(); 84 svc.setQName(new QName ("http://test", "MyConsumerService")); 85 Port port = def.createPort(); 86 port.setBinding(binding); 87 port.setName("myConsumer"); 88 svc.addPort(port); 89 def.setTargetNamespace("http://test"); 90 def.addNamespace("tns", "http://test"); 91 def.addPortType(type); 92 def.addBinding(binding); 93 def.addService(svc); 94 Document doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(def); 95 return doc; 96 } catch (Exception e) { 97 throw new RuntimeException (e); 98 } 99 } 100 }); 101 asEcho.setEndpoint("myConsumer"); 102 asEcho.setService(new QName ("http://test", "MyConsumerService")); 103 container.activateComponent(asEcho); 104 105 container.start(); 107 108 URL url = getClass().getClassLoader().getResource("xbean/xbean.xml"); 110 File path = new File (new URI (url.toString())); 111 path = path.getParentFile(); 112 component.getServiceUnitManager().deploy("xbean", path.getAbsolutePath()); 113 component.getServiceUnitManager().start("xbean"); 114 115 assertNotNull(container.getRegistry().getEndpointDescriptor( 117 container.getRegistry().getEndpoint( 118 new QName ("http://test", "MyProviderService"), "myProvider"))); 119 assertNotNull(container.getRegistry().getEndpointDescriptor( 120 container.getRegistry().getExternalEndpointsForService( 121 new QName ("http://test", "MyConsumerService"))[0])); 122 assertNotNull(container.getRegistry().getEndpointDescriptor( 123 container.getRegistry().getExternalEndpointsForService( 124 new QName ("http://test", "MySoapService"))[0])); 125 126 DefaultServiceMixClient client = new DefaultServiceMixClient(container); 128 InOut me = client.createInOutExchange(); 129 me.setService(new QName ("http://test", "MyProviderService")); 130 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 131 client.sendSync(me); 132 if (me.getStatus() == ExchangeStatus.ERROR) { 133 if (me.getFault() != null) { 134 fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent())); 135 } else if (me.getError() != null) { 136 throw me.getError(); 137 } else { 138 fail("Received ERROR status"); 139 } 140 } else { 141 logger.info(new SourceTransformer().toString(me.getOutMessage().getContent())); 142 } 143 client.done(me); 144 } 145 146 } 147 | Popular Tags |