Author: damrhei
Date: Sat Mar  8 08:49:09 2008
New Revision: 635006

URL: http://svn.apache.org/viewvc?rev=635006&view=rev
Log:
Extend the InvocationListener interface to allow notification upon exceptions 
in the JAX-WS server-side code flow. Changes JAX-WS server-side code to 
properly call out to the InvocationListener.notifyOnException methods when an 
exception is caught either from the invocation of the endpoint or just a 
general system exception. Addresses AXIS2-3582.

Added:
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationHelper.java
Modified:
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContext.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContextImpl.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListener.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListenerBean.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
    
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/Constants.java
    
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/JAXWSServerTests.java

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
 Sat Mar  8 08:49:09 2008
@@ -21,6 +21,7 @@
 
 import java.util.List;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.jaxws.ExceptionFactory;
@@ -75,6 +76,12 @@
                 t.printStackTrace();
             }
             
+            Throwable faultMessage = 
InvocationHelper.determineMappedException(t, eic);
+            if(faultMessage != null) {
+                t = faultMessage;
+            }
+            
eic.getResponseMessageContext().setCausedByException(AxisFault.makeFault(t));
+            
             
ThreadContextMigratorUtil.performThreadCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
                 eic.getRequestMessageContext().getAxisMessageContext());
             
@@ -105,8 +112,12 @@
             engine.sendFault(axisResponseMsgCtx);
             
         } catch (Throwable t) {
-            // TODO Auto-generated catch block
-            t.printStackTrace();
+            Throwable faultMessage = 
InvocationHelper.determineMappedException(t, eic);
+            if(faultMessage != null) {
+                t = faultMessage;
+            }
+            
+            throw 
ExceptionFactory.makeWebServiceException(AxisFault.makeFault(t));
         }
     }
     

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
 Sat Mar  8 08:49:09 2008
@@ -91,16 +91,15 @@
         if (log.isDebugEnabled()) {
             log.debug("Invocation pattern: synchronous");
         }
-
-        boolean good = handleRequest(eic);
-
-        if (!good) {
-            return eic;
-        }
         
         MessageContext request = eic.getRequestMessageContext();
-        MessageContext response = null;
         try {
+            boolean good = handleRequest(eic);
+
+            if (!good) {
+                return eic;
+            }
+            MessageContext response = null;
             EndpointDispatcher dispatcher = eic.getDispatcher();
             if (request != null && dispatcher != null) {
                 response = dispatcher.invoke(request);    
@@ -110,14 +109,17 @@
                 throw 
ExceptionFactory.makeWebServiceException(Messages.getMessage("invokeErr"));
             }
         } catch (Exception e) {
-            throw ExceptionFactory.makeWebServiceException(e);
+            Throwable toBeThrown = 
InvocationHelper.determineMappedException(e, eic);
+            if(toBeThrown == null) {
+                toBeThrown = e;
+            }
+            throw ExceptionFactory.makeWebServiceException(toBeThrown);
         } finally {
             // Passed pivot point
             request.getMessage().setPostPivot();
+            handleResponse(eic);    
         }
         
-        handleResponse(eic);            
-        
         return eic;
     }
     
@@ -126,14 +128,13 @@
             log.debug("Invocation pattern: asynchronous");
         }
         
-        boolean good = handleRequest(eic);
-
-        if (!good) {
-            return;
-        }
-        
         MessageContext request = eic.getRequestMessageContext();
         try {
+            boolean good = handleRequest(eic);
+
+            if (!good) {
+                return;
+            }
             EndpointDispatcher dispatcher = eic.getDispatcher();
             if (request != null && dispatcher != null) {
                 dispatcher.invokeAsync(request, eic.getCallback());    
@@ -142,7 +143,11 @@
                 throw 
ExceptionFactory.makeWebServiceException(Messages.getMessage("invokeErr"));
             }
         } catch (Exception e) {
-            throw ExceptionFactory.makeWebServiceException(e);
+            Throwable toBeThrown = 
InvocationHelper.determineMappedException(e, eic);
+            if(toBeThrown == null) {
+                toBeThrown = e;
+            }
+            throw ExceptionFactory.makeWebServiceException(toBeThrown);
         } finally {
             // FIXME (NLG): Probably need to revisit this location.  Should it 
be moved down?
             // Passed pivot point
@@ -157,14 +162,14 @@
             log.debug("Invocation pattern: one-way");
         }
     
