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.dispatch;
020:
021: import java.io.File;
022: import java.io.FileInputStream;
023: import java.util.concurrent.Future;
024:
025: import javax.xml.namespace.QName;
026: import javax.xml.soap.MessageFactory;
027: import javax.xml.soap.SOAPMessage;
028: import javax.xml.ws.Dispatch;
029: import javax.xml.ws.Response;
030: import javax.xml.ws.Service;
031:
032: import junit.framework.TestCase;
033: import org.apache.axis2.jaxws.TestLogger;
034:
035: public class SOAPMessageDispatch extends TestCase {
036: private String url = "http://localhost:8080/axis2/services/ProxyDocLitWrappedService";
037: private QName serviceName = new QName(
038: "http://org.apache.axis2.proxy.doclitwrapped",
039: "ProxyDocLitWrappedService");
040: private QName portName = new QName(
041: "http://org.apache.axis2.proxy.doclitwrapped",
042: "ProxyDocLitWrappedPort");
043:
044: String messageResource = "test-resources" + File.separator + "xml"
045: + File.separator + "soapmessage.xml";
046:
047: public void testSOAPMessageSyncMessageMode() throws Exception {
048:
049: String basedir = new File(System.getProperty("basedir", "."))
050: .getAbsolutePath();
051: String messageResource = new File(basedir, this .messageResource)
052: .getAbsolutePath();
053:
054: TestLogger.logger
055: .debug("---------------------------------------");
056: TestLogger.logger.debug("test: " + getName());
057: //Initialize the JAX-WS client artifacts
058: Service svc = Service.create(serviceName);
059: svc.addPort(portName, null, url);
060: Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
061: SOAPMessage.class, Service.Mode.MESSAGE);
062:
063: //Create SOAPMessage Object no attachments here.
064: FileInputStream inputStream = new FileInputStream(
065: messageResource);
066: MessageFactory factory = MessageFactory.newInstance();
067: SOAPMessage msgObject = factory
068: .createMessage(null, inputStream);
069:
070: //Invoke the Dispatch
071: TestLogger.logger.debug(">> Invoking Async Dispatch");
072: SOAPMessage response = dispatch.invoke(msgObject);
073:
074: assertNotNull("dispatch invoke returned null", response);
075: response.writeTo(System.out);
076: }
077:
078: public void testSOAPMessageAsyncCallbackMessageMode()
079: throws Exception {
080:
081: String basedir = new File(System.getProperty("basedir", "."))
082: .getAbsolutePath();
083: String messageResource = new File(basedir, this .messageResource)
084: .getAbsolutePath();
085:
086: TestLogger.logger
087: .debug("---------------------------------------");
088: TestLogger.logger.debug("test: " + getName());
089: //Initialize the JAX-WS client artifacts
090: Service svc = Service.create(serviceName);
091: svc.addPort(portName, null, url);
092: Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
093: SOAPMessage.class, Service.Mode.MESSAGE);
094:
095: //Create SOAPMessage Object no attachments here.
096: FileInputStream inputStream = new FileInputStream(
097: messageResource);
098: MessageFactory factory = MessageFactory.newInstance();
099: SOAPMessage msgObject = factory
100: .createMessage(null, inputStream);
101:
102: AsyncCallback<SOAPMessage> ac = new AsyncCallback<SOAPMessage>();
103: //Invoke the Dispatch
104: TestLogger.logger.debug(">> Invoking sync Dispatch");
105: Future<?> monitor = dispatch.invokeAsync(msgObject, ac);
106:
107: assertNotNull("dispatch invokeAsync returned null Future<?>",
108: monitor);
109: while (!monitor.isDone()) {
110: TestLogger.logger
111: .debug(">> Async invocation still not complete");
112: Thread.sleep(1000);
113: }
114:
115: SOAPMessage response = ac.getValue();
116: assertNotNull("dispatch invoke returned null", response);
117: response.writeTo(System.out);
118: }
119:
120: public void testSOAPMessageAsyncPollingMessageMode()
121: throws Exception {
122:
123: String basedir = new File(System.getProperty("basedir", "."))
124: .getAbsolutePath();
125: String messageResource = new File(basedir, this .messageResource)
126: .getAbsolutePath();
127:
128: TestLogger.logger
129: .debug("---------------------------------------");
130: TestLogger.logger.debug("test: " + getName());
131: //Initialize the JAX-WS client artifacts
132: Service svc = Service.create(serviceName);
133: svc.addPort(portName, null, url);
134: Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
135: SOAPMessage.class, Service.Mode.MESSAGE);
136:
137: //Create SOAPMessage Object no attachments here.
138: FileInputStream inputStream = new FileInputStream(
139: messageResource);
140: MessageFactory factory = MessageFactory.newInstance();
141: SOAPMessage msgObject = factory
142: .createMessage(null, inputStream);
143:
144: //Invoke the Dispatch
145: TestLogger.logger.debug(">> Invoking sync Dispatch");
146: Response<SOAPMessage> asyncResponse = dispatch
147: .invokeAsync(msgObject);
148:
149: assertNotNull("dispatch invokeAsync returned null Response",
150: asyncResponse);
151: while (!asyncResponse.isDone()) {
152: TestLogger.logger
153: .debug(">> Async invocation still not complete");
154: Thread.sleep(1000);
155: }
156:
157: SOAPMessage response = asyncResponse.get();
158: assertNotNull("dispatch invoke returned null", response);
159: response.writeTo(System.out);
160: }
161:
162: }
|