Author: ips
Date: Fri May 20 16:15:42 2005
New Revision: 171170

URL: http://svn.apache.org/viewcvs?rev=171170&view=rev
Log:
log error and throw IllegalStateException if a Service method returns null

Modified:
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java?rev=171170&r1=171169&r2=171170&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
 Fri May 20 16:15:42 2005
@@ -54,8 +54,8 @@
 import java.util.Map;
 
 /**
- * Base class for platform-specific providers; also is a JAX-RPC Handler to 
make it
- * easier to port to different SOAP platforms.
+ * Base class for platform-specific providers; also is a JAX-RPC Handler to 
make it easier to port to different SOAP
+ * platforms.
  *
  * @author Ian Springer
  * @author Sal Campana
@@ -144,6 +144,7 @@
                 throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
                         "SOAP request Body contains more than one body element 
- this service requires that all SOAP requests contain at most one body 
element." );
             }
+            // TODO: refactor below if-else - too much code duplication
             if ( childElems.length == 0 )  // empty Body
             {
                 if ( methodNameFromAction != null )
@@ -321,7 +322,7 @@
     {
         boolean validateRequestXml = Boolean.valueOf( getHandlerOption( 
HANDLER_OPT_VALIDATE_REQUEST_XML, "true" ) )
                 .booleanValue();
-        if ( validateRequestXml && ! ( requestXBean instanceof XmlAnyTypeImpl 
) )
+        if ( validateRequestXml && !( requestXBean instanceof XmlAnyTypeImpl ) 
)
         {
             XmlOptions validateOptions = new XmlOptions();
             List errorList = new ArrayList();
@@ -460,21 +461,13 @@
             throws Exception
     {
         XmlObject responseXBean = null;
+        Object[] params = ( requestXBean != null ) ? new Object[]
+        {
+            requestXBean
+        } : new Object[0];
         try
         {
-            if ( requestXBean != null )
-            {
-                responseXBean = (XmlObject) serviceMethod.invoke( service,
-                        new Object[]
-                        {
-                            requestXBean
-                        } );
-            }
-            else
-            {
-                responseXBean = (XmlObject) serviceMethod.invoke( service,
-                        new Object[0] );
-            }
+            responseXBean = (XmlObject) serviceMethod.invoke( service, params 
);
         }
         catch ( InvocationTargetException ite )
         {
@@ -482,7 +475,13 @@
                     serviceMethod.getName(),
                     serviceClass.getName(),
                     ite.getCause() ) );
-            throw (Exception)ite.getCause();
+            throw (Exception) ite.getCause();
+        }
+        if ( responseXBean == null && serviceMethod.getReturnType() != 
void.class )
+        {
+            // don't allow service method to return null
+            LOG.error( "Service method " + serviceMethod.getName() + " in 
class " + serviceClass.getName() + " returned null - this is not allowed." );
+            throw new IllegalStateException();
         }
         return responseXBean;
     }
@@ -585,7 +584,8 @@
         if ( serviceMethod == null )  // method not found
         {
             QName bodyElemName = XmlBeanUtils.getName( param );
-            throw new FaultException( Soap1_1Constants.FAULT_CLIENT, 
MSG.getMessage( Keys.BAD_REQUEST_BODY_ELEMENT, toString( bodyElemName ) ) );
+            throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
+                    MSG.getMessage( Keys.BAD_REQUEST_BODY_ELEMENT, toString( 
bodyElemName ) ) );
         }
         LOG.debug( MSG.getMessage( Keys.FOUND_SERVICE_METHOD, 
serviceMethod.getName() ) );
         return serviceMethod;
@@ -628,13 +628,13 @@
         try
         {
             service = (WsrfService) serviceCtor.newInstance( new Object[]
-                    {
-                        resourceContext
-                    } );
+            {
+                resourceContext
+            } );
         }
         catch ( InvocationTargetException ite )
         {
-            throw (Exception)ite.getCause();
+            throw (Exception) ite.getCause();
         }
         return service;
     }



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

Reply via email to