-        boolean good = handleRequest(eic);
 
-        if (!good) {
-            return;
-        }
-        
         MessageContext request = eic.getRequestMessageContext();
         try {
+            boolean good = handleRequest(eic);
+
+            if (!good) {
+                return;
+            }
             EndpointDispatcher dispatcher = eic.getDispatcher();
             if (request != null && dispatcher != null) {
                 dispatcher.invokeOneWay(request);    
@@ -173,7 +178,11 @@
                 throw 
ExceptionFactory.makeWebServiceException(Messages.getMessage("invokeErr"));
             }
         } catch (Exception e) {
-            throw ExceptionFactory.makeWebServiceException(e);
+            Throwable toBeThrown = 
InvocationHelper.determineMappedException(e, eic);
+            if(toBeThrown == null) {
+                toBeThrown = e;
+            }
+            throw ExceptionFactory.makeWebServiceException(toBeThrown);
         } finally {
             // Passed pivot point
             request.getMessage().setPostPivot();
@@ -184,31 +193,7 @@
     
     protected boolean handleRequest(EndpointInvocationContext eic) {
         
-        requestReceived(eic);
-        
-        MessageContext request = eic.getRequestMessageContext();
-        
-        Class serviceEndpoint = getServiceImplementation(request);
-        EndpointDescription endpointDesc = getEndpointDescription(request, 
serviceEndpoint);
-        request.setEndpointDescription(endpointDesc);
-        
-        //  TODO: review: make sure the handlers are set on the 
InvocationContext
-        //  This implementation of the JAXWS runtime does not use Endpoint, 
which
-        //  would normally be the place to initialize and store the handler 
list.
-        //  In lieu of that, we will have to intialize and store them on the 
-        //  InvocationContext.  also see the InvocationContextFactory.  On the 
client
-        //  side, the binding is not yet set when we call into that factory, 
so the
-        //  handler list doesn't get set on the InvocationContext object 
there.  Thus
-        //  we gotta do it here.
-        //  
-        //  Since we're on the server, and there apparently is no Binding 
object
-        //  anywhere to be found...
-        if (eic.getHandlers() == null) {
-            if (log.isDebugEnabled()) {
-                log.debug("No handlers found on the InvocationContext, 
initializing handler list.");
-            }
-            eic.setHandlers(new 
HandlerResolverImpl(endpointDesc.getServiceDescription()).getHandlerChain(endpointDesc.getPortInfo()));
-        }
+
 
         //Not needed since this is already handled when eic reaches this level
         //if (!Utils.bindingTypesMatch(request, 
endpointDesc.getServiceDescription())) {
@@ -221,6 +206,32 @@
         MessageContext responseMsgContext = null;
 
         try {
+            requestReceived(eic);
+            
+            MessageContext request = eic.getRequestMessageContext();
+            
+            Class serviceEndpoint = getServiceImplementation(request);
+            EndpointDescription endpointDesc = getEndpointDescription(request, 
serviceEndpoint);
+            request.setEndpointDescription(endpointDesc);
+            
+            //  TODO: review: make sure the handlers are set on the 
InvocationContext
+            //  This implementation of the JAXWS runtime does not use 
Endpoint, which
+            //  would normally be the place to initialize and store the 
handler list.
+            //  In lieu of that, we will have to intialize and store them on 
the 
+            //  InvocationContext.  also see the InvocationContextFactory.  On 
the client
+            //  side, the binding is not yet set when we call into that 
factory, so the
+            //  handler list doesn't get set on the InvocationContext object 
there.  Thus
+            //  we gotta do it here.
+            //  
+            //  Since we're on the server, and there apparently is no Binding 
object
+            //  anywhere to be found...
+            if (eic.getHandlers() == null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("No handlers found on the InvocationContext, 
initializing handler list.");
+                }
+                eic.setHandlers(new 
HandlerResolverImpl(endpointDesc.getServiceDescription()).getHandlerChain(endpointDesc.getPortInfo()));
+            }
+            
             // Get the service instance.  This will run the @PostConstruct 
code.
             ServiceInstanceFactory instanceFactory = (ServiceInstanceFactory) 
                 FactoryRegistry.getFactory(ServiceInstanceFactory.class);
@@ -292,7 +303,11 @@
            } 
         } catch (Exception e) {
             // TODO for now, throw it.  We probably should try to make an 
XMLFault object and set it on the message
-            throw ExceptionFactory.makeWebServiceException(e);  
+            Throwable toBeThrown = 
InvocationHelper.determineMappedException(e, eic);
+            if(toBeThrown == null) {
+                toBeThrown = e;
+            }
+            throw ExceptionFactory.makeWebServiceException(toBeThrown);
         } finally {
                // at this point, we are done with handler instances on the 
server; call @PreDestroy on all of them
             HandlerLifecycleManager hlm = createHandlerlifecycleManager();
@@ -551,6 +566,9 @@
                     }
                 }
             }
