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 ng...@apache.org on 2007/02/01 22:06:22 UTC

svn commit: r502357 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: core/util/MessageContextUtils.java server/dispatcher/JavaBeanDispatcher.java server/dispatcher/ProviderDispatcher.java

Author: ngallardo
Date: Thu Feb  1 13:06:20 2007
New Revision: 502357

URL: http://svn.apache.org/viewvc?view=rev&rev=502357
Log:
AXIS2-2079

- Added new call to JAX-WS MessageContextUtils
- Fixed name of existing MessageContextUtils.createMessageMessageContex()
- Changed JavaBeanDispatcher to use the new createFaultMessageContext()
- Additional minor syntactic/spacing clean-up.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.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/ProviderDispatcher.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java?view=diff&rev=502357&r1=502356&r2=502357
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java Thu Feb  1 13:06:20 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.axis2.jaxws.core.util;
 
-import javax.xml.ws.WebServiceException;
-
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.core.MessageContext;
@@ -30,16 +28,13 @@
 public class MessageContextUtils {
 
     /**
-     * Given a MessageContext, create a new MessageContext from there with the
-     * necessary information to make sure the new MessageContext is related
-     * to the existing one.  An example of a usage for this would be to create
-     * the MessageContext for a response based on the MessageContext of a 
-     * particular request. 
+     * Given a request MessageContext, create a new MessageContext from there with the necessary 
+     * information to make sure the new MessageContext is related to the existing one.  
      * 
      * @param mc - the MessageContext to use as the source
      * @return
      */
-    public static MessageContext createMessageMessageContext(MessageContext mc) {
+    public static MessageContext createResponseMessageContext(MessageContext mc) {
         try {
             org.apache.axis2.context.MessageContext sourceAxisMC = mc.getAxisMessageContext();
             
@@ -54,6 +49,25 @@
         } catch (AxisFault e) {
             throw ExceptionFactory.makeWebServiceException(e);
         }
+    }
+    
+    /**
+     * Given a request MessageContext, create a new MessageContext for a fault response.
+     * 
+     * @param mc
+     * @return
+     */
+    public static MessageContext createFaultMessageContext(MessageContext mc) {
+        try {
+            org.apache.axis2.context.MessageContext faultMC = MessageContextBuilder.createFaultMessageContext(
+                    mc.getAxisMessageContext(), null);
+            MessageContext jaxwsFaultMC = new MessageContext(faultMC);
+            return jaxwsFaultMC;
+        }
+        catch (AxisFault e) {
+            
+        }
+        return null;
     }
     
 }

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?view=diff&rev=502357&r1=502356&r2=502357
==============================================================================
--- 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 Thu Feb  1 13:06:20 2007
@@ -44,8 +44,9 @@
 public class JavaBeanDispatcher extends JavaDispatcher {
 
     private static final Log log = LogFactory.getLog(JavaBeanDispatcher.class);
+    private static final boolean debug = log.isDebugEnabled();
+    
     private EndpointDescription endpointDesc = null;
-    //private MethodMarshaller methodMarshaller = null;
     
     public JavaBeanDispatcher(Class implClass, Object serviceInstance) {
         super(implClass, serviceInstance);
@@ -56,7 +57,7 @@
      * @see org.apache.axis2.jaxws.server.EndpointDispatcher#invoke(org.apache.axis2.jaxws.core.MessageContext)
      */
     public MessageContext invoke(MessageContext mc) throws Exception {
-        if (log.isDebugEnabled()) {
+        if (debug) {
             log.debug("Preparing to invoke service endpoint implementation " +
                     "class: " + serviceImplClass.getName());
         }
@@ -72,18 +73,20 @@
         //the parameter data to invoke it with, so we use the instance and 
         //do the invoke.
         //Passing method input params to grab holder values, if any.
+        boolean faultThrown = false;
+        Throwable fault = null;
         Object response = null;
         try {
         	response = target.invoke(serviceInstance, methodInputParams);
         } catch (Exception e) {
-        	response = e;
-            if (log.isDebugEnabled()) {
+        	faultThrown = true;
+            fault = e;
+            if (debug) {
                 log.debug("Exception invoking a method of " + 
                         serviceImplClass.toString() + " of instance " +
                         serviceInstance.toString());
-                        
+                log.debug("Exception type thrown: " + e.getClass().getName());
                 log.debug("Method = " + target.toGenericString());
-              
                 for (int i=0; i<methodInputParams.length; i++) {
                     String value = (methodInputParams[i] == null) ? "null" :
                         methodInputParams[i].getClass().toString();
@@ -93,13 +96,13 @@
         }
         
         Message message = null;
-        // If the operation is one-way, then we can just return null because
-        // we cannot create a MessageContext for one-way responses.
         if(operationDesc.isOneWay()){
-        	return null;
+            // If the operation is one-way, then we can just return null because
+            // we cannot create a MessageContext for one-way responses.
+            return null;
         }
-        else if (response instanceof Throwable) {
-        	message = methodMarshaller.marshalFaultResponse((Throwable)response, mc.getOperationDescription(), 
+        else if (faultThrown) {
+        	message = methodMarshaller.marshalFaultResponse(fault, mc.getOperationDescription(), 
                         requestProtocol); // Send the response using the same protocol as the request
         }
         else if(target.getReturnType().getName().equals("void")){
@@ -111,8 +114,15 @@
                     requestProtocol); // Send the response using the same protocol as the request
         }
         
-        MessageContext responseMsgCtx = MessageContextUtils.createMessageMessageContext(mc);
-        responseMsgCtx.setMessage(message);
+        MessageContext responseMsgCtx = null;
+        if (faultThrown) {
+            responseMsgCtx = MessageContextUtils.createFaultMessageContext(mc);
+            responseMsgCtx.setMessage(message);
+        }
+        else {
+            responseMsgCtx = MessageContextUtils.createResponseMessageContext(mc);
+            responseMsgCtx.setMessage(message);            
+        }
         
         //Enable MTOM if necessary
         EndpointInterfaceDescription epInterfaceDesc = operationDesc.getEndpointInterfaceDescription();

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?view=diff&rev=502357&r1=502356&r2=502357
==============================================================================
--- 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 Thu Feb  1 13:06:20 2007
@@ -204,7 +204,7 @@
             }
             
             responseMsgCtx = MessageContextUtils.
-                createMessageMessageContext(mc);
+                createResponseMessageContext(mc);
             
             responseMsgCtx.setMessage(responseMsg);            
         }



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