cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r536470 - in /incubator/cxf/trunk/tools: common/src/main/java/org/apache/cxf/tools/common/ javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/ javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ j...
Date Wed, 09 May 2007 09:53:38 GMT
Author: mmao
Date: Wed May  9 02:53:35 2007
New Revision: 536470

URL: http://svn.apache.org/viewvc?view=rev&rev=536470
Log:
CXF-437 Java->WSDL doesn't generate Fault beans


Added:
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/BeanGenerator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBean.java
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/GreeterFault.java
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/PingMeFault.java
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGeneratorTest.java
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/DBServiceFaultBean.java.source
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/FaultDetail.java.source
    incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBeanTest.java
Modified:
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGenerator.java
    incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java?view=diff&rev=536470&r1=536469&r2=536470
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
Wed May  9 02:53:35 2007
@@ -165,13 +165,19 @@
 
         String rtn = result.toString();
 
-        //remove Apache header
-        int headerIndexStart = rtn.indexOf("<!--");
-        int headerIndexEnd = rtn.indexOf("-->");
+        rtn = ignoreTokens(rtn, "<!--", "-->");
+        rtn = ignoreTokens(rtn, "/*", "*/");
+        return rtn;
+    }
+
+    private String ignoreTokens(final String contents, final String startToken, final String
endToken) {
+        String rtn = contents;
+        int headerIndexStart = rtn.indexOf(startToken);
+        int headerIndexEnd = rtn.indexOf(endToken);
         if (headerIndexStart != -1 && headerIndexEnd != -1 && headerIndexStart
< headerIndexEnd) {
-            rtn = rtn.substring(0, headerIndexStart - 1) + rtn.substring(headerIndexEnd +
4);
+            rtn = rtn.substring(0, headerIndexStart - 1)
+                + rtn.substring(headerIndexEnd + endToken.length() + 1);
         }
-
         return rtn;
     }
 }