+            MessageContext request = eic.getRequestMessageContext();
+            
request.setProperty(org.apache.axis2.jaxws.spi.Constants.INVOCATION_LISTENER_LIST,
 
+                                eic.getInvocationListeners());
         }
     }
     
@@ -581,4 +599,5 @@
                 .getFactory(HandlerLifecycleManagerFactory.class);
         return elmf.createHandlerLifecycleManager();
     }
+    
 }

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContext.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContext.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContext.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContext.java
 Sat Mar  8 08:49:09 2008
@@ -93,6 +93,11 @@
     public void addInvocationListener(InvocationListener listener);
     
     /**
+     * Sets list of InvocationListener instances
+     */
+    public void setInvocationListeners(List<InvocationListener> listeners);
+    
+    /**
      * Gets the InvocationListener instances from the context.
      */
     public List<InvocationListener> getInvocationListeners();

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContextImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContextImpl.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContextImpl.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointInvocationContextImpl.java
 Sat Mar  8 08:49:09 2008
@@ -108,6 +108,14 @@
     
     /*
      * (non-Javadoc)
+     * @see 
org.apache.axis2.jaxws.server.EndpointInvocationContext#setInvocationListeners(List<InvocationListener>
 listeners)
+     */
+    public void setInvocationListeners(List<InvocationListener> listeners) {
+        this.ilInstances = listeners;
+    }
+    
+    /*
+     * (non-Javadoc)
      * @see 
org.apache.axis2.jaxws.server.EndpointInvocationContext#addInvocationListener(InvocationListener)
      */
     public void addInvocationListener(InvocationListener listener) {

Added: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationHelper.java?rev=635006&view=auto
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationHelper.java
 (added)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationHelper.java
 Sat Mar  8 08:49:09 2008
@@ -0,0 +1,98 @@
+package org.apache.axis2.jaxws.server;
+
+import java.util.List;
+
+import org.apache.axis2.jaxws.core.MessageContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class represents static methods that are utilized during the course
+ * of invocation of a JAX-WS endpoint. This utility class is specifically
+ * meant to be used within the JAX-WS server-side flow.
+ *
+ */
+public class InvocationHelper {
+    
+    private static final Log log = LogFactory.getLog(InvocationHelper.class);
+    
+    /**
+     * This method is responsible for driving the method below. It will 
appropriately
+     * wrap the MessageContext in an EndpointInvocationContext. The 
MessageContext 
+     * instance MUST be a request MessageContext.
+     */
+    public static void callListenersForException(Throwable t, MessageContext 
context) {
+        EndpointInvocationContext eic = new EndpointInvocationContextImpl();
+        eic.setRequestMessageContext(context);
+        
eic.setInvocationListeners((List<InvocationListener>)context.getProperty(org.apache.axis2.jaxws.spi.Constants.INVOCATION_LISTENER_LIST));
+        callListenersForException(t, eic);
+    }
+    
+    /**
+     * This method is responsible for driving the InvocationListener instances'
+     * 'notifyOnException' method. This method will be called anytime that an
+     * exception occurs within the JAX-WS server side code flow.
+     */
+    public static void callListenersForException(Throwable t, 
EndpointInvocationContext eic) {
+        List<InvocationListener> invocationListeners = 
eic.getInvocationListeners();
+        Throwable returnException = null;
+        if(invocationListeners != null && !invocationListeners.isEmpty()) {
+            InvocationListenerBean bean = new InvocationListenerBean();
+            bean.setEndpointInvocationContext(eic);
+            bean.setState(eic.getResponseMessageContext() != null ? 
InvocationListenerBean.State.RESPONSE : 
+                InvocationListenerBean.State.REQUEST);
+            bean.setThrowable(t);
+            for(InvocationListener listener : invocationListeners) {
+                listener.notifyOnException(bean);
+            }
+        }
+    }
+    
+    /**
+     * This method will drive the call to the above methods. It will drive the 
call to
+     * the 'notifyOnException' methods of all InvocationListeners. After doing 
this, it
+     * will determine if another exception has been set as the mapped 
exception, and if
+     * so it will return this exception. Otherwise, null is returned.
+     */
+    public static Throwable determineMappedException(Throwable t, 
EndpointInvocationContext eic) {
+        Throwable returnThrowable = null;
+        callListenersForException(t, eic);
+        MessageContext requestContext = eic.getRequestMessageContext();
+        MessageContext responseContext = eic.getResponseMessageContext();
+        if(requestContext != null 
+                && 
+                
requestContext.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION)
 != null) {
+            returnThrowable = (Throwable) 
requestContext.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION);
+            if(log.isDebugEnabled()) {
+                log.debug("Setting mapped exception to: " + returnThrowable + 
" from request " +
+                               "MessageContext");
+            }
+        }
+        else if(responseContext != null
+                &&
+                
responseContext.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION)
 != null) {
+            returnThrowable = (Throwable) 
responseContext.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION);
+            if(log.isDebugEnabled()) {
+                log.debug("Setting mapped exception to: " + returnThrowable + 
" from response " +
+                                "MessageContext");
+            }
+        }
+        return returnThrowable;
+    }
+    
+    /**
+     * This method will drive the call to the above methods. It will drive the 
call to
+     * the 'notifyOnException' methods of all InvocationListeners. After doing 
this, it
+     * will determine if another exception has been set as the mapped 
exception, and if
+     * so it will return this exception. Otherwise, null is returned.
+     */
+    public static Throwable determineMappedException(Throwable t, 
MessageContext context) {
+        Throwable returnThrowable = null;
+        EndpointInvocationContext eic = new EndpointInvocationContextImpl();
+        eic.setRequestMessageContext(context);
+        
eic.setInvocationListeners((List<InvocationListener>)context.getProperty(org.apache.axis2.jaxws.spi.Constants.INVOCATION_LISTENER_LIST));
+        return determineMappedException(t, eic);
+    }
+
+}

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListener.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListener.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListener.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListener.java
 Sat Mar  8 08:49:09 2008
