You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ba...@apache.org on 2006/11/07 17:55:36 UTC

svn commit: r472164 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: description/ description/impl/ marshaller/impl/

Author: barrettj
Date: Tue Nov  7 08:55:35 2006
New Revision: 472164

URL: http://svn.apache.org/viewvc?view=rev&rev=472164
Log:
AXIS2-1641
Contributed by Mike Rheinheimer

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/FaultDescription.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/FaultDescriptionImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/FaultDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/FaultDescription.java?view=diff&rev=472164&r1=472163&r2=472164
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/FaultDescription.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/FaultDescription.java Tue Nov  7 08:55:35 2006
@@ -44,7 +44,9 @@
  */
 public interface FaultDescription {
     public OperationDescription getOperationDescription();
-    public String getBeanName();
+    public String getFaultBean();
+    public String getName();
+    public String getTargetNamespace();
     public String getExceptionClassName();
     
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/FaultDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/FaultDescriptionImpl.java?view=diff&rev=472164&r1=472163&r2=472164
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/FaultDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/FaultDescriptionImpl.java Tue Nov  7 08:55:35 2006
@@ -18,27 +18,48 @@
 
 package org.apache.axis2.jaxws.description.impl;
 
+import java.lang.reflect.Constructor;
+import java.util.StringTokenizer;
+
 import javax.xml.ws.WebFault;
 
 import org.apache.axis2.jaxws.description.FaultDescription;
 import org.apache.axis2.jaxws.description.FaultDescriptionJava;
 import org.apache.axis2.jaxws.description.FaultDescriptionWSDL;
 import org.apache.axis2.jaxws.description.OperationDescription;
+
 /**
  * @see ../FaultDescription
  *
  */
-// TODO: This class is not implemented yet or used from OperationDescription
+
+
 class FaultDescriptionImpl implements FaultDescription, FaultDescriptionJava, FaultDescriptionWSDL {
     
-    private String exceptionClassName;
-    private String beanName;
+    private Class exceptionClass;
     private WebFault annotation;
     private OperationDescription parent;
+    
+    private String name = "";  // WebFault.name
+    private String faultBean = "";  // WebFault.faultBean
+    private String targetNamespace = ""; // WebFault.targetNamespace
+    
+    private static final String FAULT = "Fault";
 
-    public FaultDescriptionImpl(String exceptionClassName, String beanName, WebFault annotation, OperationDescription parent) {
-        this.exceptionClassName = exceptionClassName;
-        this.beanName = beanName;
+
+    /**
+     * The FaultDescriptionImpl class will only be used to describe exceptions declared to be thrown by a service that has
+     * a WebFault annotation.  No generic exception should ever have a FaultDescription associated with it.  It is the
+     * responsibility of the user of the FaultDescriptionImpl class to avoid instantiating this object for non-annotated
+     * generic exceptions.
+     * 
+     * @param exceptionClass an exception declared to be thrown by the service on which this FaultDescription may apply.
+     * @param beanName fully qualified package+classname of the bean associated with this exception
+     * @param annotation the WebFault annotation object on this exception class
+     * @param parent the OperationDescription that is the parent of this FaultDescription
+     */
+    public FaultDescriptionImpl(Class exceptionClass, WebFault annotation, OperationDescription parent) {
+        this.exceptionClass = exceptionClass;
         this.annotation = annotation;
         this.parent = parent;
     }
@@ -47,16 +68,136 @@
         return annotation;
     }
 
-    public String getBeanName() {
-        return beanName;
+    public String getFaultBean() {
+        if (faultBean.length() > 0) {
+            return faultBean;
+        }
+        else if (annotation.faultBean().length() > 0) {
+            faultBean = annotation.faultBean();
+        }
+        else {
+            /*
+             * we need to figure out a default.  The JAXWS spec
+             * has no defaults defined, except what can be interpreted
+             * from 2.5, 2.8, 2.8.1, and 7.2
+             *
+             * specifically, section 2.5 says "using the mapping
+             * described in section 2.4."
+             * 
+             * I have a better way:
+             * The exception class defined by the JAXWS spec has two constructors where the second parameter
+             * of each is the faultBean.  Let's see if we can figure what the faultBean is from that:
+             */
+
+            try {
+                Constructor[] cons = exceptionClass.getConstructors();
+                Class[] parms = cons[0].getParameterTypes();
+                faultBean = parms[1].getCanonicalName();
+            } catch (Exception e) {
+                /* 
+                 * if faultBean is still not set, then something is wrong with the exception
+                 * class that the code generators generated, or someone instantiated a FaultDescription
+                 * object for a generic exception.
+                 *
+                 * TODO log it?  I don't think we need to worry about throwing an exception here, as we're just
+                 * doing a best-effort to determine the faultBean name.  If the try{} fails, something is really
+                 * messed up in the generated code anyway, and I suspect nothing would work right.
+                 */
+            }
+                
+            // If all else fails, this might get us what we want:
+            if ((faultBean == null) || (faultBean.length() == 0))
+                faultBean = getOperationDescription().getRequestWrapperClassName().toString() + FAULT;
+
+        }
+        return faultBean;
+    }
+
+    public String getName() {
+        if (name.length() > 0) {
+            return name;
+        }
+        else if (annotation.name().length() > 0) {
+            name = annotation.name();
+        }
+        else {
+            // need to figure out a default.  Let's use the logic in getFaultBean()
+            name = getSimpleName(getFaultBean());
+        }
+        return name;
+    }
+
+    public String getTargetNamespace() {
+        if (targetNamespace.length() > 0) {
+            return targetNamespace;
+        }
+        else if (annotation.targetNamespace().length() > 0) {
+            targetNamespace = annotation.targetNamespace();
+        }
+        else {
+            // need to figure out a default.  Let's use the logic in getFaultBean() and make a namespace out of the package
+            
+            targetNamespace = makeNamespace(getFaultBean());
+        }
+        return targetNamespace;
     }
 
     public String getExceptionClassName() {
-        return exceptionClassName;
+        // no need for defaults here.  The exceptionClass stored in this
+        // FaultDescription object is one that has been declared to be
+        // thrown from the service method
+        return exceptionClass.getCanonicalName();
     }
 
     public OperationDescription getOperationDescription() {
         return parent;
+    }
+    
+    /**
+     * utility method to get the last token in a "."-delimited package+classname string
+     * @return
+     */
+    private static String getSimpleName(String in) {
+        if (in == null || in.length() == 0) {
+            return in;
+        }
+        String out = null;
+        StringTokenizer tokenizer = new StringTokenizer(in, ".");
+        if (tokenizer.countTokens() == 0)
+            out = in;
+        else {
+            while (tokenizer.hasMoreTokens()) {
+                out = tokenizer.nextToken();
+            }
+        }
+        return out;
+    }
+    
+    private static String makeNamespace(String packageAndClassname) {
+        if (packageAndClassname == null || packageAndClassname.length() == 0) {
+            return null;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(packageAndClassname, ".");
+        String[] tokens;
+        if (tokenizer.countTokens() == 0) {
+            tokens = new String[0];
+        } else {
+            // -1 to skip the classname
+            tokens = new String[tokenizer.countTokens()-1];
+            // -2 to skip the classname
+            for (int i=tokenizer.countTokens()-2; i >= 0; i--) {
+                tokens[i] = tokenizer.nextToken();
+            }
+        }
+        StringBuffer namespace = new StringBuffer("http://");
+        String dot = "";
+        for (int i=0; i<tokens.length; i++) {
+            if (i==1)
+                dot = ".";
+            namespace.append(dot+tokens[i]);
+        }
+        namespace.append('/');
+        return namespace.toString();
     }
     
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java?view=diff&rev=472164&r1=472163&r2=472164
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java Tue Nov  7 08:55:35 2006
@@ -358,7 +358,7 @@
             for(Class wfClass:webFaultClasses) {
                 for (Annotation anno:wfClass.getAnnotations()) {
                     if (anno.annotationType() == WebFault.class) {
-                        buildFaultList.add(new FaultDescriptionImpl(wfClass.getCanonicalName(), ((WebFault)anno).faultBean(), (WebFault)anno, this));
+                        buildFaultList.add(new FaultDescriptionImpl(wfClass, (WebFault)anno, this));
                     }
                 }
             }
@@ -704,7 +704,7 @@
     
     public FaultDescription resolveFaultByFaultBeanName(String faultBeanName) {
         for(FaultDescription fd: faultDescriptions) {
-            if (faultBeanName.equals(fd.getBeanName()))
+            if (faultBeanName.equals(fd.getFaultBean()))
                 return fd;
         }
         return null;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java?view=diff&rev=472164&r1=472163&r2=472164
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java Tue Nov  7 08:55:35 2006
@@ -122,8 +122,8 @@
 			} else {
                 for(FaultDescription fd: operationDesc.getFaultDescriptions()) {
                     for (Block block: blocks) {
-                        Object obj = createFaultBusinessObject(loadClass(fd.getBeanName()), block);
-                        if (obj.getClass().getName().equals(fd.getBeanName())) {
+                        Object obj = createFaultBusinessObject(loadClass(fd.getFaultBean()), block);
+                        if (obj.getClass().getName().equals(fd.getFaultBean())) {
                             // create the exception we actually want to throw
                             Class exceptionclass = loadClass(fd.getExceptionClassName());
                             return createCustomException(xmlfault.getReason().getText(), exceptionclass, obj);
@@ -161,7 +161,7 @@
             if (fd != null) {
             	Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
             	Object faultBean = getFaultInfo.invoke(t, null);
-            	Class faultClazz = loadClass(fd.getBeanName());
+            	Class faultClazz = loadClass(fd.getFaultBean());
             	JAXBBlockContext context = createJAXBBlockContext(faultClazz);
             	detailBlocks.add(createJAXBBlock(faultBean, context));
                 text = t.getMessage();



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