KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > hello_world_soap_http > AnnotatedGreeterImpl


1 package org.objectweb.hello_world_soap_http;
2
3
4 import java.util.HashMap JavaDoc;
5 import java.util.Map JavaDoc;
6 import java.util.logging.Logger JavaDoc;
7 import javax.annotation.Resource;
8 import javax.jws.HandlerChain;
9 import javax.jws.WebMethod;
10 import javax.jws.WebParam;
11 import javax.jws.WebResult;
12 import javax.xml.ws.RequestWrapper;
13 import javax.xml.ws.ResponseWrapper;
14 import javax.xml.ws.WebServiceContext;
15
16 @javax.jws.WebService(name = "Greeter", serviceName = "SOAPService",
17                       targetNamespace = "http://objectweb.org/hello_world_soap_http")
18 @HandlerChain(name = "TestHandlerChain", file = "handlers.xml")
19 public class AnnotatedGreeterImpl {
20
21     private static final Logger JavaDoc LOG =
22         Logger.getLogger(AnnotatedGreeterImpl.class.getName());
23
24     @Resource
25     private int foo;
26
27     private WebServiceContext context;
28
29     private final Map JavaDoc<String JavaDoc, Integer JavaDoc> invocationCount = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
30
31     public AnnotatedGreeterImpl() {
32         invocationCount.put("sayHi", 0);
33         invocationCount.put("greetMe", 0);
34         invocationCount.put("overloadedSayHi", 0);
35     }
36
37     public int getInvocationCount(String JavaDoc method) {
38         if (invocationCount.containsKey(method)) {
39             return invocationCount.get(method).intValue();
40         } else {
41             System.out.println("No invocation count for method: " + method);
42             return 0;
43         }
44     }
45
46     /**
47      * overloaded method - present for test purposes
48      */

49     @WebMethod(operationName = "sayHiOverloaded")
50     @WebResult(name = "responseType2", targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
51     @RequestWrapper(className = "org.objectweb.hello_world_soap_http.types.SayHi2",
52                     localName = "sayHi2",
53                     targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
54     @ResponseWrapper(className = "org.objectweb.hello_world_soap_http.types.SayHiResponse2",
55                      localName = "sayHiResponse2",
56                      targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
57     public String JavaDoc sayHi(String JavaDoc me) {
58         incrementInvocationCount("overloadedSayHi");
59         return "Hi " + me + "!";
60     }
61
62     @WebMethod
63     @WebResult(name = "responseType",
64                targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
65     @RequestWrapper(className = "org.objectweb.hello_world_soap_http.types.SayHi",
66                     localName = "sayHi",
67                     targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
68     @ResponseWrapper(className = "org.objectweb.hello_world_soap_http.types.SayHiResponse",
69                      localName = "sayHiResponse",
70                      targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
71     public String JavaDoc sayHi() {
72         incrementInvocationCount("sayHi");
73         return "Hi";
74     }
75
76     @WebMethod
77     @WebResult(name = "responseType",
78                targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
79     @RequestWrapper(className = "org.objectweb.hello_world_soap_http.types.GreetMe",
80                     localName = "greetMe",
81                     targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
82     @ResponseWrapper(className = "org.objectweb.hello_world_soap_http.types.GreetMeResponse",
83                      localName = "greetMeResponse",
84                      targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
85     public String JavaDoc greetMe(String JavaDoc me) {
86         incrementInvocationCount("greetMe");
87         return "Bonjour " + me + "!";
88     }
89     
90     @WebMethod
91     @RequestWrapper(className = "org.objectweb.hello_world_soap_http.types.GreetMeOneWay",
92                     localName = "greetMeOneWay",
93                     targetNamespace = "http://objectweb.org/hello_world_soap_http/types")
94     public void greetMeOneWay(String JavaDoc me) {
95         incrementInvocationCount("greetMeOneWay");
96         System.out.println("Hello there " + me);
97         System.out.println("That was OneWay to say hello");
98     }
99
100     public void testDocLitFault(String JavaDoc faultType) throws BadRecordLitFault, NoSuchCodeLitFault {
101     }
102
103     @Resource
104     public void setContext(WebServiceContext ctx) {
105         context = ctx;
106     }
107
108     public WebServiceContext getContext() {
109         return context;
110     }
111
112     @WebMethod(operationName = "PutLastTradedPrice")
113     public void putLastTradedPriceAsync(
114         @WebParam(name = "body", partName = "body")
115         String JavaDoc body) {
116         //Complete
117
}
118     
119     @WebMethod(operationName = "PutLastTradedPrice")
120     public void putLastTradedPrice(
121         @WebParam(name = "body", partName = "body")
122         String JavaDoc body) {
123         //Complete
124
}
125     
126     /**
127      * stop eclipse from whinging
128      */

129     public int getFoo() {
130         return foo;
131     }
132     
133     private void incrementInvocationCount(String JavaDoc method) {
134         LOG.info("Executing " + method);
135         int n = invocationCount.get(method);
136         invocationCount.put(method, n + 1);
137     }
138
139 }
140
Popular Tags