@@ -35,4 +35,14 @@
      */
     public void notify(InvocationListenerBean bean) throws Exception;
     
+    /**
+     * This method will be called anytime that an exception occurs
+     * within the JAX-WS server-side code flow. InvocationListener
+     * instances may change the exception being operated on by setting 
+     * the org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION
+     * property on either the request or response MessageContext. The
+     * value of the property should be an instance of Throwable.
+     */
+    public void notifyOnException(InvocationListenerBean bean);
+    
 }

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListenerBean.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListenerBean.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListenerBean.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/InvocationListenerBean.java
 Sat Mar  8 08:49:09 2008
@@ -28,6 +28,8 @@
  */
 public class InvocationListenerBean {
     
+    private Throwable throwable;
+    
     public InvocationListenerBean() {
         
     }
@@ -39,7 +41,8 @@
     
     public static enum State {
         REQUEST,
-        RESPONSE
+        RESPONSE,
+        EXCEPTION
     }
     
     private EndpointInvocationContext eic;
@@ -60,6 +63,14 @@
 
     public void setState(State state) {
         this.state = state;
+    }
+    
+    public void setThrowable(Throwable throwable) {
+        this.throwable = throwable;
+    }
+    
+    public Throwable getThrowable() {
+        return throwable;
     }
     
 }

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
 Sat Mar  8 08:49:09 2008
@@ -35,6 +35,7 @@
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.server.EndpointCallback;
 import org.apache.axis2.jaxws.server.EndpointInvocationContext;
