You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2009/06/18 15:05:44 UTC

svn commit: r786046 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client: dispatch/BaseDispatch.java proxy/JAXWSProxyHandler.java

Author: scheu
Date: Thu Jun 18 13:05:44 2009
New Revision: 786046

URL: http://svn.apache.org/viewvc?rev=786046&view=rev
Log:
JIRA:AXIS2-4395
Contributor:Paul Mariduena and Rich Scheuerle
Summary:
Changed BaseDispatch and JAXWSProxyHandler to ensure that the same logic is applied for these entry points
into the JAX-WS engine.  Comments are added to aid developers to make proper fixes.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java?rev=786046&r1=786045&r2=786046&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java Thu Jun 18 13:05:44 2009
@@ -106,6 +106,20 @@
      */
     protected abstract AsyncResponse createAsyncResponseListener();
 
+    
+    /**
+     * Note to developer: When making a change or fix to this method, please consider
+     * all 5 Proxy/Dispatch "invoke" methods now available in JAX-WS. For Dispatch, 
+     * these are:
+     * 1) Synchronous invoke()
+     * 2) invokeOneWay()
+     * 3) invokeAsynch (Future)
+     * 4) invokeAsynch (Callback)
+     * 
+     * For Proxy:
+     * 5) invokeSEIMethod() 
+     *
+     */
     public Object invoke(Object obj) throws WebServiceException {
 
         // Catch all exceptions and rethrow an appropriate WebService Exception
@@ -197,9 +211,17 @@
 
             return returnObj;
         } catch (WebServiceException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invoke(): Synchronous invocation failed, " 
+                        + "caught a WebServiceException: ", e);
+            }
             throw e;
         } catch (Exception e) {
             // All exceptions are caught and rethrown as a WebServiceException
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invoke(): Synchronous invocation failed, caught an Exception, " + 
+                        "wrapping into a WebServiceException. Exception caught: ", e);
+            }  
             throw ExceptionFactory.makeWebServiceException(e);
         }
     }
@@ -215,6 +237,19 @@
         }
     }
 
+    /**
+     * Note to developer: When making a change or fix to this method, please consider
+     * all 5 Proxy/Dispatch "invoke" methods now available in JAX-WS. For Dispatch, 
+     * these are:
+     * 1) Synchronous invoke()
+     * 2) invokeOneWay()
+     * 3) invokeAsynch (Future)
+     * 4) invokeAsynch (Callback)
+     * 
+     * For Proxy:
+     * 5) invokeSEIMethod() 
+     *
+     */
     public void invokeOneWay(Object obj) throws WebServiceException {
 
         // All exceptions are caught and rethrown as a WebServiceException
@@ -251,6 +286,27 @@
             invocationContext.setHandlers(binding.getHandlerChain());
 
             initMessageContext(obj, requestMsgCtx);
+            
+            /*
+             * if SESSION_MAINTAIN_PROPERTY is true, and the client app has explicitly set a HEADER_COOKIE on the request context, assume the client
+             * app is expecting the HEADER_COOKIE to be the session id.  If we were establishing a new session, no cookie would be sent, and the 
+             * server would reply with a "Set-Cookie" header, which is copied as a "Cookie"-keyed property to the service context during response.
+             * In this case, if we succeed in using an existing server session, no "Set-Cookie" header will be returned, and therefore no
+             * "Cookie"-keyed property would be set on the service context.  So, let's copy our request context HEADER_COOKIE key to the service
+             * context now to prevent the "no cookie" exception in BindingProvider.setupSessionContext.  It is possible the server does not support
+             * sessions, in which case no error occurs, but the client app would assume it is participating in a session.
+             */
+            if ((requestContext.containsKey(BindingProvider.SESSION_MAINTAIN_PROPERTY)) && ((Boolean)requestContext.get(BindingProvider.SESSION_MAINTAIN_PROPERTY))) {
+                if ((requestContext.containsKey(HTTPConstants.HEADER_COOKIE)) && (requestContext.get(HTTPConstants.HEADER_COOKIE) != null)) {
+                    if (invocationContext.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE) == null) {
+                        invocationContext.getServiceClient().getServiceContext().setProperty(HTTPConstants.HEADER_COOKIE, requestContext.get(HTTPConstants.HEADER_COOKIE));
+                        if (log.isDebugEnabled()) {
+                            log.debug("Client-app defined Cookie property (assume to be session cookie) on request context copied to service context." +
+                                "  Caution:  server may or may not support sessions, but client app will not be informed when not supported.");
+                        }
+                    }
+                }
+            }
 
             // call common init method for all invoke* paths
             preInvokeInit(invocationContext);