Added: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/BeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/BeanGenerator.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/BeanGenerator.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/BeanGenerator.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.common.VelocityGenerator;
+import org.apache.cxf.tools.common.model.JavaClass;
+import org.apache.cxf.tools.java2wsdl.generator.AbstractGenerator;
+import org.apache.cxf.tools.util.Compiler;
+import org.apache.cxf.tools.util.FileWriterUtil;
+
+public class BeanGenerator extends AbstractGenerator<File> {
+    private static final String TEMPLATE = "org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm";
+    private File compileToDir;
+
+    public void setCompileToDir(File f) {
+        compileToDir = f;
+    }
+    
+    protected Collection<JavaClass> generateBeanClasses(final ServiceInfo service)
{
+        return null;
+    }
+    
+    public File generate(final File sourcedir) {
+        File dir = getOutputBase();
+        if (dir == null) {
+            dir = sourcedir;
+        }
+        if (dir == null) {
+            dir = new File("./");
+        }
+        Collection<JavaClass> wrapperClasses = generateBeanClasses(getServiceModel());
+
+        if (!wrapperClasses.isEmpty()) {
+            generateAndCompile(wrapperClasses, dir);
+        }
+
+        return dir;
+    }
+
+    public void generateAndCompile(Collection<JavaClass> wrapperClasses, File dir)
{
+        VelocityGenerator generator = new VelocityGenerator();
+        generator.setBaseDir(dir.toString());
+
+        List<File> generatedFiles = new ArrayList<File>();
+        try {
+            for (JavaClass wrapperClass : wrapperClasses) {
+                generator.setCommonAttributes();
+                generator.setAttributes("bean", wrapperClass);
+            
+                File file = generator.parseOutputName(wrapperClass.getPackageName(),
+                                                      wrapperClass.getName());
+                generatedFiles.add(file);
+            
+                generator.doWrite(TEMPLATE, FileWriterUtil.getWriter(file));
+            
+                generator.clearAttributes();
+            }
+        
+
+            if (compileToDir != null) {
+                //compile the classes
+                Compiler compiler = new Compiler();
+
+                List<String> files = new ArrayList<String>(generatedFiles.size());
+                for (File file : generatedFiles) {
+                    files.add(file.getAbsolutePath());
+                }
+                if (!compiler.compileFiles(files.toArray(new String[files.size()]),
+                                           compileToDir)) {
+                    //TODO - compile issue
+                }
+
+            }
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGenerator.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
+
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import javax.wsdl.Fault;
+
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.common.model.JavaClass;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.FaultBean;
+
+
+public final class FaultBeanGenerator extends BeanGenerator {
+
+    private String getSEIPackage(final Method method) {
+        return method.getDeclaringClass().getPackage().getName();
+    }
+    
+    protected Collection<JavaClass> generateBeanClasses(final ServiceInfo serviceInfo)
{
+        Set<Class> exceptionClasses = new HashSet<Class>();
+        String seiPackageName = null;
+        for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
+            Method method = (Method) op.getProperty("operation.method");
+            exceptionClasses.addAll(getExceptionClasses(method));
+            seiPackageName = getSEIPackage(method);
+        }
+
+        Collection<JavaClass> faultBeanClasses = new HashSet<JavaClass>();
+        String defaultPackage = seiPackageName + ".jaxws";
+        FaultBean bean = new FaultBean();
+        for (Class clz : exceptionClasses) {
+            faultBeanClasses.add(bean.transform(clz, defaultPackage));
+        }
+
+        return faultBeanClasses;
+    }
+
+    protected Set<Class> getExceptionClasses(final Method method) {
+        Set<Class> exps = new HashSet<Class>();
+        final Class[] exceptionClasses = method.getExceptionTypes();
+        for (int i = 0; i < exceptionClasses.length; i++) {
+            boolean exclude = false;
+            Class exClazz = exceptionClasses[i];
+            
+            if (exClazz.equals(Exception.class) 
+                || Fault.class.isAssignableFrom(exClazz)
+                || exClazz.equals(RuntimeException.class)
+                || exClazz.equals(Throwable.class)
+                || exClazz.equals(RemoteException.class)) {
+                continue;
+            }
+
+            Method[] expMethods = exClazz.getMethods();
+            for (Method expMethod : expMethods) {
+                if ("getFaultInfo".equals(expMethod.getName())) {
+                    exclude = true;
+                    break;
+                }
+            }
+            if (exclude) {
+                continue;
+            }
+            exps.add(exClazz);
+        }
+        return exps;
+    }
+}

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGenerator.java?view=diff&rev=536470&r1=536469&r2=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGenerator.java
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGenerator.java
Wed May  9 02:53:35 2007
@@ -19,41 +19,19 @@
 
 package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+
+import java.util.Collection;
+import java.util.HashSet;
 
 import org.apache.cxf.service.model.OperationInfo;
 import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.tools.common.VelocityGenerator;
 import org.apache.cxf.tools.common.model.JavaClass;
-import org.apache.cxf.tools.java2wsdl.generator.AbstractGenerator;
 import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.RequestWrapper;
 import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.ResponseWrapper;
-import org.apache.cxf.tools.util.Compiler;
-import org.apache.cxf.tools.util.FileWriterUtil;
-
-public final class WrapperBeanGenerator extends AbstractGenerator<File> {
-    private File compileToDir;
-    
-    public File generate(final File sourcedir) {
-        File dir = getOutputBase();
-        if (dir == null) {
-            dir = sourcedir;
-        }
-        if (dir == null) {
-            dir = new File("./");
-        }
-        generateWrapperBeanClasses(getServiceModel(), dir);
-        return dir;
-    }
-    
-    public void setCompileToDir(File f) {
-        compileToDir = f;
-    }
 
-    private void generateWrapperBeanClasses(final ServiceInfo serviceInfo, final File dir)
{
-        List<JavaClass> wrapperClasses = new ArrayList<JavaClass>();
+public final class WrapperBeanGenerator extends BeanGenerator {
+    protected Collection<JavaClass> generateBeanClasses(final ServiceInfo serviceInfo)
{
+        Collection<JavaClass> wrapperClasses = new HashSet<JavaClass>();
         
         for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
             if (op.getUnwrappedOperation() != null) {
@@ -77,50 +55,6 @@
                 }
             }
         }
-
-        if (wrapperClasses.isEmpty()) {
-            return;
-        }
-
-        String templateName = "org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm";
-        VelocityGenerator generator = new VelocityGenerator();
-        generator.setBaseDir(dir.toString());
-
-        List<File> generatedFiles = new ArrayList<File>();
-        try {
-            for (JavaClass wrapperClass : wrapperClasses) {
-                generator.setCommonAttributes();
-                generator.setAttributes("bean", wrapperClass);
-            
-                File file = generator.parseOutputName(wrapperClass.getPackageName(),
-                                                      wrapperClass.getName());
-                generatedFiles.add(file);
-            
-                generator.doWrite(templateName, FileWriterUtil.getWriter(file));
-            
-                generator.clearAttributes();
-            }
-        
-
-            if (compileToDir != null) {
-                //compile the classes
-                Compiler compiler = new Compiler();
-
-                List<String> files = new ArrayList<String>(generatedFiles.size());
-                for (File file : generatedFiles) {
-                    files.add(file.getAbsolutePath());
-                }
-                if (!compiler.compileFiles(files.toArray(new String[files.size()]),
-                                           compileToDir)) {
-                    //TODO - compile issue
-                }
-
-            }
-            
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        
+        return wrapperClasses;
     }
-    
 }

Modified: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm?view=diff&rev=536470&r1=536469&r2=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
(original)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
Wed May  9 02:53:35 2007
@@ -33,8 +33,9 @@
 #end
 
 public class $bean.Name {
+
 #foreach ($field in $bean.Fields)
-    $field.Annotation
+#if($field.Annotation.length() > 0)$field.Annotation#end
     private $field.Type $field.Name;
 #end
 

Added: incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBean.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBean.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBean.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebFault;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.tools.common.model.JavaClass;
+import org.apache.cxf.tools.common.model.JavaField;
+import org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator;
+import org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass;
+import org.apache.cxf.tools.util.URIParserUtil;
+
+public final class FaultBean {
+    private static final String[] EXCLUDED_GETTER = new String[] {"getCause",
+                                                                  "getLocalizedMessage",
+                                                                  "getStackTrace",
+                                                                  "getClass"};
+
+    
+    private String getWebFaultBean(final Class<?> exceptionClass) {
+        WebFault fault = exceptionClass.getAnnotation(WebFault.class);
+        if (fault == null) {
+            return null;
+        }
+        return fault.faultBean();
+    }
+
+    private boolean isWebFaultAbsent(final Class exceptionClass) {
+        return StringUtils.isEmpty(getWebFaultBean(exceptionClass));
+    }
+    
+    public WrapperBeanClass transform(final Class exceptionClass, final String defaultPackage)
{
+        WrapperBeanClass jClass = new WrapperBeanClass();
+        if (isWebFaultAbsent(exceptionClass)) {
+            jClass.setName(exceptionClass.getSimpleName() + "Bean");
+            jClass.setPackageName(defaultPackage);
+        } else {
+            jClass.setFullClassName(getWebFaultBean(exceptionClass));
+        }
+
+        buildBeanFields(exceptionClass, jClass);
+
+        jClass.setElementName(new QName(URIParserUtil.getNamespace(exceptionClass.getPackage().getName()),
+                                        exceptionClass.getSimpleName()));
+        jClass.annotate(new WrapperBeanAnnotator());
+        
+        return jClass;
+    }
+
+    private String getFieldName(final Method method) {
+        String name = method.getName().substring(3);
+        char chars[] = name.toCharArray();
+        chars[0] = Character.toLowerCase(chars[0]);
+        return new String(chars);
+    }
+
+    private boolean isIncludedGetter(final Method method) {
+        return method.getName().startsWith("get")
+            && !Arrays.asList(EXCLUDED_GETTER).contains(method.getName());
+    }
+    
+    private void buildBeanFields(final Class exceptionClass, final JavaClass jClass) {
+        for (Method method : exceptionClass.getMethods()) {
+            if (isIncludedGetter(method)) {
+                JavaField field = new JavaField(getFieldName(method),
+                                                method.getReturnType().getName(),
+                                                "");
+                field.setOwner(jClass);
+                jClass.addField(field);
+                jClass.appendGetter(field);
+                jClass.appendSetter(field);
+            }
+        }
+    }
+    
+}

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/GreeterFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/GreeterFault.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/GreeterFault.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/GreeterFault.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.fortest.jaxws.rpc;
+ 
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.Style;
+
+@WebService(name = "Hello", targetNamespace = "http://cxf.apache.org/")
+@SOAPBinding(style = Style.RPC)
+public interface GreeterFault {
+    @WebMethod
+    void pingMeFault() throws PingMeFault;
+}

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/PingMeFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/PingMeFault.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/PingMeFault.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/fortest/jaxws/rpc/PingMeFault.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.fortest.jaxws.rpc;
+
+import javax.xml.ws.WebFault;
+
+
+@WebFault(name = "faultDetail",
+          targetNamespace = "http://apache.org/hello_world_soap_http/types",
+          faultBean = "org.apache.cxf.tools.fortest.jaxws.rpc.types.FaultDetail")
+
+public class PingMeFault extends Exception {
+
+    private int code;
+
+    public int getCode() {
+        return this.code;
+    }
+}

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGeneratorTest.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGeneratorTest.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/FaultBeanGeneratorTest.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.generator.wsdl11;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.common.ProcessorTestBase;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.java2wsdl.processor.JavaToProcessor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FaultBeanGeneratorTest extends ProcessorTestBase {
+    JavaToProcessor processor = new JavaToProcessor();
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        processor.setEnvironment(env);
+    }
+
+    @After
+    public void tearDown() {
+        super.tearDown();
+    }
+    
+    private ServiceInfo getServiceInfo() {
+        return processor.getServiceBuilder().build();
+    }
+    
+    @Test
+    public void testGenFaultBean() throws Exception {
+        String testingClass = "org.apache.cxf.tools.fortest.cxf523.Database";
+        env.put(ToolConstants.CFG_CLASSNAME, testingClass);
+        
+        FaultBeanGenerator generator = new FaultBeanGenerator();
+        generator.setServiceModel(getServiceInfo());
+        
+        generator.generate(output);
+
+        String pkgBase = "org/apache/cxf/tools/fortest/cxf523/jaxws";
+        assertEquals(1, new File(output, pkgBase).listFiles().length);
+        File faultBeanClass = new File(output, pkgBase + "/DBServiceFaultBean.java");
+        assertTrue(faultBeanClass.exists());
+
+        String expectedFile = getClass().getResource("expected/DBServiceFaultBean.java.source").getFile();
+        assertFileEquals(new File(expectedFile), faultBeanClass);
+    }
+
+    @Test
+    public void testGenFaultBeanWithCustomization() throws Exception {
+        String testingClass = "org.apache.cxf.tools.fortest.jaxws.rpc.GreeterFault";
+        env.put(ToolConstants.CFG_CLASSNAME, testingClass);
+        
+        FaultBeanGenerator generator = new FaultBeanGenerator();
+        generator.setServiceModel(getServiceInfo());
+        
+        generator.generate(output);
+
+        String pkgBase = "org/apache/cxf/tools/fortest/jaxws/rpc/types";
+        assertEquals(1, new File(output, pkgBase).listFiles().length);
+        File faultBeanClass = new File(output, pkgBase + "/FaultDetail.java");
+        assertTrue(faultBeanClass.exists());
+
+        String expectedFile = getClass().getResource("expected/FaultDetail.java.source").getFile();
+        assertFileEquals(new File(expectedFile), faultBeanClass);
+    }
+
+    @Test
+    public void testGetExceptionClasses() throws Exception {
+        Class seiClass = Class.forName("org.apache.hello_world.Greeter");
+        FaultBeanGenerator generator = new FaultBeanGenerator();
+        Set<Class> classes = new HashSet<Class>();
+        for (Method method : seiClass.getMethods()) {
+            classes.addAll(generator.getExceptionClasses(method));
+        }
+        assertEquals(0, classes.size());
+
+        classes.clear();
+        
+        seiClass = Class.forName("org.apache.cxf.tools.fortest.cxf523.Database");
+        for (Method method : seiClass.getMethods()) {
+            classes.addAll(generator.getExceptionClasses(method));
+        }
+        assertEquals(1, classes.size());
+        assertEquals("org.apache.cxf.tools.fortest.cxf523.DBServiceFault",
+                     classes.iterator().next().getName());
+    }
+}

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/DBServiceFaultBean.java.source
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/DBServiceFaultBean.java.source?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/DBServiceFaultBean.java.source
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/DBServiceFaultBean.java.source
Wed May  9 02:53:35 2007
@@ -0,0 +1,33 @@
+
+package org.apache.cxf.tools.fortest.cxf523.jaxws;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * This class was generated by the CXF 2.0-incubator-SNAPSHOT
+ * Wed May 09 17:18:10 CST 2007
+ * Generated source version: 2.0-incubator-SNAPSHOT
+ * 
+ */
+
+@XmlRootElement(namespace = "http://cxf523.fortest.tools.cxf.apache.org/", name = "DBServiceFault")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(namespace = "http://cxf523.fortest.tools.cxf.apache.org/", name = "DBServiceFault")
+
+public class DBServiceFaultBean {
+
+    private java.lang.String message;
+
+    public java.lang.String getMessage ()     {
+	           return this.message;
+        }
+
+    public void setMessage (   java.lang.String newMessage  )     {
+	           this.message = newMessage;
+        }
+
+}
+

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/FaultDetail.java.source
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/FaultDetail.java.source?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/FaultDetail.java.source
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/expected/FaultDetail.java.source
Wed May  9 02:53:35 2007
@@ -0,0 +1,42 @@
+
+package org.apache.cxf.tools.fortest.jaxws.rpc.types;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * This class was generated by the CXF 2.0-incubator-SNAPSHOT
+ * Wed May 09 17:04:04 CST 2007
+ * Generated source version: 2.0-incubator-SNAPSHOT
+ * 
+ */
+
+@XmlRootElement(namespace = "http://rpc.jaxws.fortest.tools.cxf.apache.org/", name = "PingMeFault")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(namespace = "http://rpc.jaxws.fortest.tools.cxf.apache.org/", name = "PingMeFault")
+
+public class FaultDetail {
+
+    private int code;
+    private java.lang.String message;
+
+    public int getCode ()     {
+	           return this.code;
+        }
+
+    public void setCode (   int newCode  )     {
+	           this.code = newCode;
+        }
+
+    public java.lang.String getMessage ()     {
+	           return this.message;
+        }
+
+    public void setMessage (   java.lang.String newMessage  )     {
+	           this.message = newMessage;
+        }
+
+}
+

Added: incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBeanTest.java?view=auto&rev=536470
==============================================================================
--- incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBeanTest.java
(added)
+++ incubator/cxf/trunk/tools/javato/src/test/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/FaultBeanTest.java
Wed May  9 02:53:35 2007
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
+
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+import org.apache.cxf.tools.common.model.JavaField;
+import org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass;
+import org.junit.Test;
+
+public class FaultBeanTest extends TestCase {
+
+    @Test
+    public void testTransform() throws Exception {
+        Class faultClass = Class.forName("org.apache.cxf.tools.fortest.cxf523.DBServiceFault");
+        FaultBean bean = new FaultBean();
+        WrapperBeanClass beanClass = bean.transform(faultClass, "org.apache.cxf.tools.fortest.cxf523.jaxws");
+
+        assertNotNull(beanClass);
+        assertEquals("DBServiceFaultBean", beanClass.getName());
+        assertEquals("org.apache.cxf.tools.fortest.cxf523.jaxws", beanClass.getPackageName());
+
+        assertEquals(1, beanClass.getFields().size());
+
+        JavaField field = beanClass.getFields().get(0);
+        assertEquals("message", field.getName());
+        assertEquals("java.lang.String", field.getType());
+
+        QName qname = beanClass.getElementName();
+        assertEquals("DBServiceFault", qname.getLocalPart());
+        assertEquals("http://cxf523.fortest.tools.cxf.apache.org/", qname.getNamespaceURI());
+    }
+}



Mime
View raw message