001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.hello_world_soap_http;
019:
020: import java.io.IOException;
021: import java.util.concurrent.Future;
022: import java.util.logging.Logger;
023:
024: import javax.annotation.Resource;
025:
026: import javax.jws.WebService;
027: import javax.xml.ws.AsyncHandler;
028: import javax.xml.ws.BindingProvider;
029: import javax.xml.ws.Response;
030: import javax.xml.ws.WebServiceContext;
031: import javax.xml.ws.handler.MessageContext;
032:
033: import org.apache.hello_world_soap_http.types.BareDocumentResponse;
034: import org.apache.hello_world_soap_http.types.ErrorCode;
035: import org.apache.hello_world_soap_http.types.GreetMeLaterResponse;
036: import org.apache.hello_world_soap_http.types.GreetMeResponse;
037: import org.apache.hello_world_soap_http.types.GreetMeSometimeResponse;
038: import org.apache.hello_world_soap_http.types.NoSuchCodeLit;
039: import org.apache.hello_world_soap_http.types.SayHiResponse;
040: import org.apache.hello_world_soap_http.types.TestDocLitFaultResponse;
041: import org.apache.hello_world_soap_http.types.TestNillableResponse;
042:
043: @WebService(serviceName="SOAPService",portName="SoapPort",endpointInterface="org.apache.hello_world_soap_http.Greeter",targetNamespace="http://apache.org/hello_world_soap_http",wsdlLocation="testutils/hello_world.wsdl")
044: public class GreeterImpl implements Greeter {
045:
046: private static final Logger LOG = Logger
047: .getLogger(GreeterImpl.class.getName());
048:
049: @Resource
050: private WebServiceContext context;
051:
052: private String prefix = "";
053:
054: private int invocationCount;
055:
056: public WebServiceContext getContext() {
057: return context;
058: }
059:
060: public void setPrefix(String p) {
061: prefix = p;
062: }
063:
064: public String getPrefix() {
065: return prefix;
066: }
067:
068: public String greetMe(String me) {
069: if ("secure".equals(me)) {
070: MessageContext ctx = getContext().getMessageContext();
071: return "Hello "
072: + ctx.get(BindingProvider.USERNAME_PROPERTY);
073: }
074: if ("principal".equals(me)) {
075: return "Hello " + getContext().getUserPrincipal().getName();
076: }
077:
078: LOG.info("Invoking greetMe " + prefix + me);
079: invocationCount++;
080: return "Hello " + me;
081: }
082:
083: public String greetMeLater(long delay) {
084: LOG.info("Invoking greetMeLater " + delay);
085: if (delay > 0) {
086: try {
087: Thread.sleep(delay);
088: } catch (InterruptedException ex) {
089: /// ignore
090: }
091: }
092: return "Hello, finally!";
093: }
094:
095: public String sayHi() {
096: LOG.info("Invoking sayHi");
097: invocationCount++;
098: return "Bonjour";
099: }
100:
101: public void testDocLitFault(String faultType)
102: throws BadRecordLitFault, NoSuchCodeLitFault {
103: LOG.info("Invoking testDocLitFault");
104: invocationCount++;
105: if (faultType.equals(BadRecordLitFault.class.getSimpleName())) {
106: throw new BadRecordLitFault("TestBadRecordLit",
107: "BadRecordLitFault");
108: }
109: if (faultType.equals(NoSuchCodeLitFault.class.getSimpleName())) {
110: ErrorCode ec = new ErrorCode();
111: ec.setMajor((short) 1);
112: ec.setMinor((short) 1);
113: NoSuchCodeLit nscl = new NoSuchCodeLit();
114: nscl.setCode(ec);
115: throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
116: }
117: throw new RuntimeException("Unknown source", new IOException(
118: "dummy io exception"));
119: }
120:
121: public void greetMeOneWay(String requestType) {
122: invocationCount++;
123: System.out.println("********* greetMeOneWay: " + requestType);
124: }
125:
126: public String greetMeSometime(String me) {
127: invocationCount++;
128: //System.err.println("In greetMeSometime: " + me);
129: return "How are you " + me;
130: }
131:
132: public BareDocumentResponse testDocLitBare(String in) {
133: invocationCount++;
134: BareDocumentResponse res = new BareDocumentResponse();
135: res.setCompany("CXF");
136: res.setId(1);
137: return res;
138: }
139:
140: public Future<?> greetMeSometimeAsync(String requestType,
141: AsyncHandler<GreetMeSometimeResponse> asyncHandler) {
142: invocationCount++;
143: System.err.println("In greetMeSometimeAsync 1");
144: return null;
145: /*not called */
146: }
147:
148: public Response<GreetMeSometimeResponse> greetMeSometimeAsync(
149: String requestType) {
150: invocationCount++;
151: System.err.println("In greetMeSometimeAsync 2");
152: return null;
153: /*not called */
154: }
155:
156: public Response<TestDocLitFaultResponse> testDocLitFaultAsync(
157: String faultType) {
158: invocationCount++;
159: System.err.println("In testDocLitFaultAsync 1");
160: return null;
161: /*not called */
162: }
163:
164: public Future<?> testDocLitFaultAsync(String faultType,
165: AsyncHandler ah) {
166: invocationCount++;
167: System.err.println("In testDocLitFaultAsync 2");
168: return null;
169: /*not called */
170: }
171:
172: public Future<?> testDocLitBareAsync(String bare, AsyncHandler ah) {
173: invocationCount++;
174: return null;
175: /* not called */
176: }
177:
178: public Response<BareDocumentResponse> testDocLitBareAsync(
179: String bare) {
180: invocationCount++;
181: return null;
182: /* not called */
183: }
184:
185: public Future<?> greetMeAsync(String requestType,
186: AsyncHandler<GreetMeResponse> asyncHandler) {
187: invocationCount++;
188: return null;
189: /*not called */
190: }
191:
192: public Response<GreetMeResponse> greetMeAsync(String requestType) {
193: invocationCount++;
194: return null;
195: /*not called */
196: }
197:
198: public Future<?> greetMeLaterAsync(long requestType,
199: AsyncHandler<GreetMeLaterResponse> asyncHandler) {
200: return null;
201: /*not called */
202: }
203:
204: public Response<GreetMeLaterResponse> greetMeLaterAsync(
205: long requestType) {
206: return null;
207: /*not called */
208: }
209:
210: public Future<?> sayHiAsync(AsyncHandler<SayHiResponse> asyncHandler) {
211: invocationCount++;
212: return null;
213: /*not called */
214: }
215:
216: public Response<SayHiResponse> sayHiAsync() {
217: invocationCount++;
218: return null;
219: /*not called */
220: }
221:
222: public int getInvocationCount() {
223: return invocationCount;
224: }
225:
226: public String testNillable(String nillElem, int intElem) {
227: System.out.println("the testNillable is invoked");
228: return nillElem;
229: }
230:
231: public Response<TestNillableResponse> testNillableAsync(
232: String nillElem, int intElem) {
233: return null;
234: }
235:
236: public Future<?> testNillableAsync(String nillElem, int intElem,
237: AsyncHandler<TestNillableResponse> asyncHandler) {
238: return null;
239: }
240:
241: }
|