KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
25
26 import javax.ejb.Remote JavaDoc;
27 import javax.ejb.Stateless JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.xml.ws.WebServiceException;
30 import javax.xml.ws.WebServiceRef;
31 import javax.xml.ws.WebServiceRefs;
32
33 import org.jboss.annotation.ejb.RemoteBinding;
34 import org.jboss.logging.Logger;
35
36 // standard EJB3 annotations
37
@Remote JavaDoc(EJB3Remote.class)
38 @RemoteBinding(jndiBinding = "/ejb3/EJB3Client")
39 @Stateless JavaDoc
40
41 // Test on type with wsdlLocation
42
@WebServiceRef(name = "service1", value = TestEndpointService.class, wsdlLocation = "META-INF/wsdl/TestEndpoint.wsdl")
43
44 // Test multiple on type
45
@WebServiceRefs( {
46    @WebServiceRef(name = "service2", value = TestEndpointService.class),
47    @WebServiceRef(name = "port1", value = TestEndpointService.class, type = TestEndpoint.class) })
48 public class EJB3Client implements EJB3Remote
49 {
50    // Provide logging
51
private static Logger log = Logger.getLogger(EJB3Client.class);
52
53    // Test on field with name
54
@WebServiceRef(name = "TestEndpointService3")
55    public TestEndpointService service3;
56
57    // Test on field without name
58
@WebServiceRef
59    public TestEndpointService service4;
60
61    // Test on method with value
62
@WebServiceRef(name = "TestEndpointService5")
63    public void setServiceSetter5(TestEndpointService service)
64    {
65       this.service5 = service;
66    }
67    private TestEndpointService service5;
68    
69    // Test on method without name
70
@WebServiceRef
71    public void setServiceSetter6(TestEndpointService service)
72    {
73       this.service6 = service;
74    }
75    private TestEndpointService service6;
76    
77    // Test on field with name and value
78
@WebServiceRef(name = "Port2", value = TestEndpointService.class)
79    public TestEndpoint port2;
80
81    // Test on field with value
82
@WebServiceRef(value = TestEndpointService.class)
83    public TestEndpoint port3;
84
85    public String JavaDoc echo(String JavaDoc inStr)
86    {
87       log.info("echo: " + inStr);
88
89       ArrayList JavaDoc<TestEndpoint> ports = new ArrayList JavaDoc<TestEndpoint>();
90       try
91       {
92          InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
93          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/service1")).getTestEndpointPort());
94          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/service2")).getTestEndpointPort());
95          ports.add((TestEndpoint)service3.getPort(TestEndpoint.class));
96          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/TestEndpointService3")).getTestEndpointPort());
97          ports.add((TestEndpoint)service4.getPort(TestEndpoint.class));
98          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/" + getClass().getName() + "/service4")).getTestEndpointPort());
99          ports.add((TestEndpoint)service5.getPort(TestEndpoint.class));
100          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/TestEndpointService5")).getTestEndpointPort());
101          ports.add((TestEndpoint)service6.getPort(TestEndpoint.class));
102          ports.add(((TestEndpointService)iniCtx.lookup("java:comp.ejb3/env/" + getClass().getName() + "/serviceSetter6")).getTestEndpointPort());
103          ports.add((TestEndpoint)iniCtx.lookup("java:comp.ejb3/env/port1"));
104          ports.add(port2);
105          ports.add((TestEndpoint)iniCtx.lookup("java:comp.ejb3/env/Port2"));
106          ports.add(port3);
107          ports.add((TestEndpoint)iniCtx.lookup("java:comp.ejb3/env/" + getClass().getName() + "/port3"));
108       }
109       catch (Exception JavaDoc ex)
110       {
111          log.error("Cannot add port", ex);
112          throw new WebServiceException(ex);
113       }
114
115       for (TestEndpoint port : ports)
116       {
117          String JavaDoc outStr = port.echo(inStr);
118          if (inStr.equals(outStr) == false)
119             throw new WebServiceException("Invalid echo return: " + inStr);
120       }
121
122       return inStr;
123    }
124 }
125
Popular Tags