@@ -276,13 +332,35 @@
 
             return;
         } catch (WebServiceException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeOneWay(): One-way invocation failed, " + 
+                        "caught a WebServiceException: ", e);
+            }
             throw e;
         } catch (Exception e) {
             // All exceptions are caught and rethrown as a WebServiceException
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeOneWay(): One-way invocation failed, " + 
+                        "caught an Exception, wrapping into a WebServicesException. " + 
+                        " Exception caught: ", e);
+            }
             throw ExceptionFactory.makeWebServiceException(e);
         }
     }
 
+    /**
+     * Note to developer: When making a change or fix to this method, please consider
+     * all 5 Proxy/Dispatch "invoke" methods now available in JAX-WS. For Dispatch, 
+     * these are:
+     * 1) Synchronous invoke()
+     * 2) invokeOneWay()
+     * 3) invokeAsynch (Future)
+     * 4) invokeAsynch (Callback)
+     * 
+     * For Proxy:
+     * 5) invokeSEIMethod() 
+     *
+     */
     public Future<?> invokeAsync(Object obj, AsyncHandler asynchandler) throws WebServiceException {
 
         // All exceptions are caught and rethrown as a WebServiceException
@@ -319,6 +397,26 @@
             invocationContext.setHandlers(binding.getHandlerChain());
 
             initMessageContext(obj, requestMsgCtx);
+            /*
+             * if SESSION_MAINTAIN_PROPERTY is true, and the client app has explicitly set a HEADER_COOKIE on the request context, assume the client
+             * app is expecting the HEADER_COOKIE to be the session id.  If we were establishing a new session, no cookie would be sent, and the 
+             * server would reply with a "Set-Cookie" header, which is copied as a "Cookie"-keyed property to the service context during response.
+             * In this case, if we succeed in using an existing server session, no "Set-Cookie" header will be returned, and therefore no
+             * "Cookie"-keyed property would be set on the service context.  So, let's copy our request context HEADER_COOKIE key to the service
+             * context now to prevent the "no cookie" exception in BindingProvider.setupSessionContext.  It is possible the server does not support
+             * sessions, in which case no error occurs, but the client app would assume it is participating in a session.
+             */
+            if ((requestContext.containsKey(BindingProvider.SESSION_MAINTAIN_PROPERTY)) && ((Boolean)requestContext.get(BindingProvider.SESSION_MAINTAIN_PROPERTY))) {
+                if ((requestContext.containsKey(HTTPConstants.HEADER_COOKIE)) && (requestContext.get(HTTPConstants.HEADER_COOKIE) != null)) {
+                    if (invocationContext.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE) == null) {
+                        invocationContext.getServiceClient().getServiceContext().setProperty(HTTPConstants.HEADER_COOKIE, requestContext.get(HTTPConstants.HEADER_COOKIE));
+                        if (log.isDebugEnabled()) {
+                            log.debug("Client-app defined Cookie property (assume to be session cookie) on request context copied to service context." +
+                                "  Caution:  server may or may not support sessions, but client app will not be informed when not supported.");
+                        }
+                    }
+                }
+            }
 
             // call common init method for all invoke* paths
             preInvokeInit(invocationContext);
@@ -355,13 +453,34 @@
 
             return asyncResponse;
         } catch (WebServiceException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeAsync() [Callback]: Asynchronous invocation failed, " +
+                    "caught a WebServiceException: ", e);
+            }
             throw e;
         } catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeAsync() [Callback]: Asynchronous invocation failed, " +
+                    "caught an Exception, wrapping into a WebServiceException. Exception caught: ", e);
+            }
             // All exceptions are caught and rethrown as a WebServiceException
             throw ExceptionFactory.makeWebServiceException(e);
         }
     }
 
