KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ws > jaxws > webserviceref > ServletClient


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.ws.jaxws.webserviceref;
23
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import javax.naming.InitialContext JavaDoc;
28 import javax.servlet.ServletException JavaDoc;
29 import javax.servlet.http.HttpServlet JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
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 //Test on type with wsdlLocation
39
@WebServiceRef(name = "service1", value = TestEndpointService.class, wsdlLocation = "WEB-INF/wsdl/TestEndpoint.wsdl")
40
41 // Test multiple on type
42
@WebServiceRefs( {
43    @WebServiceRef(name = "service2", value = TestEndpointService.class),
44    @WebServiceRef(name = "port1", value = TestEndpointService.class, type = TestEndpoint.class) })
45 public class ServletClient extends HttpServlet JavaDoc
46 {
47    // Provide logging
48
private static Logger log = Logger.getLogger(ServletClient.class);
49    
50    // Test on field with name
51
@WebServiceRef(name = "TestEndpointService3")
52    public TestEndpointService service3;
53
54    // Test on field without name
55
@WebServiceRef
56    public TestEndpointService service4;
57
58    // Test on method with value
59
@WebServiceRef(name = "TestEndpointService5")
60    public void setServiceSetter5(TestEndpointService service)
61    {
62       this.service5 = service;
63    }
64    private TestEndpointService service5;
65    
66    // Test on method without name
67
@WebServiceRef
68    public void setServiceSetter6(TestEndpointService service)
69    {
70       this.service6 = service;
71    }
72    private TestEndpointService service6;
73    
74    // Test on field with name and value
75
@WebServiceRef(name = "Port2", value = TestEndpointService.class)
76    public TestEndpoint port2;
77
78    // Test on field with value
79
@WebServiceRef(value = TestEndpointService.class)
80    public TestEndpoint port3;
81
82    @Override JavaDoc
83    protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc
84    {
85       String JavaDoc inStr = req.getParameter("echo");
86       log.info("doGet: " + inStr);
87       
88       ArrayList JavaDoc<TestEndpoint> ports = new ArrayList JavaDoc<TestEndpoint>();
89       try
90       {
91          InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
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 JavaDoc ex)
109       {
110          log.error("Cannot add port", ex);
111          throw new WebServiceException(ex);
112       }
113       
114       for (TestEndpoint port : ports)
115       {
116          String JavaDoc 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