+import org.apache.axis2.jaxws.server.InvocationHelper;
 import org.apache.axis2.jaxws.server.ServerConstants;
 import org.apache.axis2.jaxws.server.endpoint.Utils;
 import org.apache.axis2.jaxws.spi.Constants;
@@ -326,6 +327,15 @@
     }
     
     public MessageContext createFaultResponse(MessageContext request, Protocol 
p, Throwable t) {
+        
+        // call the InvocationListener instances before marshalling
+        // the fault into a message
+        // call the InvocationListener instances before marshalling
+        // the fault into a message
+        Throwable faultMessage = InvocationHelper.determineMappedException(t, 
request);
+        if(faultMessage != null) {
+            t = faultMessage;
+        }
         
         MethodMarshaller marshaller = getMethodMarshaller(p, 
request.getOperationDescription(),
                                                           request);

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
 Sat Mar  8 08:49:09 2008
@@ -23,6 +23,7 @@
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.server.EndpointCallback;
 import org.apache.axis2.jaxws.server.EndpointInvocationContext;
+import org.apache.axis2.jaxws.server.InvocationHelper;
 import org.apache.axis2.jaxws.server.InvocationListener;
 import org.apache.axis2.jaxws.server.InvocationListenerBean;
 import org.apache.axis2.jaxws.utility.ClassUtils;
@@ -145,6 +146,10 @@
                 } 
                 catch (Exception e) {
                     fault = ClassUtils.getRootCause(e);
+                    Throwable newFault = 
InvocationHelper.determineMappedException(fault, eic);
+                    if(newFault != null) {
+                        fault = newFault;
+                    }
                     faultThrown = true;
                 }
                 
@@ -153,6 +158,7 @@
                     if (log.isDebugEnabled()) {
                         log.debug("Invocation pattern was one way, work 
complete.");
                     }
+                    
                     responseReady(eic);
                     return null;
                 }

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
 Sat Mar  8 08:49:09 2008
@@ -38,6 +38,7 @@
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.server.EndpointCallback;
 import org.apache.axis2.jaxws.server.EndpointInvocationContext;
+import org.apache.axis2.jaxws.server.InvocationHelper;
 import org.apache.axis2.jaxws.server.ServerConstants;
 import org.apache.axis2.jaxws.utility.ClassUtils;
 import org.apache.axis2.jaxws.utility.ExecutorFactory;
@@ -367,6 +368,14 @@
         if (log.isDebugEnabled()) {
             log.debug("Create XMLFault for createFaultResponse");
         }
+        
+        // call the InvocationListener instances before marshalling
+        // the fault into a message
+        Throwable faultMessage = 
InvocationHelper.determineMappedException(fault, request);
+        if(faultMessage != null) {
+            fault = faultMessage;
+        }
+        
         Message m;
         try {
             EndpointDescription endpointDesc = 
request.getEndpointDescription();

Modified: 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/Constants.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/Constants.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/Constants.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/Constants.java
 Sat Mar  8 08:49:09 2008
@@ -56,6 +56,16 @@
     // one that was used to create the request
     public static final String CACHE_CLASSLOADER = "CACHE_CLASSLOADER";
     
+    // Value = List
+    // Usage: Store list of InvocationListener instances for a given 
request/response
+    public static final String INVOCATION_LISTENER_LIST = 
+        "org.apache.axis2.jaxws.spi.INVOCATION_LISTENER_LIST";
+    
+    // Value = Throwable
+    // Usage: Store Throwable type that should be used when constructing 
message to be
+    // sent back to the client
+    public static final String MAPPED_EXCEPTION = 
"org.apache.axis2.jaxws.spi.MAPPED_EXCEPTION";
+    
     /** Intentionally Private */
     private Constants() {
     }

Modified: 
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/JAXWSServerTests.java
URL: 
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/JAXWSServerTests.java?rev=635006&r1=635005&r2=635006&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/JAXWSServerTests.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/server/JAXWSServerTests.java
 Sat Mar  8 08:49:09 2008
@@ -19,6 +19,7 @@
 
 package org.apache.axis2.jaxws.server;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
@@ -111,6 +112,74 @@
         assertTrue((Boolean) response.getProperty("responseReady"));
     }
     
