[jbossws-commits] JBossWS SVN: r11728 - in stack/native/trunk/modules/core/src/main/java/org/jboss/ws: metadata/wsdl and 1 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Mar 8 09:50:23 EST 2010


Author: richard.opalka at jboss.com
Date: 2010-03-08 09:50:23 -0500 (Mon, 08 Mar 2010)
New Revision: 11728

Modified:
   stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
   stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java
   stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/metadata/ToolsAnnotationMetaDataBuilder.java
Log:
[JBWS-2953] fixing WebMethod detection to follow JAX-WS specification

Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java	2010-03-08 14:49:24 UTC (rev 11727)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java	2010-03-08 14:50:23 UTC (rev 11728)
@@ -87,6 +87,7 @@
 import org.jboss.ws.metadata.wsdl.WSDLBindingOperation;
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
 import org.jboss.ws.metadata.wsdl.WSDLMIMEPart;
+import org.jboss.ws.metadata.wsdl.WSDLUtils;
 import org.jboss.wsf.common.JavaUtils;
 import org.jboss.wsf.spi.binding.BindingCustomization;
 import org.jboss.wsf.spi.deployment.Endpoint;
@@ -586,11 +587,7 @@
    {
       String javaName = method.getName();
 
-      // Methods added by JBoss AOP will be marked as synthetic and should be skipped.
-      if (method.isSynthetic() == true)
-    	  return;
-      
-      // skip asnyc methods, they dont need meta data representation
+      // skip async methods, they dont need meta data representation
       if (method.getName().endsWith(Constants.ASYNC_METHOD_SUFFIX))
          return;
 
@@ -932,35 +929,18 @@
       epMetaData.clearOperations();
 
       // Process @WebMethod annotations
-      int webMethodCount = 0;
+      boolean webMethodFound = false;
       for (Method method : wsClass.getMethods())
       {
-         WebMethod annotation = method.getAnnotation(WebMethod.class);
-         boolean exclude = annotation != null && annotation.exclude();
-         if (!exclude && (annotation != null || wsClass.isInterface()))
+         if (WSDLUtils.isWebMethod(method))
          {
             processWebMethod(epMetaData, method);
-            webMethodCount++;
+            webMethodFound = true;
          }
       }
 
-      // @WebService should expose all inherited methods if @WebMethod is never specified
-      if (webMethodCount == 0 && !wsClass.isInterface())
-      {
-         for (Method method : wsClass.getMethods())
-         {
-            WebMethod annotation = method.getAnnotation(WebMethod.class);
-            boolean exclude = annotation != null && annotation.exclude();
-            if (!exclude && method.getDeclaringClass() != Object.class)
-            {
-               processWebMethod(epMetaData, method);
-               webMethodCount++;
-            }
-         }
-      }
-
-      if (webMethodCount == 0)
-         throw new WSException("No exposable methods found");
+      if (!webMethodFound)
+         throw new WSException("Exposable methods not found: " + wsClass);
    }
 
    protected void initWrapperGenerator(ClassLoader loader)

Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java	2010-03-08 14:49:24 UTC (rev 11727)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java	2010-03-08 14:50:23 UTC (rev 11728)
@@ -256,17 +256,11 @@
 
    /** Check if this method should be ignored
     */
-   public boolean checkIgnoreMethod(Method method)
+   public boolean checkIgnoreMethod(final Method method)
    {
-      String methodname = method.getName();
       if (ignoredMethods == null)
       {
          ignoredMethods = new ArrayList<String>();
-         Method[] objMethods = Object.class.getMethods();
-         for (int i = 0; i < objMethods.length; i++)
-         {
-            ignoredMethods.add(objMethods[i].getName());
-         }
          //Add the SessionBean Methods to the ignore list
          Method[] sbMethods = SessionBean.class.getMethods();
          for (int i = 0; i < sbMethods.length; i++)
@@ -275,16 +269,58 @@
          }
       }
 
-      boolean ignoreMethod = ignoredMethods.contains(methodname);
+      boolean ignoreMethod = ignoredMethods.contains(method.getName());
 
       // FIXME: This code is a duplicate, it should read from the UMDM
-      if (method.getDeclaringClass().isAnnotationPresent(WebService.class) && method.isAnnotationPresent(WebMethod.class) == false)
+      if (!isWebMethod(method))
          ignoreMethod = true;
 
       return ignoreMethod;
    }
-
+   
    /**
+    * The public, non-static or non-final methods that satisfy one of the following conditions:
+    * 1. They are annotated with the javax.jws.WebMethod annotation with the exclude element set to
+    * false or missing (since false is the default for this annotation element).
+    * 2. They are not annotated with the javax.jws.WebMethod annotation but their declaring class has a
+    * javax.jws.WebService annotation.
+    * @param method to process
+    * @return true if webmethod, false otherwise
+    */
+   public static boolean isWebMethod(final Method method)
+   {
+      if (!isWebMethodCandidate(method))
+         return false;
+         
+      final WebMethod webMethodAnnotation = method.getAnnotation(WebMethod.class);
+      
+      if (webMethodAnnotation != null)
+      {
+         return !webMethodAnnotation.exclude();
+      }
+      else
+      {
+         return method.getDeclaringClass().getAnnotation(WebService.class) != null;
+      }
+   }
+   
+   /**
+    * Only public, non-static and non-final methods are web method candidates.
+    *
+    * @param method to process
+    * @return true if satisfies modifier requirements, false otherwise
+    */
+   private static boolean isWebMethodCandidate(final Method method)
+   {
+      final int modifiers = method.getModifiers();
+      final boolean isPublic = Modifier.isPublic(modifiers);
+      final boolean isNotStatic = !Modifier.isStatic(modifiers);
+      final boolean isNotFinal = !Modifier.isFinal(modifiers);
+      
+      return isPublic && isNotStatic && isNotFinal;
+   }
+   
+   /**
     * Chop "PortType" at the end of the String
     * @param name
     * @return

Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/metadata/ToolsAnnotationMetaDataBuilder.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/metadata/ToolsAnnotationMetaDataBuilder.java	2010-03-08 14:49:24 UTC (rev 11727)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/metadata/ToolsAnnotationMetaDataBuilder.java	2010-03-08 14:50:23 UTC (rev 11728)
@@ -75,7 +75,7 @@
    private void generateOperationMetaData()
    {
       //    Generate the Operation Metadata
-      Method[] marr = endpoint.getDeclaredMethods();
+      Method[] marr = endpoint.getMethods();
       if( marr != null)
       {
          int len = Array.getLength(marr);



More information about the jbossws-commits mailing list