1 22 package org.jboss.test.ws.jaxws.webserviceref; 23 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 27 import javax.naming.InitialContext ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.http.HttpServlet ; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 import javax.xml.ws.WebServiceException; 33 import javax.xml.ws.WebServiceRef; 34 import javax.xml.ws.WebServiceRefs; 35 36 import org.jboss.logging.Logger; 37 38 @WebServiceRef(name = "service1", value = TestEndpointService.class, wsdlLocation = "WEB-INF/wsdl/TestEndpoint.wsdl") 40 41 @WebServiceRefs( { 43 @WebServiceRef(name = "service2", value = TestEndpointService.class), 44 @WebServiceRef(name = "port1", value = TestEndpointService.class, type = TestEndpoint.class) }) 45 public class ServletClient extends HttpServlet 46 { 47 private static Logger log = Logger.getLogger(ServletClient.class); 49 50 @WebServiceRef(name = "TestEndpointService3") 52 public TestEndpointService service3; 53 54 @WebServiceRef 56 public TestEndpointService service4; 57 58 @WebServiceRef(name = "TestEndpointService5") 60 public void setServiceSetter5(TestEndpointService service) 61 { 62 this.service5 = service; 63 } 64 private TestEndpointService service5; 65 66 @WebServiceRef 68 public void setServiceSetter6(TestEndpointService service) 69 { 70 this.service6 = service; 71 } 72 private TestEndpointService service6; 73 74 @WebServiceRef(name = "Port2", value = TestEndpointService.class) 76 public TestEndpoint port2; 77 78 @WebServiceRef(value = TestEndpointService.class) 80 public TestEndpoint port3; 81 82 @Override 83 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException 84 { 85 String inStr = req.getParameter("echo"); 86 log.info("doGet: " + inStr); 87 88 ArrayList <TestEndpoint> ports = new ArrayList <TestEndpoint>(); 89 try 90 { 91 InitialContext iniCtx = new InitialContext (); 92 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/service1")).getTestEndpointPort()); 93 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/service2")).getTestEndpointPort()); 94 ports.add((TestEndpoint)service3.getPort(TestEndpoint.class)); 95 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/TestEndpointService3")).getTestEndpointPort()); 96 ports.add((TestEndpoint)service4.getPort(TestEndpoint.class)); 97 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/" + getClass().getName() + "/service4")).getTestEndpointPort()); 98 ports.add((TestEndpoint)service5.getPort(TestEndpoint.class)); 99 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/TestEndpointService5")).getTestEndpointPort()); 100 ports.add((TestEndpoint)service6.getPort(TestEndpoint.class)); 101 ports.add(((TestEndpointService)iniCtx.lookup("java:comp/env/" + getClass().getName() + "/serviceSetter6")).getTestEndpointPort()); 102 ports.add((TestEndpoint)iniCtx.lookup("java:comp/env/port1")); 103 ports.add(port2); 104 ports.add((TestEndpoint)iniCtx.lookup("java:comp/env/Port2")); 105 ports.add(port3); 106 ports.add((TestEndpoint)iniCtx.lookup("java:comp/env/" + getClass().getName() + "/port3")); 107 } 108 catch (Exception ex) 109 { 110 log.error("Cannot add port", ex); 111 throw new WebServiceException(ex); 112 } 113 114 for (TestEndpoint port : ports) 115 { 116 String outStr = port.echo(inStr); 117 if (inStr.equals(outStr) == false) 118 throw new WebServiceException("Invalid echo return: " + inStr); 119 } 120 121 res.getWriter().print(inStr); 122 } 123 } 124 | Popular Tags |