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 na...@apache.org on 2006/07/26 15:07:25 UTC
svn commit: r425727 [2/3] - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/client/
src/org/apache/axis2/jaxws/client/proxy/ src/org/apache/axis2/jaxws/core/
src/org/apache/axis2/jaxws/core/control...
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Wed Jul 26 06:07:23 2006
@@ -17,67 +17,51 @@
package org.apache.axis2.jaxws.core.controller;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
+import javax.xml.namespace.QName;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
-import javax.xml.ws.WebServiceException;
-import javax.xml.ws.Service.Mode;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.jaxws.AxisCallback;
import org.apache.axis2.jaxws.BindingProvider;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.core.InvocationContext;
import org.apache.axis2.jaxws.core.MessageContext;
-import org.apache.axis2.jaxws.impl.AsyncListenerWrapper;
import org.apache.axis2.jaxws.impl.AsyncListener;
+import org.apache.axis2.jaxws.impl.AsyncListenerWrapper;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
import org.apache.axis2.jaxws.util.Constants;
+import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * The <tt>AxisInvocationController</tt> is a stateless entity used to
- * invoke the Axis2 client APIs. All of the information that the
- * AxisInvocationController needs should exist within the InvocatonContext
- * that is passed in.
- *
- * The request information is passed in within the InvocationContext. The
- * AxisInvocationController assumes that there is a MessageContext within that
- * InvocationContext that is populated with all of the information that it
- * needs to invoke. If not, an error will be returned. Once the response
- * comes back, the information for that response will be held inside of the
- * MessageContext representing the response, that exists in the
- * InvocationContext.
- *
- * The AxisInvocationController supports four different invocation patterns:
- *
- * 1) synchronous - This is represented by the {@link #invoke(InvocationContext)}
- * method. This is a blocking call to the Axis2 client.
+ * The <tt>AxisInvocationController</tt> is an implementation of the
+ * {@link org.apache.axis2.jaxws.core.controller.InvocationController}
+ * interface. This implemenation uses the Axis2 engine to drive the
+ * request to the target service.
*
- * 2) one-way - This is represented by the {@link #invokeOneWay(InvocationContext)}
- * method. This is a one-way invocation that only returns errors related
- * to sending the message. If an error occurs while processing, the client
- * will not be notified.
- *
- * 3) asynchronous (callback) - {@link #invokeAsync(InvocationContext, AsyncHandler)}
- *
- * 4) asynchronous (polling) - {@link #invokeAsync(InvocationContext)}
+ * For more information on how to invoke this class, please see the
+ * InvocationController interface comments.
*/
public class AxisInvocationController implements InvocationController {
private static Log log = LogFactory.getLog(AxisInvocationController.class);
- /**
- * Performs a synchronous (blocking) invocation of the client.
- *
- * @param ic
- * @return
+ /*
+ * (non-Javadoc)
+ * @see org.apache.axis2.jaxws.core.controller.InvocationController#invoke(org.apache.axis2.jaxws.core.InvocationContext)
*/
public InvocationContext invoke(InvocationContext ic) {
if (log.isDebugEnabled()) {
@@ -93,46 +77,83 @@
throw ExceptionFactory.makeWebServiceException("Cannot invoke; request MessageContext was null");
}
- // Setup the MessageContext for the response
+ // Get the request MessageContext
MessageContext requestMsgCtx = ic.getRequestMessageContext();
- MessageContext responseMsgCtx = new MessageContext();
- ic.setResponseMessageContext(responseMsgCtx);
+ MessageContext responseMsgCtx = null;
+
+ // We need the qname of the operation being invoked to know which
+ // AxisOperation the OperationClient should be based on.
+ // TODO: Need to get the operation qname from the MessageContext
+ QName operationName = ServiceClient.ANON_OUT_IN_OP;
+
+ // TODO: Will the ServiceClient stick around on the InvocationContext
+ // or will we need some other mechanism of creating this?
+ // Try to create an OperationClient from the passed in ServiceClient
+ ServiceClient svcClient = ic.getServiceClient();
+ OperationClient opClient = createOperationClient(svcClient, operationName);
- ServiceClient client = ic.getServiceClient();
- if (client != null) {
+ if (opClient != null) {
// Get the target endpoint address and setup the TO endpoint
// reference. This tells us where the request is going.
String targetUrl = (String) requestMsgCtx.getProperties().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
EndpointReference toEPR = new EndpointReference(targetUrl);
- client.getOptions().setTo(toEPR);
+ opClient.getOptions().setTo(toEPR);
// Get the SOAP Action (if needed)
- String soapAction = getSOAPAction(requestMsgCtx);
- client.getOptions().setAction(soapAction);
+ String soapAction = configureSOAPAction(requestMsgCtx);
+ opClient.getOptions().setAction(soapAction);
- // Use the ServiceClient to send the request.
- OMElement rspEnvelope = null;
+ // Use the OperationClient to send the request and put the contents
+ // of the response in the response MessageContext.
try {
- OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
- rspEnvelope = client.sendReceive(ServiceClient.ANON_OUT_IN_OP, reqEnvelope);
+ // The MessageContext will contain a Message object with the
+ // contents that need to be sent. We need to get those contents
+ // in a form that Axis2 can consume them, an AXIOM SOAPEnvelope.
+ Message requestMsg = requestMsgCtx.getMessage();
+ SOAPEnvelope requestOM = (SOAPEnvelope) requestMsg.getAsOMElement();
+
+ org.apache.axis2.context.MessageContext axisRequestMsgCtx =
+ requestMsgCtx.getAxisMessageContext();
+ axisRequestMsgCtx.setEnvelope(requestOM);
+
+ // Setting the ServiceContext will create the association between
+ // the OperationClient it's MessageContexts and the
+ // AxisService/AxisOperation that they are tied to.
+ axisRequestMsgCtx.setServiceContext(svcClient.getServiceContext());
+
+ // Set the Axis2 request MessageContext
+ opClient.addMessageContext(axisRequestMsgCtx);
+ opClient.execute(true);
+
+ // Collect the response MessageContext and envelope
+ org.apache.axis2.context.MessageContext axisResponseMsgCtx =
+ opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+
+ SOAPEnvelope rspEnvelope = axisResponseMsgCtx.getEnvelope();
+ Message responseMsg = null;
+ if (rspEnvelope != null) {
+ responseMsg = createMessageFromOM(rspEnvelope);
+ }
+
+ // Setup the response MessageContext
+ responseMsgCtx = new MessageContext(axisResponseMsgCtx);
+ responseMsgCtx.setMessage(responseMsg);
} catch (AxisFault e) {
throw ExceptionFactory.makeWebServiceException(e);
+ } catch (MessageException e) {
+ throw ExceptionFactory.makeWebServiceException(e);
}
- // Set the response message on the response MessageContext
- responseMsgCtx.setMessageAsOM(rspEnvelope);
+ // Set the response MessageContext on the InvocationContext
+ ic.setResponseMessageContext(responseMsgCtx);
}
return ic;
}
- /**
- * Performs a one-way invocation of the client. This is NOT a robust
- * invocation, so any fault that occurs during the processing of the request
- * will not be returned to the client. Errors returned to the client are
- * problems that occurred during the sending of the message to the server.
- *
- * @param ic
+ /*
+ * (non-Javadoc)
+ * @see org.apache.axis2.jaxws.core.controller.InvocationController#invokeOneWay(org.apache.axis2.jaxws.core.InvocationContext)
*/
public void invokeOneWay(InvocationContext ic) {
if (log.isDebugEnabled()) {
@@ -157,39 +178,54 @@
MessageContext responseMsgCtx = new MessageContext();
ic.setResponseMessageContext(responseMsgCtx);
- ServiceClient client = ic.getServiceClient();
- if (client != null) {
+ // Try to create an OperationClient from the passed in ServiceClient
+ ServiceClient svcClient = ic.getServiceClient();
+ OperationClient opClient = createOperationClient(svcClient, ServiceClient.ANON_OUT_ONLY_OP);
+
+ if (opClient != null) {
// Get the target endpoint address and setup the TO endpoint
// reference. This tells us where the request is going.
String targetUrl = (String) requestMsgCtx.getProperties().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
EndpointReference toEPR = new EndpointReference(targetUrl);
- client.getOptions().setTo(toEPR);
+ opClient.getOptions().setTo(toEPR);
// Get the SOAP Action (if needed)
- String soapAction = getSOAPAction(requestMsgCtx);
- client.getOptions().setAction(soapAction);
+ String soapAction = configureSOAPAction(requestMsgCtx);
+ opClient.getOptions().setAction(soapAction);
- // Use the ServiceClient to send the request.
+ // Use the OperationClient to send the request.
+ Message responseMsg = null;
+ org.apache.axis2.context.MessageContext axisResponseMsgCtx = null;
try {
- OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
- client.fireAndForget(ServiceClient.ANON_OUT_ONLY_OP, reqEnvelope);
+ // We need to prepare the contents of the Message from the request
+ // MessageContext to be sent
+ Message requestMsg = requestMsgCtx.getMessage();
+ SOAPEnvelope requestOM = (SOAPEnvelope) requestMsg.getAsOMElement();
+
+ org.apache.axis2.context.MessageContext axisRequestMsgCtx =
+ requestMsgCtx.getAxisMessageContext();
+
+ axisRequestMsgCtx.setEnvelope(requestOM);
+
+ // Setting the ServiceContext will create the association between
+ // the OperationClient it's MessageContexts and the
+ // AxisService/AxisOperation that they are tied to.
+ axisRequestMsgCtx.setServiceContext(svcClient.getServiceContext());
+ opClient.addMessageContext(axisRequestMsgCtx);
+ opClient.execute(true);
} catch (AxisFault e) {
throw ExceptionFactory.makeWebServiceException(e);
+ } catch (MessageException e) {
+ throw ExceptionFactory.makeWebServiceException(e);
}
}
return;
}
- /**
- * Performs an asynchronous (non-blocking) invocation of the client based
- * on a callback model. The AsyncHandler that is passed in is the callback
- * that the client programmer supplied when they invoked their JAX-WS
- * Dispatch or their SEI-based dynamic proxy.
- *
- * @param ic
- * @param callback
- * @return
+ /*
+ * (non-Javadoc)
+ * @see org.apache.axis2.jaxws.core.controller.InvocationController#invokeAsync(org.apache.axis2.jaxws.core.InvocationContext, javax.xml.ws.AsyncHandler)
*/
public Future<?> invokeAsync(InvocationContext ic, AsyncHandler callback) {
if (log.isDebugEnabled()) {
@@ -207,29 +243,29 @@
// Setup the MessageContext for the response
MessageContext requestMsgCtx = ic.getRequestMessageContext();
- MessageContext responseMsgCtx = new MessageContext();
- ic.setResponseMessageContext(responseMsgCtx);
- ServiceClient client = ic.getServiceClient();
- if (client != null) {
+ ServiceClient svcClient = ic.getServiceClient();
+ OperationClient opClient = createOperationClient(svcClient, ServiceClient.ANON_OUT_IN_OP);
+
+ if (opClient != null) {
// Get the target endpoint address and setup the TO endpoint
// reference. This tells us where the request is going.
String targetUrl = (String) requestMsgCtx.getProperties().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
EndpointReference toEPR = new EndpointReference(targetUrl);
- client.getOptions().setTo(toEPR);
+ opClient.getOptions().setTo(toEPR);
// Get the SOAP Action (if needed)
- String soapAction = getSOAPAction(requestMsgCtx);
- client.getOptions().setAction(soapAction);
+ String soapAction = configureSOAPAction(requestMsgCtx);
+ opClient.getOptions().setAction(soapAction);
// Setup the client so that it knows whether the underlying call to
// Axis2 knows whether or not to start a listening port for an
// asynchronous response.
Boolean useAsyncMep = (Boolean) requestMsgCtx.getProperties().get(Constants.USE_ASYNC_MEP);
if((useAsyncMep != null && useAsyncMep.booleanValue())
- || client.getOptions().isUseSeparateListener()) {
- client.getOptions().setUseSeparateListener(true);
- client.getOptions().setTransportInProtocol("http");
+ || opClient.getOptions().isUseSeparateListener()) {
+ opClient.getOptions().setUseSeparateListener(true);
+ opClient.getOptions().setTransportInProtocol("http");
}
// There should be an AsyncListener that is configured and set on the
@@ -240,6 +276,7 @@
AsyncListener listener = ic.getAsyncListener();
AxisCallback axisCallback = new AxisCallback();
listener.setAxisCallback(axisCallback);
+ listener.setInvocationContext(ic);
// Once the AsyncListener is configured, we must include that in an
// AsyncListenerWrapper. The wrapper is what will handle the lifecycle
@@ -257,13 +294,28 @@
throw ExceptionFactory.makeWebServiceException("Cannot call asynchronous invoke with null callback");
}
- // Get the request message from the MessageContext and send it
- // using the ServiceClient API.
- OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
try {
- client.sendReceiveNonBlocking(ServiceClient.ANON_OUT_IN_OP, reqEnvelope, axisCallback);
+ // Get the request message from the MessageContext and send it
+ // using the OperationClient API.
+ Message requestMsg = requestMsgCtx.getMessage();
+ SOAPEnvelope requestOM = (SOAPEnvelope) requestMsg.getAsOMElement();
+
+ // The envelope must be set on the Axis2 MessageContext as a
+ // OM-based SOAPEnvelope
+ org.apache.axis2.context.MessageContext axisRequestMsgCtx =
+ requestMsgCtx.getAxisMessageContext();
+ axisRequestMsgCtx.setEnvelope(requestOM);
+
+ // Setting the ServiceContext will create the association between
+ // the OperationClient it's MessageContexts and the
+ // AxisService/AxisOperation that they are tied to.
+ axisRequestMsgCtx.setServiceContext(svcClient.getServiceContext());
+ opClient.addMessageContext(axisRequestMsgCtx);
+ opClient.setCallback(axisCallback);
+ opClient.execute(false);
} catch (AxisFault e) {
- e.printStackTrace();
+ throw ExceptionFactory.makeWebServiceException(e);
+ } catch (MessageException e) {
throw ExceptionFactory.makeWebServiceException(e);
}
@@ -290,63 +342,40 @@
return wrapper;
}
-
+
return null;
}
- /**
- * Performs an asynchronous (non-blocking) invocation of the client based
- * on a polling model. The Response object that is returned allows the
- * client programmer to poll against it to see if a response has been sent
- * back by the server.
- *
- * @param ic
- * @return
+ /*
+ * (non-Javadoc)
+ * @see org.apache.axis2.jaxws.core.controller.InvocationController#invokeAsync(org.apache.axis2.jaxws.core.InvocationContext)
*/
public Response invokeAsync(InvocationContext ic) {
if (log.isDebugEnabled()) {
log.debug("Invocation pattern: async (polling)");
}
- return null;
+
+ throw ExceptionFactory.makeWebServiceException("Aysnchronous polling invocations are not supported yet.");
}
/**
- * Creates the OperationClient instance that will be invoked upon.
+ * Returns the SOAPAction that should be used for the invocation. This
+ * method will get the information from the MessageContext passed in
+ * either from :
*
- * This will be used instead of the ServiceClient as we mature the
- * AxisInvocationController
+ * a) the JAX-WS properties available on the MessageContext or
+ * b) the WSDL configuration information available from the MessageContext
+ *
+ * @param ctx
+ * @return
*/
- /*
- private OperationClient createOperationClient(MessageContext mc) {
- OperationClient client = null;
- String operationName = mc.getOperationName();
-
- if (operationName != null) {
- AxisService service = mc.getMetadata();
- AxisOperation operation = service.getOperation(new QName(operationName));
-
- if (operation == null) {
- throw ExceptionFactory.makeWebServiceException("Operation not found.");
- }
-
- try {
- ServiceContext ctx = new ServiceContext(service, );
- client = operation.createClient(ctx, null);
- client.addMessageContext(null);
- }
- catch (AxisFault af) {
- throw new WebServiceException(af);
- }
- }
- else {
- throw ExceptionFactory.makeWebServiceException("Operation name not set.");
- }
+ private String configureSOAPAction(MessageContext ctx) {
+ //TODO: Need to get SOAPAction information from the WSDL config
- return client;
- }
- */
-
- private String getSOAPAction(MessageContext ctx){
+ //TODO: Need to determine what the story is with using the SOAPAction
+ // declared in the WSDL. If the property says not to use it, but it's
+ // listed in the WSDL, do we still include it? Do we include it if
+ // the property is not even set?
Boolean useSoapAction = (Boolean) ctx.getProperties().get(BindingProvider.SOAPACTION_USE_PROPERTY);
if(useSoapAction != null && useSoapAction.booleanValue()){
return (String) ctx.getProperties().get(BindingProvider.SOAPACTION_URI_PROPERTY);
@@ -354,4 +383,43 @@
return null;
}
-}
+
+ /**
+ * Use the provided ServiceClient instance to create an OperationClient identified
+ * by the operation QName provided.
+ *
+ * @param sc
+ * @param operation
+ * @return
+ */
+ private OperationClient createOperationClient(ServiceClient sc, QName operation) {
+ if (sc == null) {
+ throw ExceptionFactory.makeWebServiceException("Cannot create OperationClient, ServiceClient was null");
+ }
+ if (operation == null) {
+ throw ExceptionFactory.makeWebServiceException("Cannot create OperationClient, QName was null");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Creating OperationClient for operation: " + operation);
+ }
+
+ try {
+ OperationClient client = sc.createClient(ServiceClient.ANON_OUT_IN_OP);
+ return client;
+ } catch (AxisFault e) {
+ //TODO: NLS and ExceptionFactory
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
+
+ private Message createMessageFromOM(OMElement om) throws MessageException {
+ try {
+ MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = mf.createFrom(om);
+ return msg;
+ } catch (Exception e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java Wed Jul 26 06:07:23 2006
@@ -1,19 +1,101 @@
-package org.apache.axis2.jaxws.core.controller;
-
-import java.util.concurrent.Future;
-
-import javax.xml.ws.AsyncHandler;
-import javax.xml.ws.Response;
-
-import org.apache.axis2.jaxws.core.InvocationContext;
-
-public interface InvocationController {
-
- public InvocationContext invoke(InvocationContext ic);
-
- public void invokeOneWay(InvocationContext ic);
-
- public Response invokeAsync(InvocationContext ic);
-
- public Future<?> invokeAsync(InvocationContext ic, AsyncHandler asyncHandler);
-}
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.core.controller;
+
+import java.util.concurrent.Future;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.apache.axis2.jaxws.core.InvocationContext;
+
+/**
+ * The <tt>InvocationController</tt> is an interface for an entity used to
+ * invoke a target web service. All of the information that the
+ * InvocationController needs should exist within the InvocatonContext
+ * that is passed in to the various invoke methods.
+ *
+ * The request information is passed in within the InvocationContext. The
+ * InvocationController assumes that there is a MessageContext within that
+ * InvocationContext that is populated with all of the information that it
+ * needs to invoke. If not, an error will be returned. Once the response
+ * comes back, the information for that response will be held inside of the
+ * MessageContext representing the response, that exists in the
+ * InvocationContext.
+ *
+ * The InvocationController supports four different invocation patterns:
+ *
+ * 1) synchronous - This is represented by the {@link #invoke(InvocationContext)}
+ * method. This is a blocking, request/response call to the web service.
+ *
+ * 2) one-way - This is represented by the {@link #invokeOneWay(InvocationContext)}
+ * method. This is a one-way invocation that only returns errors related
+ * to sending the message. If an error occurs while processing, the client
+ * will not be notified.
+ *
+ * 3) asynchronous (callback) - {@link #invokeAsync(InvocationContext, AsyncHandler)}
+ *
+ * 4) asynchronous (polling) - {@link #invokeAsync(InvocationContext)}
+ */
+public interface InvocationController {
+
+ /**
+ * Performs a synchronous (blocking) invocation of a target service. The
+ * InvocationContext passed in should contain a valid MessageContext
+ * containing the properties and message to be sent for the request. The
+ * response contents will be processed and placed in the InvocationContext
+ * as well.
+ *
+ * @param ic
+ * @return
+ */
+ public InvocationContext invoke(InvocationContext ic);
+
+ /**
+ * Performs a one-way invocation of the client. This is SHOULD NOT be a
+ * robust invocation, so any fault that occurs during the processing of
+ * the request will not be returned to the client. Errors returned to the
+ * client are problems that occurred during the sending of the message to
+ * the server.
+ *
+ * @param ic
+ */
+ public void invokeOneWay(InvocationContext ic);
+
+ /**
+ * Performs an asynchronous (non-blocking) invocation of the client based
+ * on a callback model. The AsyncHandler that is passed in is the callback
+ * that the client programmer supplied when they invoked their JAX-WS
+ * Dispatch or their SEI-based dynamic proxy.
+ *
+ * @param ic
+ * @param callback
+ * @return
+ */
+ public Response invokeAsync(InvocationContext ic);
+
+ /**
+ * Performs an asynchronous (non-blocking) invocation of the client based
+ * on a polling model. The Response object that is returned allows the
+ * client programmer to poll against it to see if a response has been sent
+ * back by the server.
+ *
+ * @param ic
+ * @return
+ */
+ public Future<?> invokeAsync(InvocationContext ic, AsyncHandler asyncHandler);
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java Wed Jul 26 06:07:23 2006
@@ -28,7 +28,7 @@
JSR-181 Annotations:
@WebService Note this can be specified on the endpoint Impl without an SEI
-- name itÂ’s the PortType Class Name, one you get with getPort() call in Service Delegate [NT]
+- name its the PortType Class Name, one you get with getPort() call in Service Delegate [NT]
- targetNamespace
- serviceName default is portType+Service. Should we use this if Service.create call does not provide/have ServiceQname?[NT]
- wsdlLocation if no wsdl location provided the read this annotation. Should this override what is client sets?[NT]
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java Wed Jul 26 06:07:23 2006
@@ -22,7 +22,11 @@
import org.apache.axiom.om.OMElement;
import org.apache.axis2.jaxws.AxisCallback;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.core.InvocationContext;
import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.MessageException;
/**
@@ -38,6 +42,7 @@
protected AxisCallback axisCallback;
protected Mode mode;
+ protected InvocationContext invocationCtx;
public AsyncListener() {
//do nothing
@@ -51,6 +56,10 @@
axisCallback = cb;
}
+ public void setInvocationContext(InvocationContext ic) {
+ invocationCtx = ic;
+ }
+
//TODO: This will probably be removed or at least made a little more
//clear since it's only the Dispatch that's concerned with the mode.
public void setMode(Mode m) {
@@ -68,6 +77,7 @@
}
MessageContext responseMsgCtx = axisCallback.getResponseMessageContext();
+
Object responseObj = getResponseValueObject(responseMsgCtx);
return responseObj;
}
@@ -85,7 +95,12 @@
* @param msg
*/
protected Object getResponseValueObject(MessageContext mc) {
- OMElement msg = mc.getMessageAsOM();
- return msg.toString();
+ try {
+ Message msg = mc.getMessage();
+ OMElement om = msg.getAsOMElement();
+ return om.toString();
+ } catch (MessageException e) {
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/JAXBParameter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/JAXBParameter.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/JAXBParameter.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/param/JAXBParameter.java Wed Jul 26 06:07:23 2006
@@ -1,158 +1,161 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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.param;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.ws.WebServiceException;
-import javax.xml.ws.Service.Mode;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.soap.SOAPEnvelope;
-
-/**
- * Parameter implementation for JAX-B objects. *
- */
-public class JAXBParameter implements Parameter {
-
- private Object value;
- private JAXBContext context;
- private Marshaller marshaller;
- private Unmarshaller unmarshaller;
-
- public JAXBParameter() {}
-
- public JAXBParameter(Object value){
- this.value = value;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object o) {
- value = o;
- }
-
- public JAXBContext getJAXBContext() {
- return context;
- }
-
- public void setJAXBContext(JAXBContext ctx) {
- context = ctx;
- }
-
- public XMLStreamReader getValueAsStreamReader() {
- createMarshaller();
-
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaller.marshal(value, baos);
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
- return reader;
- } catch (Exception e) {
- //TODO: Add proper error handling
- e.printStackTrace();
- }
-
- return null;
- }
-
- public OMElement toOMElement() {
- try {
- StAXOMBuilder builder = new StAXOMBuilder(
- OMAbstractFactory.getOMFactory(),
- getValueAsStreamReader());
- OMElement documentElement = builder.getDocumentElement();
- return documentElement;
- } catch (Exception e) {
- //TODO: Add proper error handling
- e.printStackTrace();
- }
-
- return null;
- }
-
- public void fromOM(OMElement omElement) {
- createUnmarshaller();
-
- try {
- ByteArrayInputStream bais = new ByteArrayInputStream(omElement.toString().getBytes());
- value = unmarshaller.unmarshal(bais);
-
- } catch (JAXBException e) {
- e.printStackTrace();
- }
- }
-
- public SOAPEnvelope toEnvelope(Mode mode,String soapVersionURI) {
- return ParameterUtils.toEnvelope(mode, soapVersionURI, this);
- }
-
- public void fromEnvelope(Mode mode, SOAPEnvelope env) {
- ParameterUtils.fromEnvelope(mode, env, this);
- }
-
- /*
- * Setup the Marshaller for serialization
- */
- private void createMarshaller() {
- if (context != null) {
- try {
- marshaller = context.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
-
- } catch (JAXBException e) {
- throw new WebServiceException("Error creating Marshaller from JAXBContext");
- }
- }
- else {
- throw new WebServiceException("Cannot create Marshaller from null JAXBContext");
- }
- }
-
- /*
- * Setup the Unmarshaller for deserialization
- */
- private void createUnmarshaller() {
- if (unmarshaller != null)
- return;
-
- if (context != null) {
- try {
- unmarshaller = context.createUnmarshaller();
- } catch (JAXBException e) {
- throw new WebServiceException("Error creating Unmarshaller from JAXBContext");
- }
- }
- else {
- throw new WebServiceException("Cannot create Unmarshaller from null JAXBContext");
- }
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.param;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.Service.Mode;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.soap.SOAPEnvelope;
+
+/**
+ * Parameter implementation for JAX-B objects. *
+ */
+public class JAXBParameter implements Parameter {
+
+ private Object value;
+ private JAXBContext context;
+ private Marshaller marshaller;
+ private Unmarshaller unmarshaller;
+
+ public JAXBParameter() {}
+
+ public JAXBParameter(Object value){
+ this.value = value;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object o) {
+ value = o;
+ }
+
+ public JAXBContext getJAXBContext() {
+ return context;
+ }
+
+ public void setJAXBContext(JAXBContext ctx) {
+ context = ctx;
+ }
+
+ public XMLStreamReader getValueAsStreamReader() {
+ createMarshaller();
+
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ marshaller.marshal(value, baos);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
+ return reader;
+ } catch (Exception e) {
+ //TODO: Add proper error handling
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public OMElement toOMElement() {
+ try {
+ StAXOMBuilder builder = new StAXOMBuilder(
+ OMAbstractFactory.getOMFactory(),
+ getValueAsStreamReader());
+ OMElement documentElement = builder.getDocumentElement();
+ return documentElement;
+ } catch (Exception e) {
+ //TODO: Add proper error handling
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public void fromOM(OMElement omElement) {
+ createUnmarshaller();
+
+ String omString = omElement.toString();
+ System.out.println(">> [OMSTRING] " + omString);
+
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(omString.getBytes());
+ value = unmarshaller.unmarshal(bais);
+
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public SOAPEnvelope toEnvelope(Mode mode,String soapVersionURI) {
+ return ParameterUtils.toEnvelope(mode, soapVersionURI, this);
+ }
+
+ public void fromEnvelope(Mode mode, SOAPEnvelope env) {
+ ParameterUtils.fromEnvelope(mode, env, this);
+ }
+
+ /*
+ * Setup the Marshaller for serialization
+ */
+ private void createMarshaller() {
+ if (context != null) {
+ try {
+ marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+
+ } catch (JAXBException e) {
+ throw new WebServiceException("Error creating Marshaller from JAXBContext");
+ }
+ }
+ else {
+ throw new WebServiceException("Cannot create Marshaller from null JAXBContext");
+ }
+ }
+
+ /*
+ * Setup the Unmarshaller for deserialization
+ */
+ private void createUnmarshaller() {
+ if (unmarshaller != null)
+ return;
+
+ if (context != null) {
+ try {
+ unmarshaller = context.createUnmarshaller();
+ } catch (JAXBException e) {
+ throw new WebServiceException("Error creating Unmarshaller from JAXBContext");
+ }
+ }
+ else {
+ throw new WebServiceException("Cannot create Unmarshaller from null JAXBContext");
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/CallbackHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/CallbackHandler.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/CallbackHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/CallbackHandler.java Wed Jul 26 06:07:23 2006
@@ -1,79 +1,60 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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;
-
-import java.io.StringWriter;
-
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.ws.AsyncHandler;
-import javax.xml.ws.Response;
-
-public class CallbackHandler<T> implements AsyncHandler <T> {
-
- public void handleResponse(Response response) {
- System.out.println(">> Processing async reponse");
- try{
- T res = (T) response.get();
-
- if(res instanceof String){
- System.out.println("Response [" + res + "]");
- }
- else if(res instanceof SAXSource){
-
- SAXSource retVal = (SAXSource)res;
- StringBuffer buffer = new StringBuffer();
- byte b;
- while ((b = (byte) retVal.getInputSource().getByteStream().read()) != -1) {
- char c = (char) b;
- buffer.append(c);
-
- }
- System.out.println(">> Response [" + buffer + "]");
- }
- else if(res instanceof StreamSource){
- StreamSource retVal = (StreamSource) res;
-
- byte b;
- StringBuffer buffer = new StringBuffer();
- while ((b = (byte) retVal.getInputStream().read()) != -1) {
- char c = (char) b;
- buffer.append(c);
-
- }
- System.out.println(">> Response [" + buffer + "]");
- }
- else if(res instanceof DOMSource){
- DOMSource retVal = (DOMSource) res;
-
- StringWriter writer = new StringWriter();
- Transformer trasformer = TransformerFactory.newInstance().newTransformer();
- Result result = new StreamResult(writer);
- trasformer.transform(retVal, result);
- StringBuffer buffer = writer.getBuffer();
- System.out.println(">> Response [" + buffer + "]");
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+
+public class CallbackHandler<T> implements AsyncHandler <T> {
+
+ public void handleResponse(Response response) {
+ System.out.println(">> Processing async reponse");
+ try{
+ T res = (T) response.get();
+
+ if(res instanceof String){
+ System.out.println("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();
+
+ System.out.println(responseText);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DOMSourceDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DOMSourceDispatch.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DOMSourceDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DOMSourceDispatch.java Wed Jul 26 06:07:23 2006
@@ -1,246 +1,215 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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;
-
-import java.io.ByteArrayInputStream;
-import java.io.StringWriter;
-import java.util.Map;
-import java.util.concurrent.Future;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
-import javax.xml.ws.Service.Mode;
-
-import junit.framework.TestCase;
-
-import org.apache.axis2.jaxws.CallbackHandler;
-import org.w3c.dom.Document;
-
-public class DOMSourceDispatch extends TestCase{
- private String urlHost = "localhost";
- private String urlPort = "8080";
- private String urlSuffix = "/axis2/services/EchoService";
- private String endpointUrl = "http://" + urlHost + ":" + urlPort + urlSuffix;
- private String soapMessage ="<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns1:echoString xmlns:ns1=\"http://test\"><ns1:input xmlns=\"http://test\">HELLO THERE!!!</ns1:input></ns1:echoString></soap:Body></soap:Envelope>";
- private String xmlString = "<ns1:echoString xmlns:ns1=\"http://test\"><ns1:input xmlns=\"http://test\">HELLO THERE!!!</ns1:input></ns1:echoString>";
- private QName serviceQname = new QName("http://ws.apache.org/axis2", "EchoService");
- private QName portQname = new QName("http://ws.apache.org/axis2", "EchoServiceSOAP11port0");
-
- public void testSync() {
- try {
- System.out.println("---------------------------------------");
- Service svc = Service.create(serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- null);
- ByteArrayInputStream stream = new ByteArrayInputStream(xmlString
- .getBytes());
- Map<String, Object> requestContext = dispatch.getRequestContext();
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- domFactory.setNamespaceAware(true);
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
-
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
- endpointUrl);
- System.out.println(">> Invoking sync Dispatch");
- DOMSource retVal = (DOMSource) dispatch.invoke(srcStream);
-
- assertNotNull("dispatch invoke returned null",retVal);
-
- StringWriter writer = new StringWriter();
- Transformer trasformer = TransformerFactory.newInstance().newTransformer();
- Result result = new StreamResult(writer);
- trasformer.transform(retVal, result);
- System.out.println(">> Response [" + writer.getBuffer().toString() + "]");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- // Not for Alpha
- public void testAsyncPooling() {
-
- }
-
- public void testSyncWithMessageMode(){
- try {
- System.out.println("---------------------------------------");
- Service svc = Service.create(serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- Mode.MESSAGE);
- ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes());
- Map<String, Object> requestContext = dispatch.getRequestContext();
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
-
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
- endpointUrl);
- System.out.println(">> Invoking sync Dispatch with Message Mode");
- DOMSource retVal = (DOMSource) dispatch.invoke(srcStream);
-
- assertNotNull("dispatch invoke returned null",retVal);
-
- StringWriter writer = new StringWriter();
- Transformer trasformer = TransformerFactory.newInstance().newTransformer();
- Result result = new StreamResult(writer);
- trasformer.transform(retVal, result);
- System.out.println(">> Response [" + writer.getBuffer().toString() + "]");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void testAsyncCallbackWithMessageMode() {
- try {
- System.out.println("---------------------------------------");
- CallbackHandler<Source> callbackHandler = new CallbackHandler<Source>();
- Service svc = Service.create(serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- Mode.MESSAGE);
- ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage
- .getBytes());
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
-
- Map<String, Object> requestContext = dispatch.getRequestContext();
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
- endpointUrl);
-
- System.out.println(">> Invoking async (callback) Dispatch");
- Future<?> monitor = dispatch.invokeAsync(srcStream, callbackHandler);
-
- while (!monitor.isDone()) {
- System.out.println(">> Async invocation still not complete");
- Thread.sleep(1000);
- }
-
- //monitor.get();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /*
- public void testSyncWithWSDL() {
- try {
- System.out.println("---------------------------------------");
- URL wsdlUrl = new URL(endpointUrl + "?wsdl");
- Service svc = Service.create(wsdlUrl,serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- Mode.PAYLOAD);
- ByteArrayInputStream stream = new ByteArrayInputStream(xmlString
- .getBytes());
- Map<String, Object> requestContext = dispatch.getRequestContext();
-
- String url = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
- assertNotNull("ERROR: the URL should not be null", url);
-
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
- System.out.println(">> URL from WSDL [" + url + "]");
- System.out.println(">> Invoking sync Dispatch with WSDL, Service and Port");
- DOMSource retVal = (DOMSource) dispatch.invoke(srcStream);
-
- StringWriter writer = new StringWriter();
- Transformer trasformer = TransformerFactory.newInstance().newTransformer();
- Result result = new StreamResult(writer);
- trasformer.transform(retVal, result);
- System.out.println(">> Response [" + writer.getBuffer().toString() + "]");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- */
- public void testAsyncCallback() {
- try{
- System.out.println("---------------------------------------");
- CallbackHandler<Source> callbackHandler = new CallbackHandler<Source>();
- Service svc = Service.create(serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- null);
- ByteArrayInputStream stream = new ByteArrayInputStream(xmlString
- .getBytes());
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
- Map<String, Object> requestContext = dispatch.getRequestContext();
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
- endpointUrl);
-
- System.out.println(">> Invoking async (callback) Dispatch");
- Future<?> monitor = dispatch.invokeAsync(srcStream, callbackHandler);
-
- while (!monitor.isDone()) {
- System.out.println(">> Async invocation still not complete");
- Thread.sleep(1000);
- }
-
- //monitor.get();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void testOneWay() {
- try {
- System.out.println("---------------------------------------");
- Service svc = Service.create(serviceQname);
- svc.addPort(portQname, null, endpointUrl);
- Dispatch<Source> dispatch = svc.createDispatch(portQname, Source.class,
- null);
- ByteArrayInputStream stream = new ByteArrayInputStream(xmlString
- .getBytes());
- Map<String, Object> requestContext = dispatch.getRequestContext();
- DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
- Document domTree = domBuilder.parse(stream);
- DOMSource srcStream = new DOMSource(domTree);
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
- endpointUrl);
- System.out.println(">> Invoking One Way Dispatch");
- dispatch.invokeOneWay(srcStream);
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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;
+
+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.Service;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+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 {
+ System.out.println("---------------------------------------");
+ System.out.println("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);
+
+ System.out.println(">> 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);
+ System.out.println(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 {
+ System.out.println("---------------------------------------");
+ System.out.println("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);
+
+ System.out.println(">> 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);
+ System.out.println(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 {
+ System.out.println("---------------------------------------");
+ System.out.println("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
+ CallbackHandler<Source> callbackHandler = new CallbackHandler<Source>();
+
+ System.out.println(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ System.out.println(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+ }
+
+ public void testAsyncCallbackMessageMode() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("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
+ CallbackHandler<Source> callbackHandler = new CallbackHandler<Source>();
+
+ System.out.println(">> Invoking async (callback) Dispatch");
+ Future<?> monitor = dispatch.invokeAsync(request, callbackHandler);
+
+ while (!monitor.isDone()) {
+ System.out.println(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+ }
+
+ public void testOneWayPayloadMode() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("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);
+
+ System.out.println(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ public void testOneWayMessageMode() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("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);
+
+ System.out.println(">> Invoking One Way Dispatch");
+ dispatch.invokeOneWay(request);
+ }
+
+ /**
+ * 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;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestConstants.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestConstants.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestConstants.java Wed Jul 26 06:07:23 2006
@@ -20,7 +20,25 @@
public class DispatchTestConstants {
- public static String URL = "http://localhost:8080/axis2/services/EchoService";
- public static QName QNAME_SERVICE = new QName("http://ws.apache.org/axis2", "EchoService");
- public static QName QNAME_PORT = new QName("http://ws.apache.org/axis2", "EchoServiceSOAP11port0");
+ public static final String URL = "http://localhost:8080/axis2/services/EchoService";
+ 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 sampleSoapMessage =
+ sampleSoapEnvelopeHeader +
+ sampleBodyContent +
+ sampleSoapEnvelopeFooter;
}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/DispatchTestSuite.java Wed Jul 26 06:07:23 2006
@@ -1,41 +1,41 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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;
-
-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(SourceDispatch.class);
- suite.addTestSuite(DOMSourceDispatch.class);
- suite.addTestSuite(SAXSourceDispatch.class);
- // FIXME: Add this test in
-
- suite.addTestSuite(JAXBDispatch.class);
-
- return suite;
- }
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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;
+
+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);
+ // FIXME: Add this test in
+
+ suite.addTestSuite(JAXBDispatch.class);
+
+ return suite;
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBDispatch.java?rev=425727&r1=425726&r2=425727&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/JAXBDispatch.java Wed Jul 26 06:07:23 2006
@@ -1,112 +1,108 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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;
-
-import java.util.concurrent.Future;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
-import javax.xml.ws.WebServiceException;
-
-import junit.framework.TestCase;
-import test.EchoString;
-import test.EchoStringResponse;
-import test.ObjectFactory;
-
-public class JAXBDispatch extends TestCase {
-
- private Dispatch<Object> dispatch;
- private EchoString request;
-
- public JAXBDispatch(String name) {
- super(name);
- }
-
- public void setUp() {
- //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
- JAXBContext jbc = null;
- try {
- jbc = JAXBContext.newInstance("test");
- dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
- jbc, Service.Mode.PAYLOAD);
- } catch (Exception e) {
- e.printStackTrace();
- fail("[ERROR] - could not create JAXBContext");
- }
-
- //Create the input param
- ObjectFactory factory = new ObjectFactory();
- request = factory.createEchoString();
- }
-
- public void testSync() {
- System.out.println("test: " + getName());
-
- request.setInput("SYNC JAXB TEST");
- try {
- System.out.println(">> Invoking sync Dispatch with JAX-B Parameter");
- EchoStringResponse response = (EchoStringResponse) dispatch.invoke(request);
-
- 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);
-
- System.out.println(">> Response [" + response.getEchoStringReturn() + "]");
- } catch(WebServiceException e) {
- e.printStackTrace();
- fail("[ERROR] - Sync Dispatch invocation failed");
- }
- }
-
- public void testAysnc() {
- System.out.println("test: " + getName());
-
- request.setInput("ASYNC(CALLBACK) JAXB TEST");
- try {
- JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
-
- System.out.println(">> Invoking async(callback) Dispatch with JAX-B Parameter");
- Future<?> monitor = dispatch.invokeAsync(request, callback);
-
- while (!monitor.isDone()) {
- System.out.println(">> Async invocation still not complete");
- Thread.sleep(1000);
- }
- } catch(Exception e) {
- e.printStackTrace();
- fail("[ERROR] - Async(callback) Dispatch invocation failed");
- }
- }
-
- public void testOneWay() {
- System.out.println("test: " + getName());
-
- request.setInput("ONE-WAY JAXB TEST");
- try {
- System.out.println(">> Invoking one-way Dispatch with JAX-B Parameter");
- dispatch.invokeOneWay(request);
- } catch(WebServiceException e) {
- e.printStackTrace();
- fail("[ERROR] - One-way Dispatch invocation failed");
- }
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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;
+
+import java.util.concurrent.Future;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+
+import junit.framework.TestCase;
+import test.EchoString;
+import test.EchoStringResponse;
+import test.ObjectFactory;
+
+public class JAXBDispatch extends TestCase {
+
+ private Dispatch<Object> dispatch;
+
+ 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
+ JAXBContext jbc = null;
+ jbc = JAXBContext.newInstance("test");
+ dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
+ jbc, Service.Mode.PAYLOAD);
+ }
+
+ public void testSync() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("SYNC JAXB TEST");
+
+ // Invoke the Dispatch<Object>
+ System.out.println(">> Invoking sync Dispatch with JAX-B Parameter");
+ EchoStringResponse response = (EchoStringResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+
+ System.out.println(">> 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 testAysnc() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("ASYNC(CALLBACK) JAXB TEST");
+
+ // Create the callback for async responses
+ JAXBCallbackHandler<Object> callback = new JAXBCallbackHandler<Object>();
+
+ // Invoke the Dispatch<Object> asynchronously
+ System.out.println(">> Invoking async(callback) Dispatch with JAX-B Parameter");
+ Future<?> monitor = dispatch.invokeAsync(request, callback);
+
+ while (!monitor.isDone()) {
+ System.out.println(">> Async invocation still not complete");
+ Thread.sleep(1000);
+ }
+ }
+
+ public void testOneWay() throws Exception {
+ System.out.println("---------------------------------------");
+ System.out.println("test: " + getName());
+
+ // Create the input param
+ ObjectFactory factory = new ObjectFactory();
+ EchoString request = factory.createEchoString();
+ request.setInput("ONE-WAY JAXB TEST");
+
+ // Invoke the Dispatch<Object> one-way
+ System.out.println(">> Invoking one-way Dispatch with JAX-B Parameter");
+ dispatch.invokeOneWay(request);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org