axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r423736 [2/2] - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: ./ client/ core/ core/controller/ impl/
Date Thu, 20 Jul 2006 03:21:06 GMT
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java?rev=423736&r1=423735&r2=423736&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
Wed Jul 19 20:21:05 2006
@@ -1,90 +1,95 @@
-/*
- * 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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.ws.Service.Mode;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.jaxws.description.ServiceDescription;
-
-/**
- * The <code>org.apache.axis2.jaxws.core.MessageContext</code> is
- * an interface that extends the JAX-WS 2.0 <code>javax.xml.ws.handler.MessageContext</code>
- * defined in the spec.  This encapsulates all of the functionality needed
- * of the MessageContext for the other JAX-WS spec pieces (the handlers 
- * for example) and also provides the needed bits of contextual information 
- * for the rest of the JAX-WS implementation.
- * 
- * Specifically, this is responsible for providing APIs so that the client 
- * and server implementation portions can get to the Message, defined by the 
- * Message Model format and also any metadata that is available.
- */
-public class MessageContext {
-
-    private org.apache.axis2.context.MessageContext axisMsgCtx;
-    private Map<String, Object> properties;
-    private ServiceDescription serviceDesc;
-    private Mode mode;
-        
-    private OMElement message;  //FIXME: This is temporary until we integrate with the Message
Model
-    
-    public MessageContext() {
-        axisMsgCtx = new org.apache.axis2.context.MessageContext();
-        properties = new HashMap<String, Object>();
-    }
-    
-    public Map<String, Object> getProperties() {   
-        return properties;
-    }
-    
-    public ServiceDescription getServiceDescription() {
-        return serviceDesc;
-    }
-    
-    public void setServiceDescription(ServiceDescription sd) {
-        serviceDesc = sd;
-    }
-    
-    public Mode getMode() {
-        return mode;
-    }
-    
-    public void setMode(Mode m) {
-        mode = m;
-    }
-    
-    public String getOperationName() {
-        return null;
-    }
-    
-    //FIXME: This is a temporary mechanism until the Message Model 
-    //implementation is available.
-    public void setMessageAsOM(OMElement msg) {
-        message = msg;
-    }
-    
-    public OMElement getMessageAsOM() {
-        return message;
-    }
-    
-    protected org.apache.axis2.context.MessageContext getAxisMessageContext() {
-        return axisMsgCtx;
-    }
-}
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.ws.Service.Mode;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+
+/**
+ * The <code>org.apache.axis2.jaxws.core.MessageContext</code> is
+ * an interface that extends the JAX-WS 2.0 <code>javax.xml.ws.handler.MessageContext</code>
+ * defined in the spec.  This encapsulates all of the functionality needed
+ * of the MessageContext for the other JAX-WS spec pieces (the handlers 
+ * for example) and also provides the needed bits of contextual information 
+ * for the rest of the JAX-WS implementation.
+ * 
+ * Specifically, this is responsible for providing APIs so that the client 
+ * and server implementation portions can get to the Message, defined by the 
+ * Message Model format and also any metadata that is available.
+ */
+public class MessageContext {
+
+    private org.apache.axis2.context.MessageContext axisMsgCtx;
+    private Map<String, Object> properties;
+    private ServiceDescription serviceDesc;
+    private Mode mode;
+        
+    private OMElement message;  //FIXME: This is temporary until we integrate with the Message
Model
+    
+    public MessageContext() {
+        axisMsgCtx = new org.apache.axis2.context.MessageContext();
+        properties = new HashMap<String, Object>();
+    }
+    
+    public MessageContext(org.apache.axis2.context.MessageContext mc) {
+        axisMsgCtx = mc;
+        properties = new HashMap<String, Object>();
+    }
+    
+    public Map<String, Object> getProperties() {   
+        return properties;
+    }
+    
+    public ServiceDescription getServiceDescription() {
+        return serviceDesc;
+    }
+    
+    public void setServiceDescription(ServiceDescription sd) {
+        serviceDesc = sd;
+    }
+    
+    public Mode getMode() {
+        return mode;
+    }
+    
+    public void setMode(Mode m) {
+        mode = m;
+    }
+    
+    public String getOperationName() {
+        return null;
+    }
+    
+    //FIXME: This is a temporary mechanism until the Message Model 
+    //implementation is available.
+    public void setMessageAsOM(OMElement msg) {
+        message = msg;
+    }
+    
+    public OMElement getMessageAsOM() {
+        return message;
+    }
+    
+    protected org.apache.axis2.context.MessageContext getAxisMessageContext() {
+        return axisMsgCtx;
+    }
+}

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=423736&r1=423735&r2=423736&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 19 20:21:05 2006
@@ -1,211 +1,356 @@
-/*
- * 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 javax.xml.ws.WebServiceException;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.jaxws.BindingProvider;
-import org.apache.axis2.jaxws.core.InvocationContext;
-import org.apache.axis2.jaxws.core.MessageContext;
-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.
- * 
- * 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 class AxisInvocationController implements InvocationController {
-    
-    private static Log log = LogFactory.getLog(AxisInvocationController.class);
-    
-    /**
-     * Performs a synchronous (blocking) invocation of the client.
-     * 
-     * @param ic
-     * @return
-     */
-    public InvocationContext invoke(InvocationContext ic) {
-        if (log.isDebugEnabled()) {
-            log.debug("Invocation pattern: synchronous");
-        }
-        
-        // Check to make sure we at least have a valid InvocationContext
-        // and request MessageContext
-        if (ic == null) {
-            throw new WebServiceException("Cannot invoke; InvocationContext was null");
-        }
-        if (ic.getRequestMessageContext() == null) {
-            throw new WebServiceException("Cannot invoke; request MessageContext was null");
-        }
-        
-        // Setup the MessageContext for the response
-        MessageContext requestMsgCtx = ic.getRequestMessageContext();
-        MessageContext responseMsgCtx = new MessageContext();
-        ic.setResponseMessageContext(responseMsgCtx);
-        
-        ServiceClient client = ic.getServiceClient();        
-        if (client != 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);
-            
-            // Get the SOAP Action (if needed)
-            String soapAction = getSOAPAction(requestMsgCtx);
-            client.getOptions().setAction(soapAction);
-            
-            // Use the ServiceClient to send the request.
-            OMElement rspEnvelope = null;
-            try {
-                OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
-                rspEnvelope = client.sendReceive(ServiceClient.ANON_OUT_IN_OP, reqEnvelope);
-            } catch (AxisFault e) {
-                throw new WebServiceException(e);
-            }
-            
-            responseMsgCtx.setMessageAsOM(rspEnvelope);
-        }
-
-        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
-     */
-    public void invokeOneWay(InvocationContext ic) {
-        if (log.isDebugEnabled()) {
-            log.debug("Invocation pattern: one-way");
-        }
-        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
-     */
-    public Future<?> invokeAsync(InvocationContext ic, AsyncHandler callback) {
-        if (log.isDebugEnabled()) {
-            log.debug("Invocation pattern: async (callback)");
-        }
-        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
-     */
-    public Response invokeAsync(InvocationContext ic) {
-        if (log.isDebugEnabled()) {
-            log.debug("Invocation pattern: async (polling)");
-        }
-        return null;
-    }
-    
-    /**
-     * Creates the OperationClient instance that will be invoked upon.
-     * 
-     * This will be used instead of the ServiceClient as we mature the 
-     * AxisInvocationController
-     */
-    /*
-    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 new WebServiceException("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 new WebServiceException("Operation name not set.");
-        }
-        
-        return client;
-    }
-    */
-    
-    private String getSOAPAction(MessageContext ctx){
-        Boolean useSoapAction = (Boolean) ctx.getProperties().get(BindingProvider.SOAPACTION_USE_PROPERTY);
-        if(useSoapAction != null && useSoapAction.booleanValue()){
-            return (String) ctx.getProperties().get(BindingProvider.SOAPACTION_URI_PROPERTY);
-        }
-        
-        return null;
-    }
-}
+/*
+ * 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.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+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.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.jaxws.AxisCallback;
+import org.apache.axis2.jaxws.BindingProvider;
+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.util.Constants;
+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.
+ * 
+ * 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 class AxisInvocationController implements InvocationController {
+    
+    private static Log log = LogFactory.getLog(AxisInvocationController.class);
+    
+    /**
+     * Performs a synchronous (blocking) invocation of the client.
+     * 
+     * @param ic
+     * @return
+     */
+    public InvocationContext invoke(InvocationContext ic) {
+        if (log.isDebugEnabled()) {
+            log.debug("Invocation pattern: synchronous");
+        }
+        
+        // Check to make sure we at least have a valid InvocationContext
+        // and request MessageContext
+        if (ic == null) {
+            throw new WebServiceException("Cannot invoke; InvocationContext was null");
+        }
+        if (ic.getRequestMessageContext() == null) {
+            throw new WebServiceException("Cannot invoke; request MessageContext was null");
+        }
+        
+        // Setup the MessageContext for the response
+        MessageContext requestMsgCtx = ic.getRequestMessageContext();
+        MessageContext responseMsgCtx = new MessageContext();
+        ic.setResponseMessageContext(responseMsgCtx);
+        
+        ServiceClient client = ic.getServiceClient();        
+        if (client != 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);
+            
+            // Get the SOAP Action (if needed)
+            String soapAction = getSOAPAction(requestMsgCtx);
+            client.getOptions().setAction(soapAction);
+            
+            // Use the ServiceClient to send the request.
+            OMElement rspEnvelope = null;
+            try {
+                OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
+                rspEnvelope = client.sendReceive(ServiceClient.ANON_OUT_IN_OP, reqEnvelope);
+            } catch (AxisFault e) {
+                throw new WebServiceException(e);
+            }
+            
+            // Set the response message on the response MessageContext
+            responseMsgCtx.setMessageAsOM(rspEnvelope);
+        }
+
+        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
+     */
+    public void invokeOneWay(InvocationContext ic) {
+        if (log.isDebugEnabled()) {
+            log.debug("Invocation pattern: one-way");
+        }
+        
+        // Check to make sure we at least have a valid InvocationContext
+        // and request MessageContext
+        if (ic == null) {
+            throw new WebServiceException("Cannot invoke; InvocationContext was null");
+        }
+        if (ic.getRequestMessageContext() == null) {
+            throw new WebServiceException("Cannot invoke; request MessageContext was null");
+        }
+        
+        // Setup the MessageContext for the response
+        MessageContext requestMsgCtx = ic.getRequestMessageContext();
+        
+        //TODO: Need to figure out whether or not we need to create the response
+        //MessageContext here and whether or not handlers need to be run for 
+        //one-way invocations.
+        MessageContext responseMsgCtx = new MessageContext();
+        ic.setResponseMessageContext(responseMsgCtx);
+        
+        ServiceClient client = ic.getServiceClient();        
+        if (client != 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);
+            
+            // Get the SOAP Action (if needed)
+            String soapAction = getSOAPAction(requestMsgCtx);
+            client.getOptions().setAction(soapAction);
+            
+            // Use the ServiceClient to send the request.
+            try {
+                OMElement reqEnvelope = requestMsgCtx.getMessageAsOM();
+                client.fireAndForget(ServiceClient.ANON_OUT_ONLY_OP, reqEnvelope);
+            } catch (AxisFault e) {
+                throw new WebServiceException(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
+     */
+    public Future<?> invokeAsync(InvocationContext ic, AsyncHandler callback) {
+        if (log.isDebugEnabled()) {
+            log.debug("Invocation pattern: async (callback)");
+        }
+
+        // Check to make sure we at least have a valid InvocationContext
+        // and request MessageContext
+        if (ic == null) {
+            throw new WebServiceException("Cannot invoke; InvocationContext was null");
+        }
+        if (ic.getRequestMessageContext() == null) {
+            throw new WebServiceException("Cannot invoke; request MessageContext was null");
+        }
+        
+        // Setup the MessageContext for the response
+        MessageContext requestMsgCtx = ic.getRequestMessageContext();
+        MessageContext responseMsgCtx = new MessageContext();
+        ic.setResponseMessageContext(responseMsgCtx);
+        
+        ServiceClient client = ic.getServiceClient();        
+        if (client != 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);
+            
+            // Get the SOAP Action (if needed)
+            String soapAction = getSOAPAction(requestMsgCtx);
+            client.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");
+            }
+            
+            // There should be an AsyncListener that is configured and set on the
+            // InvocationContext.  We must get this and use it to wait for the 
+            // async response to come back.  The AxisCallback that is set on the 
+            // AsyncListener is the callback that Axis2 will call when the response
+            // has arrived.
+            AsyncListener listener = ic.getAsyncListener();
+            AxisCallback axisCallback = new AxisCallback();
+            listener.setAxisCallback(axisCallback);
+            
+            // Once the AsyncListener is configured, we must include that in an 
+            // AsyncListenerWrapper.  The wrapper is what will handle the lifecycle 
+            // of the listener and determine when it's started and stopped.
+            AsyncListenerWrapper<?> wrapper = new AsyncListenerWrapper<Object>(listener);
+
+            // Inside of the wrapper we must set the callback that the JAX-WS
+            // client programmer provided.  This is the user object that we 
+            // must call back on once we've done everything we need to do at
+            // the JAX-WS layer.
+            if(callback != null){
+                wrapper.setAsyncHandler(callback);
+            }
+            else {
+                throw new WebServiceException("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);
+            } catch (AxisFault e) {
+                e.printStackTrace();
+                throw new WebServiceException(e);
+            }
+            
+            // Now that the request has been sent, start the listener thread so that it can
+            // catch the async response.
+            // TODO: Need to determine whether this should be done BEFORE or AFTER
+            // we send the request.  My guess is before though.
+            try {
+                // TODO:Need to figure out where we get the Executor from
+                // Can't be from the MessageContext, but should maybe be 
+                // set somewhere accessible.
+                // FIXME: This should NOT be an ExecutorService, but should just
+                // be a plain old Executor.
+                ExecutorService exec = (ExecutorService) ic.getExecutor();
+                Future<?> future = exec.submit(wrapper);
+                future.get();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+                throw new WebServiceException(e.getMessage());
+            } catch (ExecutionException e) {
+                e.printStackTrace();
+                throw new WebServiceException(e.getMessage());
+            }
+            
+            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
+     */
+    public Response invokeAsync(InvocationContext ic) {
+        if (log.isDebugEnabled()) {
+            log.debug("Invocation pattern: async (polling)");
+        }
+        return null;
+    }
+    
+    /**
+     * Creates the OperationClient instance that will be invoked upon.
+     * 
+     * This will be used instead of the ServiceClient as we mature the 
+     * AxisInvocationController
+     */
+    /*
+    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 new WebServiceException("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 new WebServiceException("Operation name not set.");
+        }
+        
+        return client;
+    }
+    */
+    
+    private String getSOAPAction(MessageContext ctx){
+        Boolean useSoapAction = (Boolean) ctx.getProperties().get(BindingProvider.SOAPACTION_USE_PROPERTY);
+        if(useSoapAction != null && useSoapAction.booleanValue()){
+            return (String) ctx.getProperties().get(BindingProvider.SOAPACTION_URI_PROPERTY);
+        }
+        
+        return null;
+    }
+}

Added: 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=423736&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListener.java
Wed Jul 19 20:21:05 2006
@@ -0,0 +1,91 @@
+/*
+ * 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.impl;
+
+import java.util.concurrent.Callable;
+
+import javax.xml.ws.Service.Mode;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.jaxws.AxisCallback;
+import org.apache.axis2.jaxws.core.MessageContext;
+
+
+/**
+ * The AsyncListener is responsible for holding the callback that was passed
+ * to the Axis2 client and waiting for that async response to come back.  Once 
+ * the response comes back, the AsyncListener will perform whatever function is
+ * needed by the JAX-WS layer before returning.
+ * 
+ * This class implements the Callable interface and is what will be called by
+ * the execute() method of the client's Executor.
+ */
+public class AsyncListener implements Callable {
+
+    protected AxisCallback axisCallback;
+    protected Mode mode;
+    
+    public AsyncListener() {
+        //do nothing
+    }
+    
+    public AsyncListener(AxisCallback cb) {
+        axisCallback = cb;
+    }
+    
+    public void setAxisCallback(AxisCallback cb) {
+        axisCallback = cb;
+    }
+    
+    //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) {
+        mode = m;
+    }
+    
+    /**
+     * This method will be called to collect the async response from Axis2.  
+     */
+    public Object call() throws Exception {
+        if (axisCallback != null) {
+            while (!axisCallback.isComplete()) {
+                //TODO: The wait period should probably be configurable
+                Thread.sleep(1000);
+            }
+            
+            MessageContext responseMsgCtx = axisCallback.getResponseMessageContext();
+            Object responseObj = getResponseValueObject(responseMsgCtx);
+            return responseObj;            
+        }
+        else {
+            //throw an Exception
+        }
+        
+        return null;
+    }
+    
+    /**
+     * A default implementation of this method that returns the contents
+     * of the message in the form of an XML String.  Subclasses should override
+     * this to convert the response message into whatever format they require.
+     * @param msg
+     */
+    protected Object getResponseValueObject(MessageContext mc) {
+        OMElement msg = mc.getMessageAsOM();
+        return msg.toString();
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListenerWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListenerWrapper.java?rev=423736&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListenerWrapper.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/impl/AsyncListenerWrapper.java
Wed Jul 19 20:21:05 2006
@@ -0,0 +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.impl;
+
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+/**
+ * The AsyncListenerWrapper is what wraps the AsyncListener that waits for
+ * the response.  The AsyncListenerWrapper controls the lifecycle of the 
+ * listener, determining when it is started and stopped.
+ * 
+ * The wrapper is also the item that will call the users AsyncHandler that
+ * they provided when they made the asynchronous call.
+ */
+public class AsyncListenerWrapper<T> extends FutureTask<T> implements Response<T>
{
+
+    private Map<String, Object> responseCtx;
+    private AsyncHandler asyncHandler;
+    
+    public AsyncListenerWrapper(Callable<T> processor) {
+        super(processor);
+    }
+    
+    public void setAsyncHandler(AsyncHandler ah) {
+        asyncHandler = ah;
+    }
+    
+    public Map<String, Object> getContext() {
+        return responseCtx;
+    }
+    
+    protected void done() {
+        super.done();
+        
+        if(!isCancelled()){
+            if(asyncHandler != null){
+                asyncHandler.handleResponse(this);
+            }
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message