+    /**
+     * Note to developer: When making a change or fix to this method, please consider
+     * all 5 Proxy/Dispatch "invoke" methods now available in JAX-WS. For Dispatch, 
+     * these are:
+     * 1) Synchronous invoke()
+     * 2) invokeOneWay()
+     * 3) invokeAsynch (Future)
+     * 4) invokeAsynch (Callback)
+     * 
+     * For Proxy:
+     * 5) invokeSEIMethod() 
+     *
+     */
     public Response invokeAsync(Object obj) throws WebServiceException {
 
         // All exceptions are caught and rethrown as a WebServiceException
@@ -398,6 +517,27 @@
             invocationContext.setHandlers(binding.getHandlerChain());
 
             initMessageContext(obj, requestMsgCtx);
+            
+            /*
+             * if SESSION_MAINTAIN_PROPERTY is true, and the client app has explicitly set a HEADER_COOKIE on the request context, assume the client
+             * app is expecting the HEADER_COOKIE to be the session id.  If we were establishing a new session, no cookie would be sent, and the 
+             * server would reply with a "Set-Cookie" header, which is copied as a "Cookie"-keyed property to the service context during response.
+             * In this case, if we succeed in using an existing server session, no "Set-Cookie" header will be returned, and therefore no
+             * "Cookie"-keyed property would be set on the service context.  So, let's copy our request context HEADER_COOKIE key to the service
+             * context now to prevent the "no cookie" exception in BindingProvider.setupSessionContext.  It is possible the server does not support
+             * sessions, in which case no error occurs, but the client app would assume it is participating in a session.
+             */
+            if ((requestContext.containsKey(BindingProvider.SESSION_MAINTAIN_PROPERTY)) && ((Boolean)requestContext.get(BindingProvider.SESSION_MAINTAIN_PROPERTY))) {
+                if ((requestContext.containsKey(HTTPConstants.HEADER_COOKIE)) && (requestContext.get(HTTPConstants.HEADER_COOKIE) != null)) {
+                    if (invocationContext.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE) == null) {
+                        invocationContext.getServiceClient().getServiceContext().setProperty(HTTPConstants.HEADER_COOKIE, requestContext.get(HTTPConstants.HEADER_COOKIE));
+                        if (log.isDebugEnabled()) {
+                            log.debug("Client-app defined Cookie property (assume to be session cookie) on request context copied to service context." +
+                                "  Caution:  server may or may not support sessions, but client app will not be informed when not supported.");
+                        }
+                    }
+                }
+            }
 
             // call common init method for all invoke* paths
             preInvokeInit(invocationContext);
@@ -434,8 +574,16 @@
 
             return asyncResponse;
         } catch (WebServiceException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeAsync() [Polling]: Asynchronous invocation failed, " +
+                    "caught a WebServiceException: ", e);
+            }
             throw e;
         } catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("BaseDispatch.invokeAsync() [Polling]: Asynchronous invocation failed, " +
+                    "caught an Exception, wrapping into a WebServiceException. Exception caught: ",e);
+            }
             // All exceptions are caught and rethrown as a WebServiceException
             throw ExceptionFactory.makeWebServiceException(e);
         }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?rev=786046&r1=786045&r2=786046&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Thu Jun 18 13:05:44 2009
@@ -161,9 +161,20 @@
     }
 
     /*
-    * Performs the invocation of the method defined on the Service Endpoint
-    * Interface.
-    */
+     * Note to developer: When making a change or fix to this method, please consider
+     * all 5 Proxy/Dispatch "invoke" methods now available in JAX-WS. For Dispatch, 
+     * these are:
+     * 1) Synchronous invoke()
+     * 2) invokeOneWay()
+     * 3) invokeAsynch (Future)
+     * 4) invokeAsynch (Callback)
+     * 
+     * For Proxy:
+     * 5) invokeSEIMethod() 
+     *
+     * Performs the invocation of the method defined on the Service Endpoint
+     * Interface.
+     */
     private Object invokeSEIMethod(Method method, Object[] args) throws Throwable {
         if (log.isDebugEnabled()) {
             log.debug("Attempting to invoke SEI Method " + method.getName());
@@ -295,6 +306,10 @@
             //Check to see if we need to maintain session state
             checkMaintainSessionState(request, requestIC);
 
+            if (log.isDebugEnabled()) {
+                log.debug("Exiting the method invokeSEIMethod() - Async Callback ");
+            }
+
             return future;
         }
 
@@ -310,6 +325,10 @@
 
             //Check to see if we need to maintain session state
             checkMaintainSessionState(request, requestIC);
+            
+            if (log.isDebugEnabled()) {
+                log.debug("Exiting the method invokeSEIMethod() - Async Polling ");
+            }
 
             return response;
         }
@@ -329,9 +348,18 @@
                     getResponseContext(), responseContext);
             
             Object responseObj = createResponse(method, args, responseContext, operationDesc);
+
+            if (log.isDebugEnabled()) {
+                log.debug("Exiting the method invokeSEIMethod() - Sync");
+            }
+                        
             return responseObj;
         }
 
+        if (log.isDebugEnabled()) {
+            log.debug("Exiting the method invokeSEIMethod() - One Way ");
+        }
+
         return null;
     }