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: */
019: package org.apache.axis2.jaxws.proxy;
020:
021: import java.io.File;
022: import java.net.URL;
023: import java.util.concurrent.Future;
024:
025: import javax.xml.namespace.QName;
026: import javax.xml.ws.AsyncHandler;
027: import javax.xml.ws.BindingProvider;
028: import javax.xml.ws.Response;
029: import javax.xml.ws.Service;
030:
031: import junit.framework.TestCase;
032: import org.apache.axis2.jaxws.proxy.doclitwrapped.sei.DocLitWrappedProxy;
033: import org.apache.axis2.jaxws.proxy.doclitwrapped.sei.ProxyDocLitWrappedService;
034: import org.apache.axis2.jaxws.TestLogger;
035: import org.test.proxy.doclitwrapped.ReturnType;
036:
037: public class ProxyTests extends TestCase {
038: private QName serviceName = new QName(
039: "http://doclitwrapped.proxy.test.org",
040: "ProxyDocLitWrappedService");
041: private String axisEndpoint = "http://localhost:8080/axis2/services/ProxyDocLitWrappedService";
042: private QName portName = new QName(
043: "http://doclitwrapped.proxy.test.org",
044: "ProxyDocLitWrappedPort");
045: private String wsdlLocation = System.getProperty("basedir", ".")
046: + "/"
047: + "test/org/apache/axis2/jaxws/proxy/doclitwrapped/META-INF/ProxyDocLitWrapped.wsdl";
048: private boolean runningOnAxis = true;
049:
050: public void testMultipleServiceCalls() {
051: try {
052: if (!runningOnAxis) {
053: return;
054: }
055: TestLogger.logger
056: .debug("---------------------------------------");
057: TestLogger.logger.debug("test:" + getName());
058: String request = new String("some string request");
059: TestLogger.logger.debug("Service Call #1");
060: ProxyDocLitWrappedService service1 = new ProxyDocLitWrappedService();
061: DocLitWrappedProxy proxy1 = service1
062: .getProxyDocLitWrappedPort();
063: BindingProvider p1 = (BindingProvider) proxy1;
064: p1.getRequestContext().put(
065: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
066: axisEndpoint);
067: String response1 = proxy1.invoke(request);
068: TestLogger.logger.debug("Proxy Response =" + response1);
069: TestLogger.logger
070: .debug("---------------------------------------");
071:
072: TestLogger.logger.debug("Service Call #2");
073: ProxyDocLitWrappedService service2 = new ProxyDocLitWrappedService();
074: DocLitWrappedProxy proxy2 = service2
075: .getProxyDocLitWrappedPort();
076: BindingProvider p2 = (BindingProvider) proxy2;
077: p2.getRequestContext().put(
078: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
079: axisEndpoint);
080: String response2 = proxy2.invoke(request);
081: TestLogger.logger.debug("Proxy Response =" + response2);
082: TestLogger.logger
083: .debug("---------------------------------------");
084:
085: } catch (Exception e) {
086: //fail(getName() + " failed");
087: e.printStackTrace();
088: }
089: }
090:
091: public void testInvokeWithNullParam() {
092: try {
093: if (!runningOnAxis) {
094: return;
095: }
096: TestLogger.logger
097: .debug("---------------------------------------");
098: TestLogger.logger.debug("Test Name: " + getName());
099: File wsdl = new File(wsdlLocation);
100: URL wsdlUrl = wsdl.toURL();
101: Service service = Service.create(null, serviceName);
102: Object proxy = service.getPort(portName,
103: DocLitWrappedProxy.class);
104: TestLogger.logger
105: .debug(">>Invoking Binding Provider property");
106: BindingProvider p = (BindingProvider) proxy;
107: p.getRequestContext().put(
108: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
109: axisEndpoint);
110:
111: DocLitWrappedProxy dwp = (DocLitWrappedProxy) proxy;
112: TestLogger.logger.debug(">> Invoking Proxy Synchronously");
113: String request = null;
114: String response = dwp.invoke(request);
115: TestLogger.logger.debug("Proxy Response =" + response);
116: TestLogger.logger
117: .debug("---------------------------------------");
118: } catch (Exception e) {
119: e.printStackTrace();
120: fail("Exception received" + e);
121: }
122: }
123:
124: public void testInvoke() {
125: try {
126: if (!runningOnAxis) {
127: return;
128: }
129: TestLogger.logger
130: .debug("---------------------------------------");
131:
132: File wsdl = new File(wsdlLocation);
133: URL wsdlUrl = wsdl.toURL();
134: Service service = Service.create(null, serviceName);
135: String request = new String("some string request");
136: Object proxy = service.getPort(portName,
137: DocLitWrappedProxy.class);
138: TestLogger.logger
139: .debug(">>Invoking Binding Provider property");
140: BindingProvider p = (BindingProvider) proxy;
141: p.getRequestContext().put(
142: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
143: axisEndpoint);
144:
145: DocLitWrappedProxy dwp = (DocLitWrappedProxy) proxy;
146: TestLogger.logger.debug(">> Invoking Proxy Synchronously");
147: String response = dwp.invoke(request);
148: TestLogger.logger.debug("Proxy Response =" + response);
149: TestLogger.logger
150: .debug("---------------------------------------");
151: } catch (Exception e) {
152: e.printStackTrace();
153: fail("Exception received" + e);
154: }
155: }
156:
157: public void testInvokeWithWSDL() {
158: try {
159: if (!runningOnAxis) {
160: return;
161: }
162: TestLogger.logger
163: .debug("---------------------------------------");
164: File wsdl = new File(wsdlLocation);
165: URL wsdlUrl = wsdl.toURL();
166: Service service = Service.create(wsdlUrl, serviceName);
167: String request = new String("some string request");
168: Object proxy = service.getPort(portName,
169: DocLitWrappedProxy.class);
170: TestLogger.logger
171: .debug(">>Invoking Binding Provider property");
172: BindingProvider p = (BindingProvider) proxy;
173: p.getRequestContext().put(
174: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
175: axisEndpoint);
176:
177: DocLitWrappedProxy dwp = (DocLitWrappedProxy) proxy;
178: TestLogger.logger.debug(">> Invoking Proxy Synchronously");
179: String response = dwp.invoke(request);
180: TestLogger.logger.debug("Proxy Response =" + response);
181: TestLogger.logger
182: .debug("---------------------------------------");
183: } catch (Exception e) {
184: e.printStackTrace();
185: fail("Exception received" + e);
186: }
187: }
188:
189: public void testInvokeAsyncCallback() {
190: try {
191: if (!runningOnAxis) {
192: return;
193: }
194: TestLogger.logger
195: .debug("---------------------------------------");
196:
197: File wsdl = new File(wsdlLocation);
198: URL wsdlUrl = wsdl.toURL();
199: Service service = Service.create(null, serviceName);
200: String request = new String("some string request");
201: Object proxy = service.getPort(portName,
202: DocLitWrappedProxy.class);
203: TestLogger.logger
204: .debug(">>Invoking Binding Provider property");
205: BindingProvider p = (BindingProvider) proxy;
206: p.getRequestContext().put(
207: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
208: axisEndpoint);
209:
210: DocLitWrappedProxy dwp = (DocLitWrappedProxy) proxy;
211: TestLogger.logger
212: .debug(">> Invoking Proxy Asynchronous Callback");
213: AsyncHandler handler = new AsyncCallback();
214: Future<?> response = dwp.invokeAsync(request, handler);
215: TestLogger.logger
216: .debug("---------------------------------------");
217: } catch (Exception e) {
218: e.printStackTrace();
219: fail("Exception received" + e);
220: }
221: }
222:
223: public void testInvokeAsyncPolling() {
224: try {
225: TestLogger.logger
226: .debug("---------------------------------------");
227:
228: File wsdl = new File(wsdlLocation);
229: URL wsdlUrl = wsdl.toURL();
230: Service service = Service.create(null, serviceName);
231: DocLitWrappedProxy proxy = service.getPort(portName,
232: DocLitWrappedProxy.class);
233:
234: String request = new String("some string request");
235:
236: TestLogger.logger
237: .debug(">> Invoking Binding Provider property");
238: BindingProvider p = (BindingProvider) proxy;
239: p.getRequestContext().put(
240: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
241: axisEndpoint);
242:
243: TestLogger.logger
244: .debug(">> Invoking Proxy with async polling request");
245: Response<ReturnType> asyncResponse = proxy
246: .invokeAsync(request);
247:
248: while (!asyncResponse.isDone()) {
249: TestLogger.logger
250: .debug(">> Async invocation still not complete");
251: Thread.sleep(1000);
252: }
253:
254: ReturnType response = asyncResponse.get();
255: assertNotNull(response);
256: } catch (Exception e) {
257: e.printStackTrace();
258: fail("Exception received" + e);
259: }
260: }
261:
262: public void testTwoWay() {
263: /*
264: try{
265: if(runningOnAxis){
266: return;
267: }
268: File wsdl= new File(wsdlLocation);
269: URL wsdlUrl = wsdl.toURL();
270: Service service = Service.create(null, serviceName);
271: String request = new String("some string request");
272:
273: Object proxy =service.getPort(portName, DocLitWrappedProxy.class);
274: BindingProvider p = (BindingProvider)proxy;
275: p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,wasEndpoint);
276:
277: DocLitWrappedProxy dwp = (DocLitWrappedProxy)proxy;
278: String response = dwp.twoWay(request);
279: System.out.println("Response =" + response);
280: }catch(Exception e){
281: e.printStackTrace();
282: fail("Exception received" + e);
283: }
284: */
285: }
286:
287: public void testOneWay() {
288:
289: }
290:
291: public void testHolder() {
292:
293: }
294:
295: public void testTwoWayAsyncCallback() {
296: /*
297: try{
298: if(runningOnAxis){
299: return;
300: }
301: File wsdl= new File(wsdlLocation);
302: URL wsdlUrl = wsdl.toURL();
303: Service service = Service.create(null, serviceName);
304:
305: String request = new String("some string request");
306:
307: Object proxy =service.getPort(portName, DocLitWrappedProxy.class);
308: BindingProvider p = (BindingProvider)proxy;
309: p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,wasEndpoint);
310:
311: DocLitWrappedProxy dwp = (DocLitWrappedProxy)proxy;
312: AsyncHandler handler = new AsyncCallback();
313: Future<?> response = dwp.twoWayAsync(request, handler);
314:
315: }catch(Exception e){
316: e.printStackTrace();
317: fail("Exception received" + e);
318: }
319: */
320: }
321:
322: public void testAsyncPooling() {
323:
324: }
325: }
|