1 17 package org.apache.servicemix.http; 18 19 import javax.jbi.servicedesc.ServiceEndpoint; 20 import javax.servlet.http.HttpServletResponse ; 21 import javax.wsdl.Definition; 22 import javax.wsdl.PortType; 23 import javax.wsdl.factory.WSDLFactory; 24 import javax.wsdl.xml.WSDLReader; 25 import javax.xml.namespace.QName ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.commons.httpclient.HttpClient; 30 import org.apache.commons.httpclient.methods.GetMethod; 31 import org.apache.servicemix.components.util.EchoComponent; 32 import org.apache.servicemix.jbi.container.ActivationSpec; 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.springframework.core.io.UrlResource; 37 import org.w3c.dom.Document ; 38 39 public class HttpWsdlTest extends TestCase { 40 41 protected JBIContainer container; 42 43 protected void setUp() throws Exception { 44 container = new JBIContainer(); 45 container.setUseMBeanServer(false); 46 container.setCreateMBeanServer(false); 47 container.setEmbedded(true); 48 container.init(); 49 } 50 51 protected void tearDown() throws Exception { 52 if (container != null) { 53 container.shutDown(); 54 } 55 } 56 57 public void testWithNonStandaloneWsdl() throws Exception { 58 ActivationSpec asEcho = new ActivationSpec("echo", new EchoComponent() { 60 public Document getServiceDescription(ServiceEndpoint endpoint) { 61 try { 62 Definition def = WSDLFactory.newInstance().newDefinition(); 63 PortType type = def.createPortType(); 64 type.setUndefined(false); 65 type.setQName(new QName ("http://porttype.test", "MyConsumerInterface")); 66 def.setTargetNamespace("http://porttype.test"); 67 def.addNamespace("tns", "http://porttype.test"); 68 def.addPortType(type); 69 Document doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(def); 70 return doc; 71 } catch (Exception e) { 72 throw new RuntimeException (e); 73 } 74 } 75 }); 76 asEcho.setEndpoint("myConsumer"); 77 asEcho.setService(new QName ("http://test", "MyConsumerService")); 78 container.activateComponent(asEcho); 79 80 HttpEndpoint ep = new HttpEndpoint(); 82 ep.setService(new QName ("http://test", "MyConsumerService")); 83 ep.setEndpoint("myConsumer"); 84 ep.setRoleAsString("consumer"); 85 ep.setLocationURI("http://localhost:8195/Service"); 86 HttpSpringComponent http = new HttpSpringComponent(); 87 http.setEndpoints(new HttpEndpoint[] { ep }); 88 container.activateComponent(http, "HttpWsdlTest"); 89 90 container.start(); 92 93 GetMethod get = new GetMethod("http://localhost:8195/Service/?wsdl"); 94 int state = new HttpClient().executeMethod(get); 95 assertEquals(HttpServletResponse.SC_OK, state); 96 Document doc = (Document ) new SourceTransformer().toDOMNode(new StringSource(get.getResponseBodyAsString())); 97 98 WSDLFactory factory = WSDLFactory.newInstance(); 100 WSDLReader reader = factory.newWSDLReader(); 101 Definition def; 102 def = reader.readWSDL("http://localhost:8195/Service/?wsdl", doc); 103 assertNotNull(def); 104 assertNotNull(def.getImports()); 105 assertEquals(1, def.getImports().size()); 106 } 107 108 public void testExternalNonStandaloneWsdl() throws Exception { 109 HttpEndpoint ep = new HttpEndpoint(); 111 ep.setService(new QName ("http://test", "MyConsumerService")); 112 ep.setEndpoint("myConsumer"); 113 ep.setRoleAsString("consumer"); 114 ep.setLocationURI("http://localhost:8196/Service/"); 115 ep.setWsdlResource(new UrlResource("http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-08/Retailer.wsdl")); 116 HttpSpringComponent http = new HttpSpringComponent(); 117 http.setEndpoints(new HttpEndpoint[] { ep }); 118 container.activateComponent(http, "HttpWsdlTest"); 119 120 container.start(); 122 123 GetMethod get = new GetMethod("http://localhost:8196/Service/?wsdl"); 124 int state = new HttpClient().executeMethod(get); 125 assertEquals(HttpServletResponse.SC_OK, state); 126 Document doc = (Document ) new SourceTransformer().toDOMNode(new StringSource(get.getResponseBodyAsString())); 127 128 WSDLFactory factory = WSDLFactory.newInstance(); 130 WSDLReader reader = factory.newWSDLReader(); 131 Definition def; 132 def = reader.readWSDL("http://localhost:8196/Service/?wsdl", doc); 133 assertNotNull(def); 134 assertNotNull(def.getImports()); 135 assertEquals(1, def.getImports().size()); 136 } 137 138 } 139 | Popular Tags |