You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by wo...@apache.org on 2008/03/03 19:48:24 UTC
svn commit: r633234 [5/24] - in /webservices/axis2/trunk/java: ./
modules/jaxws-integration/ modules/jaxws-integration/test/
modules/jaxws-integration/test/client/ modules/jaxws-integration/test/org/
modules/jaxws-integration/test/org/apache/ modules/j...
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/AsyncCallback.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/AsyncCallback.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/AsyncCallback.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/AsyncCallback.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.util.concurrent.ExecutionException;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+public class AsyncCallback<T> implements AsyncHandler<T> {
+
+ private T value;
+ private Throwable exception;
+
+ public void handleResponse(Response<T> response) {
+ try {
+ value = response.get();
+ } catch (Throwable t) {
+ exception = t;
+ }
+ }
+
+ public boolean hasError() {
+ return (exception != null);
+ }
+
+ public Throwable getError() {
+ return exception;
+ }
+
+ public T getValue() {
+ return value;
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/CallbackHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/CallbackHandler.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/CallbackHandler.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/CallbackHandler.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.TestLogger;
+
+public class CallbackHandler<T> implements AsyncHandler <T> {
+
+ public void handleResponse(Response response) {
+ TestLogger.logger.debug(">> Processing async reponse");
+ try{
+ T res = (T) response.get();
+
+ if(res instanceof SOAPMessage){
+ SOAPMessage message = (SOAPMessage) res;
+ message.writeTo(System.out);
+
+ }
+
+ if(res instanceof String){
+ TestLogger.logger.debug("Response [" + res + "]");
+ }
+ else if(Source.class.isAssignableFrom(res.getClass())){
+ Source source = (Source) res;
+
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(source);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+
+ TestLogger.logger.debug(responseText);
+ }
+ TestLogger.logger.debug("---------------------------------------------");
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DOMSourceDispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.io.ByteArrayInputStream;
+import java.util.concurrent.Future;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+
+import junit.framework.TestCase;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.TestLogger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * This class tests the JAX-WS Dispatch with various forms of the
+ * javax.xml.transform.dom.DOMSource
+ */
+public class DOMSourceDispatch extends TestCase{
+
+ private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ public void testSyncPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleBodyContent);
+
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ Source response = dispatch.invoke(request);
+ assertNotNull("dispatch invoke returned null",response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testSyncMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleSoapMessage);
+
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ Source response = dispatch.invoke(request);
+ assertNotNull("dispatch invoke returned null",response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncCallbackPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleBodyContent);
+
+ // Setup the callback for async responses
+ AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = callbackHandler.getValue();
+ assertNotNull(response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncCallbackMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleSoapMessage);
+
+ // Setup the callback for async responses
+ AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = callbackHandler.getValue();
+ assertNotNull(response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncPollingPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleBodyContent);
+
+ TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
+ Response<Source> asyncResponse = dispatch.invokeAsync(request);
+
+ while (!asyncResponse.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = asyncResponse.get();
+ assertNotNull(response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncPollingMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleSoapMessage);
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Response<Source> asyncResponse = dispatch.invokeAsync(request);
+
+ while (!asyncResponse.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = asyncResponse.get();
+ assertNotNull(response);
+
+ // Turn the Source into a String so we can check it
+ String responseText = createStringFromSource(response);
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testOneWayPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleBodyContent);
+
+ TestLogger.logger.debug(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ public void testOneWayMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create the DOMSource
+ DOMSource request = createDOMSourceFromString(DispatchTestConstants.sampleSoapMessage);
+
+ TestLogger.logger.debug(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ public void testBadDOMSource() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create the DOMSource
+ DOMSource request = new DOMSource();
+
+ try {
+ dispatch.invokeOneWay(request);
+ fail("WebServiceException was expected");
+ } catch (WebServiceException e) {
+ TestLogger.logger.debug("A Web Service Exception was expected: " + e.toString());
+ assertTrue(e.getMessage() != null);
+ } catch (Exception e) {
+ fail("WebServiceException was expected, but received " + e);
+ }
+
+ }
+ /**
+ * Create a DOMSource with the provided String as the content
+ * @param input
+ * @return
+ */
+ private DOMSource createDOMSourceFromString(String input) throws Exception {
+ byte[] bytes = input.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+
+ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+ domFactory.setNamespaceAware(true);
+ DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
+ Document domTree = domBuilder.parse(stream);
+ Node node = domTree.getDocumentElement();
+
+ DOMSource domSource = new DOMSource(node);
+ return domSource;
+ }
+
+ /**
+ * Create a String from the provided Source
+ * @param input
+ * @return
+ */
+ private String createStringFromSource(Source input) throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(input);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String text = r2w.getAsString();
+ return text;
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestConstants.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestConstants.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestConstants.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import javax.xml.namespace.QName;
+
+public class DispatchTestConstants {
+
+ public static final String URL = "http://localhost:6060/axis2/services/EchoService";
+ public static final String BADURL = "http://this.is.not.a.valid.hostname.at.all.no.way:9999/wacky";
+ public static final QName QNAME_SERVICE = new QName("http://ws.apache.org/axis2", "EchoService");
+ public static final QName QNAME_PORT = new QName("http://ws.apache.org/axis2", "EchoServiceSOAP11port0");
+
+ private static final String sampleSoapEnvelopeHeader =
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ "<soap:Body>";
+
+ private static final String sampleSoapEnvelopeFooter =
+ "</soap:Body>" +
+ "</soap:Envelope>";
+
+ public static final String sampleBodyContent =
+ "<ns1:echoString xmlns:ns1=\"http://test\">" +
+ "<ns1:input xmlns=\"http://test\">HELLO THERE!!!</ns1:input>" +
+ "</ns1:echoString>";
+
+ public static final String sampleBodyContent_bad =
+ "<ns1:echoString xmlns:ns1=\"http://test\">" +
+ "<ns1:input xmlns=\"http://test\">THROW EXCEPTION</ns1:input>" +
+ "</ns1:echoString>";
+
+ public static final String sampleSoapMessage =
+ sampleSoapEnvelopeHeader +
+ sampleBodyContent +
+ sampleSoapEnvelopeFooter;
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestSuite.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestSuite.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestSuite.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/DispatchTestSuite.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import junit.framework.TestSuite;
+
+public class DispatchTestSuite {
+
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite();
+ suite = addTestSuites(suite);
+ return suite;
+ }
+
+ public static TestSuite addTestSuites(TestSuite suite) {
+ suite.addTestSuite(StringDispatch.class);
+ suite.addTestSuite(StreamSourceDispatch.class);
+ suite.addTestSuite(DOMSourceDispatch.class);
+ suite.addTestSuite(SAXSourceDispatch.class);
+ suite.addTestSuite(SOAPMessageDispatch.class);
+ suite.addTestSuite(JAXBDispatch.class);
+ suite.addTestSuite(JAXBSourceDispatch.class);
+ return suite;
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBCallbackHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBCallbackHandler.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBCallbackHandler.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBCallbackHandler.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import test.EchoStringResponse;
+import org.apache.axis2.jaxws.TestLogger;
+
+public class JAXBCallbackHandler<T> implements AsyncHandler<T> {
+
+ T data = null;
+ public void handleResponse(Response response) {
+ try {
+ data = (T) response.get();
+ TestLogger.logger.debug(">> Async response received: " + data);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public T getData() {
+ return data;
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBDispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBDispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.util.concurrent.Future;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import org.xmlsoap.schemas.soap.envelope.Body;
+import org.xmlsoap.schemas.soap.envelope.Envelope;
+import org.apache.axis2.jaxws.TestLogger;
+
+import junit.framework.TestCase;
+import test.EchoString;
+import test.EchoStringResponse;
+import test.ObjectFactory;
+
+public class JAXBDispatch extends TestCase {
+
+ private Dispatch<Object> dispatchPayload;
+ private Dispatch<Object> dispatchMessage;
+ private JAXBContext jbc;
+
+ public JAXBDispatch(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ //Create the Service object
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+
+ //Create the JAX-B Dispatch object to recognize the test and soap packages
+ jbc = JAXBContext.newInstance("test:org.xmlsoap.schemas.soap.envelope");
+
+ // Create Payload and Message Dispatch
+ dispatchPayload = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ jbc, Service.Mode.PAYLOAD);
+ dispatchMessage = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ jbc, Service.Mode.MESSAGE);
+ }
+
+ public void testSyncPayload() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("SYNC JAXB PAYLOAD TEST");
+
+ // Invoke the Dispatch<Object>
+ TestLogger.logger.debug(">> Invoking sync Dispatch with JAX-B Parameter");
+ EchoStringResponse response = (EchoStringResponse) dispatchPayload.invoke(request);
+
+ assertNotNull(response);
+
+ TestLogger.logger.debug(">> Response content: " + response.getEchoStringReturn());
+
+ assertTrue("[ERROR] - Response object was null", response != null);
+ assertTrue("[ERROR] - No content in response object", response.getEchoStringReturn() != null);
+ assertTrue("[ERROR] - Zero length content in response", response.getEchoStringReturn().length() > 0);
+ }
+
+ public void testAysncPayload() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("ASYNC(CALLBACK) JAXB PAYLOAD TEST");
+
+ // Create the callback for async responses
+ JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
+
+ // Invoke the Dispatch<Object> asynchronously
+ TestLogger.logger.debug(">> Invoking async(callback) Dispatch with JAX-B Parameter");
+ Future<?> monitor = dispatchPayload.invokeAsync(request, callback);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ EchoStringResponse response = (EchoStringResponse) callback.getData();
+ assertNotNull(response);
+
+ TestLogger.logger.debug(">> Response content: " + response.getEchoStringReturn());
+
+ assertTrue("[ERROR] - Response object was null", response != null);
+ assertTrue("[ERROR] - No content in response object", response.getEchoStringReturn() != null);
+ assertTrue("[ERROR] - Zero length content in response", response.getEchoStringReturn().length() > 0);
+
+ }
+
+ public void testOneWayPayload() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("ONE-WAY JAXB PAYLOAD TEST");
+
+ // Invoke the Dispatch<Object> one-way
+ TestLogger.logger.debug(">> Invoking one-way Dispatch with JAX-B Parameter");
+ dispatchPayload.invokeOneWay(request);
+ }
+
+ public void testSyncMessage() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString echoString = factory.createEchoString();
+ echoString.setInput("SYNC JAXB MESSAGETEST");
+
+ JAXBElement<Envelope> request = createJAXBEnvelope();
+ request.getValue().getBody().getAny().add(echoString);
+
+ jbc.createMarshaller().marshal(request,System.out);
+
+ // Invoke the Dispatch<Object>
+ TestLogger.logger.debug(">> Invoking sync Dispatch with JAX-B Parameter");
+ JAXBElement<Envelope> jaxbResponse = (JAXBElement<Envelope>) dispatchMessage.invoke(request);
+
+ assertNotNull(jaxbResponse);
+ Envelope response = jaxbResponse.getValue();
+ assertNotNull(response);
+ assertNotNull(response.getBody());
+ EchoStringResponse echoStringResponse = (EchoStringResponse) response.getBody().getAny().get(0);
+
+ TestLogger.logger.debug(">> Response content: " + echoStringResponse.getEchoStringReturn());
+ assertTrue("[ERROR] - No content in response object", echoStringResponse.getEchoStringReturn() != null);
+ assertTrue("[ERROR] - Zero length content in response", echoStringResponse.getEchoStringReturn().length() > 0);
+ }
+
+ public void testAysncMessage() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString echoString = factory.createEchoString();
+ echoString.setInput("ASYNC(CALLBACK) JAXB MESSAGE TEST");
+
+ JAXBElement<Envelope> request = createJAXBEnvelope();
+ request.getValue().getBody().getAny().add(echoString);
+
+
+ // Create the callback for async responses
+ JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
+
+ // Invoke the Dispatch<Object> asynchronously
+ TestLogger.logger.debug(">> Invoking async(callback) Dispatch with JAX-B Parameter");
+ Future<?> monitor = dispatchMessage.invokeAsync(request, callback);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ JAXBElement<Envelope> jaxbResponse = (JAXBElement<Envelope>) callback.getData();
+
+ assertNotNull(jaxbResponse);
+ Envelope response = jaxbResponse.getValue();
+
+ assertNotNull(response);
+ assertNotNull(response.getBody());
+ EchoStringResponse echoStringResponse = (EchoStringResponse) response.getBody().getAny().get(0);
+
+ TestLogger.logger.debug(">> Response content: " + echoStringResponse.getEchoStringReturn());
+ assertTrue("[ERROR] - No content in response object", echoStringResponse.getEchoStringReturn() != null);
+ assertTrue("[ERROR] - Zero length content in response", echoStringResponse.getEchoStringReturn().length() > 0);
+
+
+ }
+
+ public void testOneWayMessge() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString echoString = factory.createEchoString();
+ echoString.setInput("ONE-WAY JAXB MESSAGE TEST");
+
+ JAXBElement<Envelope> request = createJAXBEnvelope();
+ request.getValue().getBody().getAny().add(echoString);
+
+ // Invoke the Dispatch<Object> one-way
+ TestLogger.logger.debug(">> Invoking one-way Dispatch with JAX-B Parameter");
+ dispatchMessage.invokeOneWay(request);
+ }
+
+ private JAXBElement<Envelope> createJAXBEnvelope() {
+ org.xmlsoap.schemas.soap.envelope.ObjectFactory factory =
+ new org.xmlsoap.schemas.soap.envelope.ObjectFactory();
+ Envelope env = new Envelope();
+
+ Body body = new Body();
+ env.setBody(body);
+
+ JAXBElement<Envelope> jaxbEnv = factory.createEnvelope(env);
+ return jaxbEnv;
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBSourceDispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBSourceDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/JAXBSourceDispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import junit.framework.TestCase;
+import org.test.dispatch.jaxbsource.Invoke;
+import org.test.dispatch.jaxbsource.ObjectFactory;
+import org.apache.axis2.jaxws.TestLogger;
+
+/*
+* This is a test case for Invoking Dispatch with a JAXBSource.
+* test uses JAXB Objects from org.test.dispatch.jaxbsource package, create a request of JAXBSource type
+* and invokes the service endpoint and reads the response of type Source. Assert failure if response not received.
+*/
+
+
+public class JAXBSourceDispatch extends TestCase {
+ /**
+ * Invoke a sync Dispatch<JAXBSource> in PAYLOAD mode
+ */
+
+ private String url = "http://localhost:6060/axis2/services/SourceProviderService";
+ private QName serviceName = new QName("http://ws.apache.org/axis2", "SourceProviderService");
+ private QName portName =new QName("http://ws.apache.org/axis2", "SimpleProviderServiceSOAP11port0");
+
+ public void testJAXBSourceSyncPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+ try{
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, url);
+ Dispatch<Source> dispatch = svc.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
+
+ //Create JAXBContext and JAXBSource here.
+ ObjectFactory factory = new ObjectFactory();
+ Invoke invokeObj = factory.createInvoke();
+ invokeObj.setInvokeStr("Some Request");
+ JAXBContext ctx = JAXBContext.newInstance("org.test.dispatch.jaxbsource");
+
+ JAXBSource jbSrc = new JAXBSource(ctx.createMarshaller(), invokeObj);
+ // Invoke the Dispatch
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ //Invoke Server endpoint and read response
+ Source response = dispatch.invoke(jbSrc);
+
+ assertNotNull("dispatch invoke returned null", response);
+ //Print the response as string.
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ Result result = new StreamResult(writer);
+ t.transform(response, result);
+
+ TestLogger.logger.debug("Response On Client: \n" + writer.getBuffer().toString());
+ TestLogger.logger.debug("---------------------------------------");
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/ParamTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/ParamTests.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/ParamTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/ParamTests.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.TestCase;
+
+/**
+ * A suite for some tests for specific behavior in the Dispatch with
+ * null and invalid params.
+ */
+public class ParamTests extends TestCase {
+
+ public ParamTests(String name) {
+ super(name);
+ }
+
+ public void testNullSoapParamWithMessageMode() {
+ QName serviceName = new QName("http://test", "MyService");
+ QName portName = new QName("http://test", "MyPort");
+
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
+
+ Dispatch<Source> dispatch = svc.createDispatch(portName,
+ Source.class, Mode.PAYLOAD);
+
+ boolean handled = false;
+ try {
+ dispatch.invoke(null);
+ }
+ catch (WebServiceException wse) {
+ handled = true;
+ }
+
+ assertTrue("A WebServiceException should be thrown for this null param", handled);
+ }
+
+ public void testNullHttpParamWithPayloadMode() {
+ // fill in this test when we add XML/HTTP Binding support
+ }
+
+ public void testNullHttpParamWithMessageMode() {
+ // fill in this test when we add XML/HTTP Binding support
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SAXSourceDispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.io.ByteArrayInputStream;
+import java.util.concurrent.Future;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+
+import junit.framework.TestCase;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.TestLogger;
+import org.xml.sax.InputSource;
+
+/**
+ * This class tests the JAX-WS Dispatch<Source> with content in various
+ * forms of a javax.xml.transform.sax.SAXSource.
+ */
+public class SAXSourceDispatch extends TestCase{
+
+ private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ public void testSyncPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ Source response = dispatch.invoke(request);
+
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testSyncMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking sync Dispatch with Message Mode");
+ Source response = dispatch.invoke(request);
+
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncCallbackPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Setup the callback for async responses
+ AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = callbackHandler.getValue();
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncCallbackMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Setup the callback for async responses
+ AsyncCallback<Source> callbackHandler = new AsyncCallback<Source>();
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = callbackHandler.getValue();
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncPollingPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
+ Response<Source> asyncResponse = dispatch.invokeAsync(request);
+
+ while (!asyncResponse.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = asyncResponse.get();
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testAsyncPollingMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
+ Response<Source> asyncResponse = dispatch.invokeAsync(request);
+
+ while (!asyncResponse.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ Source response = asyncResponse.get();
+ assertNotNull("dispatch invoke returned null", response);
+
+ // Prepare the response content for checking
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
+ Reader2Writer r2w = new Reader2Writer(reader);
+ String responseText = r2w.getAsString();
+ TestLogger.logger.debug(responseText);
+
+ // Check to make sure the content is correct
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ public void testOneWayPayloadMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.PAYLOAD);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ public void testOneWayMessageMode() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create a SAXSource out of the string content
+ byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+ InputSource input = new InputSource(stream);
+ Source request = new SAXSource(input);
+
+ TestLogger.logger.debug(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ public void testBadSAXSource() throws Exception {
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+
+ // Initialize the JAX-WS client artifacts
+ Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
+ svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
+ Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ Source.class, Service.Mode.MESSAGE);
+
+ // Create an empty (invalid) SAXSource
+ Source request = new SAXSource();
+
+ try {
+ dispatch.invoke(request);
+ fail("WebServiceException was expected");
+ } catch (WebServiceException e) {
+ TestLogger.logger.debug("A Web Service Exception was expected: " + e.toString());
+ assertTrue(e.getMessage() != null);
+ } catch (Exception e) {
+ fail("WebServiceException was expected, but received:" + e);
+ }
+
+ try {
+ dispatch.invokeOneWay(request);
+ fail("WebServiceException was expected");
+ } catch (WebServiceException e) {
+ TestLogger.logger.debug("A Web Service Exception was expected: " + e.toString());
+ assertTrue(e.getMessage() != null);
+ } catch (Exception e) {
+ fail("WebServiceException was expected, but received:" + e);
+ }
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAP12Dispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAP12Dispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAP12Dispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAP12Dispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import org.apache.axis2.jaxws.description.builder.MDQConstants;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * This class uses the JAX-WS Dispatch API to test sending and receiving
+ * messages using SOAP 1.2.
+ */
+public class SOAP12Dispatch extends TestCase {
+
+ private static final QName QNAME_SERVICE = new QName(
+ "http://org/apache/axis2/jaxws/test/SOAP12", "SOAP12Service");
+ private static final QName QNAME_PORT = new QName(
+ "http://org/apache/axis2/jaxws/test/SOAP12", "SOAP12Port");
+ private static final String URL_ENDPOINT = "http://localhost:6060/axis2/services/SOAP12ProviderService.SOAP12ProviderPort";
+
+ private static final String sampleRequest =
+ "<test:echoString xmlns:test=\"http://org/apache/axis2/jaxws/test/SOAP12\">" +
+ "<test:input>SAMPLE REQUEST MESSAGE</test:input>" +
+ "</test:echoString>";
+ private static final String sampleEnvelopeHead =
+ "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" +
+ "<soapenv:Header /><soapenv:Body>";
+ private static final String sampleEnvelopeHead_MustUnderstand =
+ "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" +
+ "<soapenv:Header>" +
+ "<soapenv:codeHeaderSOAP12 soapenv:mustUnderstand=\"true\">" +
+ "<code>default</code>" +
+ "</soapenv:codeHeaderSOAP12>" +
+ "</soapenv:Header>" +
+ "<soapenv:Body>";
+ private static final String sampleEnvelopeTail =
+ "</soapenv:Body></soapenv:Envelope>";
+ private static final String sampleEnvelope =
+ sampleEnvelopeHead +
+ sampleRequest +
+ sampleEnvelopeTail;
+
+ private static final String sampleEnvelope_MustUnderstand =
+ sampleEnvelopeHead_MustUnderstand +
+ sampleRequest +
+ sampleEnvelopeTail;
+
+ public SOAP12Dispatch(String name) {
+ super(name);
+ }
+
+ /**
+ * Test sending a SOAP 1.2 request in PAYLOAD mode
+ */
+ public void testSOAP12DispatchPayloadMode() throws Exception {
+ // Create the JAX-WS client needed to send the request
+ Service service = Service.create(QNAME_SERVICE);
+ service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
+ Dispatch<Source> dispatch = service.createDispatch(
+ QNAME_PORT, Source.class, Mode.PAYLOAD);
+
+ // Create the Source object with the payload contents. Since
+ // we're in PAYLOAD mode, we don't have to worry about the envelope.
+ byte[] bytes = sampleRequest.getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ StreamSource request = new StreamSource(bais);
+
+ // Send the SOAP 1.2 request
+ Source response = dispatch.invoke(request);
+
+ assertTrue("The response was null. We expected content to be returned.", response != null);
+
+ // Convert the response to a more consumable format
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer trans = factory.newTransformer();
+ trans.transform(response, result);
+
+ // Check to make sure the contents are correct. Again, since we're
+ // in PAYLOAD mode, we shouldn't have anything related to the envelope
+ // in the return, just the contents of the Body.
+ String responseText = baos.toString();
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+ }
+
+ /**
+ * Test sending a SOAP 1.2 request in PAYLOAD mode using SOAP/JMS
+ */
+ public void testSOAP12JMSDispatchPayloadMode() throws Exception {
+ // Create the JAX-WS client needed to send the request
+ Service service = Service.create(QNAME_SERVICE);
+ service.addPort(QNAME_PORT, MDQConstants.SOAP12JMS_BINDING, URL_ENDPOINT);
+ Dispatch<Source> dispatch = service.createDispatch(
+ QNAME_PORT, Source.class, Mode.PAYLOAD);
+
+ // Create the Source object with the payload contents. Since
+ // we're in PAYLOAD mode, we don't have to worry about the envelope.
+ byte[] bytes = sampleRequest.getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ StreamSource request = new StreamSource(bais);
+
+ // Send the SOAP 1.2 request
+ Source response = dispatch.invoke(request);
+
+ assertTrue("The response was null. We expected content to be returned.", response != null);
+
+ // Convert the response to a more consumable format
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer trans = factory.newTransformer();
+ trans.transform(response, result);
+
+ // Check to make sure the contents are correct. Again, since we're
+ // in PAYLOAD mode, we shouldn't have anything related to the envelope
+ // in the return, just the contents of the Body.
+ String responseText = baos.toString();
+ assertTrue(!responseText.contains("soap"));
+ assertTrue(!responseText.contains("Envelope"));
+ assertTrue(!responseText.contains("Body"));
+ assertTrue(responseText.contains("echoStringResponse"));
+
+ }
+
+
+ /**
+ * Test sending a SOAP 1.2 request in MESSAGE mode
+ */
+ public void testSOAP12DispatchMessageMode() throws Exception {
+ // Create the JAX-WS client needed to send the request
+ Service service = Service.create(QNAME_SERVICE);
+ service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
+ Dispatch<Source> dispatch = service.createDispatch(
+ QNAME_PORT, Source.class, Mode.MESSAGE);
+
+ // Create the Source object with the message contents. Since
+ // we're in MESSAGE mode, we'll need to make sure we create this
+ // with the right protocol.
+ byte[] bytes = sampleEnvelope.getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ StreamSource request = new StreamSource(bais);
+
+ Source response = dispatch.invoke(request);
+
+ // Convert the response to a more consumable format
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer trans = factory.newTransformer();
+ trans.transform(response, result);
+
+ // Check to make sure the contents of the message are correct
+ String responseText = baos.toString();
+ assertTrue(responseText.contains("soap"));
+ assertTrue(responseText.contains("Body"));
+ assertTrue(responseText.contains("Envelope"));
+ assertTrue(responseText.contains("echoStringResponse"));
+
+ // Check to make sure the message returned had the right protocol version
+ // TODO: Need to determine whether or not we should be using the hard
+ // coded URLs here, or whether we should be using a constant for the
+ // purposes of the test.
+ assertTrue(responseText.contains("http://www.w3.org/2003/05/soap-envelope"));
+ assertTrue(!responseText.contains("http://schemas.xmlsoap.org/soap/envelope"));
+ }
+
+ /**
+ * Test sending a SOAP 1.2 request in MESSAGE mode
+ */
+ public void testSOAP12DispatchMessageMode_MustUnderstand() throws Exception {
+ // Create the JAX-WS client needed to send the request
+ Service service = Service.create(QNAME_SERVICE);
+ service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
+ Dispatch<Source> dispatch = service.createDispatch(
+ QNAME_PORT, Source.class, Mode.MESSAGE);
+
+ // Create the Source object with the message contents. Since
+ // we're in MESSAGE mode, we'll need to make sure we create this
+ // with the right protocol.
+ byte[] bytes = sampleEnvelope_MustUnderstand.getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ StreamSource request = new StreamSource(bais);
+
+ SOAPFaultException e = null;
+ try {
+ Source response = dispatch.invoke(request);
+ } catch (SOAPFaultException ex) {
+ e = ex;
+ }
+
+ assertNotNull("We should have an exception, but none was thrown.", e);
+ assertEquals("FaultCode should be \"MustUnderstand\"", "MustUnderstand", e.getFault().getFaultCodeAsQName().getLocalPart());
+
+
+ }
+}
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAPMessageDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAPMessageDispatch.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAPMessageDispatch.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/dispatch/SOAPMessageDispatch.java Mon Mar 3 10:47:38 2008
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.dispatch;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.concurrent.Future;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+
+import junit.framework.TestCase;
+import org.apache.axis2.jaxws.TestLogger;
+
+public class SOAPMessageDispatch extends TestCase {
+ private String url = "http://localhost:6060/axis2/services/ProxyDocLitWrappedService.DocLitWrappedProxyImplPort";
+ private QName serviceName = new QName(
+ "http://org.apache.axis2.proxy.doclitwrapped", "ProxyDocLitWrappedService");
+ private QName portName = new QName("http://org.apache.axis2.proxy.doclitwrapped",
+ "ProxyDocLitWrappedPort");
+
+ String messageResource = "test-resources" + File.separator + "xml" + File.separator +"soapmessage.xml";
+
+ public void testSOAPMessageSyncMessageMode() throws Exception {
+
+ String basedir = new File(System.getProperty("basedir",".")).getAbsolutePath();
+ String messageResource = new File(basedir, this.messageResource).getAbsolutePath();
+
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+ //Initialize the JAX-WS client artifacts
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, url);
+ Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+
+ //Create SOAPMessage Object no attachments here.
+ FileInputStream inputStream = new FileInputStream(messageResource);
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage msgObject = factory.createMessage(null, inputStream);
+
+ //Invoke the Dispatch
+ TestLogger.logger.debug(">> Invoking Async Dispatch");
+ SOAPMessage response = dispatch.invoke(msgObject);
+
+ assertNotNull("dispatch invoke returned null", response);
+ response.writeTo(System.out);
+ }
+
+ public void testSOAPMessageAsyncCallbackMessageMode() throws Exception {
+
+ String basedir = new File(System.getProperty("basedir",".")).getAbsolutePath();
+ String messageResource = new File(basedir, this.messageResource).getAbsolutePath();
+
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+ //Initialize the JAX-WS client artifacts
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, url);
+ Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+
+ //Create SOAPMessage Object no attachments here.
+ FileInputStream inputStream = new FileInputStream(messageResource);
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage msgObject = factory.createMessage(null, inputStream);
+
+ AsyncCallback<SOAPMessage> ac = new AsyncCallback<SOAPMessage>();
+ //Invoke the Dispatch
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(msgObject, ac);
+
+ assertNotNull("dispatch invokeAsync returned null Future<?>", monitor);
+ while (!monitor.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ SOAPMessage response = ac.getValue();
+ assertNotNull("dispatch invoke returned null", response);
+ response.writeTo(System.out);
+ }
+
+ public void testSOAPMessageAsyncPollingMessageMode() throws Exception {
+
+ String basedir = new File(System.getProperty("basedir",".")).getAbsolutePath();
+ String messageResource = new File(basedir, this.messageResource).getAbsolutePath();
+
+ TestLogger.logger.debug("---------------------------------------");
+ TestLogger.logger.debug("test: " + getName());
+ //Initialize the JAX-WS client artifacts
+ Service svc = Service.create(serviceName);
+ svc.addPort(portName, null, url);
+ Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+
+ //Create SOAPMessage Object no attachments here.
+ FileInputStream inputStream = new FileInputStream(messageResource);
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage msgObject = factory.createMessage(null, inputStream);
+
+ //Invoke the Dispatch
+ TestLogger.logger.debug(">> Invoking sync Dispatch");
+ Response<SOAPMessage> asyncResponse = dispatch.invokeAsync(msgObject);
+
+ assertNotNull("dispatch invokeAsync returned null Response", asyncResponse);
+ while (!asyncResponse.isDone()) {
+ TestLogger.logger.debug(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+
+ SOAPMessage response = asyncResponse.get();
+ assertNotNull("dispatch invoke returned null", response);
+ response.writeTo(System.out);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org