+    /**
+     * This will test that exceptions are properly handed down to the 
registered
+     * instances of InvocationListener objects.
+     */
+    public void testHandleException() {
+        EndpointController controller = new EndpointController();
+        EndpointCallback callback = new EndpointCallback();
+        EndpointInvocationContext eic = new EndpointInvocationContextImpl();
+        MessageContext request = new MessageContext();
+        eic.setRequestMessageContext(request);
+        eic.addInvocationListener(new TestInvocationListener());
+        Exception e = new Exception();
+        InvocationHelper.callListenersForException(e, eic);
+        
assertNotNull(request.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION));
+        
+        // now test that in the case this happens on a response, we set values 
+        // on the response message context
+        MessageContext response = new MessageContext();
+        eic.setResponseMessageContext(response);
+        eic.addInvocationListener(new TestInvocationListener());
+        e = new Exception();
+        InvocationHelper.callListenersForException(e, eic);
+        
assertNotNull(response.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION));
+        
+        // now test the InvocationHelper method that accepts a throwable and
+        // MessageContext
+        controller = new EndpointController();
+        callback = new EndpointCallback();
+        eic = new EndpointInvocationContextImpl();
+        request = new MessageContext();
+        eic.setRequestMessageContext(request);
+        eic.addInvocationListener(new TestInvocationListener());
+        e = new Exception();
+        
request.setProperty(org.apache.axis2.jaxws.spi.Constants.INVOCATION_LISTENER_LIST,
 
+                            eic.getInvocationListeners());
+        InvocationHelper.callListenersForException(e, request);
+        
assertNotNull(request.getProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION));
+        
+    }
+    
+    /**
+     * This test will verify that the 
InvocationHelper.determineMappedException method is 
+     * capable of correctly identifying the method to be thrown on the 
server-side.
+     */
+    public void testDetermineException() {
+        
+        // test the signature of determineMappedException that takes an 
EndpointInvocationContext
+        EndpointController controller = new EndpointController();
+        EndpointInvocationContext eic = new EndpointInvocationContextImpl();
+        MessageContext request = new MessageContext();
+        eic.setRequestMessageContext(request);
+        eic.addInvocationListener(new TestInvocationListener());
+        Throwable t = InvocationHelper.determineMappedException(new 
ArrayIndexOutOfBoundsException(), eic);
+        assertNotNull(t);
+        
assertTrue(t.getClass().getName().equals(NullPointerException.class.getName()));
+        
+        // test the signature of determineMappedException that takes a 
MessageContext
+        controller = new EndpointController();
+        request = new MessageContext();
+        List<InvocationListener> invocationListeners = new 
ArrayList<InvocationListener>();
+        invocationListeners.add(new TestInvocationListener());
+        
request.setProperty(org.apache.axis2.jaxws.spi.Constants.INVOCATION_LISTENER_LIST,
 
+                            invocationListeners);
+        t = InvocationHelper.determineMappedException(new 
ArrayIndexOutOfBoundsException(), request);
+        assertNotNull(t);
+        
assertTrue(t.getClass().getName().equals(NullPointerException.class.getName()));
+    }
+    
     static class TestInvocationProcessorFactory1 implements 
InvocationListenerFactory {
         public InvocationListener createInvocationListener(MessageContext 
context) {
             return new TestInvocationListener();
@@ -131,9 +200,22 @@
                 bean.getEndpointInvocationContext().getRequestMessageContext().
                     setProperty("requestReceived", true);
             }
-            else {
+            else if 
(bean.getState().equals(InvocationListenerBean.State.RESPONSE)){
                 
bean.getEndpointInvocationContext().getResponseMessageContext().
                     setProperty("responseReady", true);
+            }
+        }
+        
+        public void notifyOnException(InvocationListenerBean bean) {
+            if(bean.getState().equals(InvocationListenerBean.State.REQUEST)) {
+                bean.getEndpointInvocationContext().getRequestMessageContext().
+                    
setProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION, 
+                                new NullPointerException());
+            }
+            else if 
(bean.getState().equals(InvocationListenerBean.State.RESPONSE)){
+                
bean.getEndpointInvocationContext().getResponseMessageContext().
+                    
setProperty(org.apache.axis2.jaxws.spi.Constants.MAPPED_EXCEPTION, 
+                                new NullPointerException());
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to