cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r573528 - in /incubator/cxf/trunk/tools/javato/ws/src: main/java/org/apache/cxf/tools/java2wsdl/processor/ main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/...
Date Fri, 07 Sep 2007 10:17:19 GMT
Author: ema
Date: Fri Sep  7 03:17:18 2007
New Revision: 573528

URL: http://svn.apache.org/viewvc?rev=573528&view=rev
Log:
* Add function to check if the input class carries WebService Annotation for javaws frontend
* Add function to check if the parameter or return type directly or indirectly implemented
java.rmi.Remote interface for javaws frontend
 

Added:
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JAXWSFrontEndProcessor.java
Removed:
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ServiceInfoToJavaProcessor.java
Modified:
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/Messages.properties
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/generator/JaxwsClientGenerator.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/WSDLGeneratorFactoryTest.java

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java?rev=573528&r1=573527&r2=573528&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/JavaToWSDLProcessor.java
Fri Sep  7 03:17:18 2007
@@ -146,9 +146,9 @@
         context.put(Class.class, clz);
         if (clz.isInterface()) {
             context.put(ToolConstants.GEN_FROM_SEI, Boolean.TRUE);
-            context.put(ToolConstants.SEI_CLASS, clz);
+            context.put(ToolConstants.SEI_CLASS, clz.getName());
         } else {
-            context.put(ToolConstants.IMPL_CLASS, clz);
+            context.put(ToolConstants.IMPL_CLASS, clz.getName());
             if (clz.getInterfaces().length == 1) {
                 context.put(ToolConstants.SEI_CLASS, clz.getInterfaces()[0].getName());
             }

Added: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JAXWSFrontEndProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JAXWSFrontEndProcessor.java?rev=573528&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JAXWSFrontEndProcessor.java
(added)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/JAXWSFrontEndProcessor.java
Fri Sep  7 03:17:18 2007
@@ -0,0 +1,195 @@
+/**
+ * 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.GenericArrayType;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jws.WebService;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.common.Processor;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolContext;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.common.model.JavaException;
+import org.apache.cxf.tools.common.model.JavaInterface;
+import org.apache.cxf.tools.common.model.JavaMethod;
+import org.apache.cxf.tools.common.model.JavaModel;
+import org.apache.cxf.tools.common.model.JavaParameter;
+import org.apache.cxf.tools.common.model.JavaReturn;
+import org.apache.cxf.tools.common.model.JavaType.Style;
+import org.apache.cxf.tools.java2ws.util.JavaFirstUtil;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.AbstractJaxwsGenerator;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsClientGenerator;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsImplGenerator;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsSEIGenerator;
+import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.generator.JaxwsServerGenerator;
+
+public class JAXWSFrontEndProcessor implements Processor {
+    private static final Logger LOG = LogUtils.getL7dLogger(JAXWSFrontEndProcessor.class);
+    private ToolContext context;
+    private List<AbstractJaxwsGenerator> generators = new ArrayList<AbstractJaxwsGenerator>();
+    private List<String> infList = new ArrayList<String>();
+    
+    @SuppressWarnings("unchecked")
+    public void process() throws ToolException {
+        checkJaxwsClass();
+        List<ServiceInfo> services = (List<ServiceInfo>)context.get(ToolConstants.SERVICE_LIST);
+        ServiceInfo serviceInfo = services.get(0);
+        JavaInterface jinf = JavaFirstUtil.serviceInfo2JavaInf(serviceInfo);
+        JavaModel jm = new JavaModel();
+        jm.addInterface("inf", jinf);
+        jinf.setJavaModel(jm);
+        context.put(JavaModel.class, jm);
+        context.put(ToolConstants.SERVICE_NAME, serviceInfo.getName());
+        EndpointInfo endpointInfo = serviceInfo.getEndpoints().iterator().next();
+        context.put(ToolConstants.PORT_NAME, endpointInfo.getName());
+        generators.add(new JaxwsSEIGenerator());
+        generators.add(new JaxwsImplGenerator());
+        generators.add(new JaxwsServerGenerator());
+        generators.add(new JaxwsClientGenerator());
+
+        for (AbstractJaxwsGenerator generator : generators) {
+            generator.generate(context);
+        }
+
+    }
+
+    public void setEnvironment(ToolContext env) {
+        this.context = env;
+    }
+
+    public JavaInterface serviceInfo2JavaInf(ServiceInfo service) {
+        JavaInterface javaInf = new JavaInterface();
+        InterfaceInfo inf = service.getInterface();
+        for (OperationInfo op : inf.getOperations()) {
+            JavaMethod jm = new JavaMethod();
+            Method m = (Method)op.getProperty(ReflectionServiceFactoryBean.METHOD);
+            jm.setName(m.getName());
+            int i = 0;
+            for (Type type : m.getGenericParameterTypes()) {
+                JavaParameter jp = new JavaParameter();
+                jp.setClassName(getClassName(type));
+                jp.setStyle(Style.IN);
+                jp.setName("arg" + i++);
+                jm.addParameter(jp);
+            }
+
+            for (Type type : m.getGenericExceptionTypes()) {
+                JavaException jex = new JavaException();
+                String className = getClassName(type);
+                jex.setClassName(className);
+                jex.setName(className);
+                jm.addException(jex);
+            }
+
+            JavaReturn jreturn = new JavaReturn();
+            jreturn.setClassName(getClassName(m.getGenericReturnType()));
+            jreturn.setStyle(Style.OUT);
+            jm.setReturn(jreturn);
+
+            javaInf.setPackageName(m.getDeclaringClass().getPackage().getName());
+            javaInf.addMethod(jm);
+            javaInf.setName(inf.getName().getLocalPart());
+
+            jm.getParameterList();
+
+        }
+        return javaInf;
+    }
+
+    public String getClassName(Type type) {
+        if (type instanceof Class) {
+            Class clz = (Class)type;
+            if (clz.isArray()) {
+                return clz.getComponentType().getName() + "[]";
+            } else {
+                return clz.getName();
+            }
+        } else if (type instanceof ParameterizedType) {
+            return type.toString();
+        } else if (type instanceof GenericArrayType) {
+            return type.toString();
+        }
+
+        return "";
+    }
+
+    public void checkJaxwsClass() {
+        Class<?> clz = context.get(Class.class);
+        WebService webServiceAnno = (WebService)clz.getAnnotation(WebService.class);
+        if (webServiceAnno == null) {
+            Message msg = new Message("CLASS_DOESNOT_CARRY_WEBSERVICE_ANNO", LOG, clz.getName());
+            LOG.log(Level.WARNING, msg.toString());
+            throw new ToolException(msg);
+        }
+        if (isImplRmiRemote(clz)) {
+            Message msg = new Message("PARA_OR_RETURN_IMPL_REMOTE", LOG, clz.getName());
+            LOG.log(Level.WARNING, msg.toString());
+            throw new ToolException(msg);
+        }
+    }
+    
+    
+    private boolean isImplRmiRemote(Class claz) {
+        for (Method method : claz.getMethods()) {
+            if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())
+                && !method.getDeclaringClass().getName().equals("java.lang.Object"))
{
+                Class[] paraClasses = method.getParameterTypes();
+                for (Class clz : paraClasses) {
+                    getInfClass(clz);
+                }
+                Class returnClass = method.getReturnType();
+                getInfClass(returnClass);
+            }
+        }
+        if (infList.contains("java.rmi.Remote")) {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private void getInfClass(Class claz) {
+        for (Class inf : claz.getInterfaces()) {
+            getInfClass(inf);
+        }
+        if (claz.getSuperclass() != null) {
+            getInfClass(claz.getSuperclass());
+        }
+        if (claz.isInterface()) {
+            infList.add(claz.getName());
+        }
+    }
+    
+}

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/Messages.properties?rev=573528&r1=573527&r2=573528&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/Messages.properties
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/Messages.properties
Fri Sep  7 03:17:18 2007
@@ -21,4 +21,6 @@
 LOAD_WRAPPER_CLASS_FAILED = Can not load wrapper class {0}, please check the @RequestWrapper
or @ResponseWrapper and also check the class is in your classpath
 WRAPPER_CLASS_NOT_EXIST = Wrapper class not exist
 SOAPBinding_RPC_ON_METHOD = Method [{0}] processing error : SOAPBinding annotation can not
be placed on method with RPC style 
-LOADING_WRAPPER_CLASS = Trying to load wrapper class {0}
\ No newline at end of file
+LOADING_WRAPPER_CLASS = Trying to load wrapper class {0}
+CLASS_DOESNOT_CARRY_WEBSERVICE_ANNO = Class {0} does not carry a WebService annotation
+PARA_OR_RETURN_IMPL_REMOTE = Parameter or return type directly or indirectly implemented
the java.rmi.Remote interface in Class {0}  
\ No newline at end of file

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/generator/JaxwsClientGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/generator/JaxwsClientGenerator.java?rev=573528&r1=573527&r2=573528&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/generator/JaxwsClientGenerator.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/generator/JaxwsClientGenerator.java
Fri Sep  7 03:17:18 2007
@@ -61,7 +61,7 @@
             setAttributes("service", service);
             setAttributes("port", port);
             setAttributes("address", "http://localhost:9090/hello");
-            setAttributes("seiClass", ((Class)env.get(ToolConstants.SEI_CLASS)).getName());
+            setAttributes("seiClass", (String)env.get(ToolConstants.SEI_CLASS));
             setCommonAttributes();
             doWrite(CLIENT_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()
+ "Client"));
 

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java?rev=573528&r1=573527&r2=573528&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
Fri Sep  7 03:17:18 2007
@@ -48,18 +48,18 @@
 
     @After
     public void tearDown() {
-        //super.tearDown();
+        super.tearDown();
         System.setProperty("java.class.path", cp);
     }
 
-    @Ignore
+    @Test
     public void testVersionOutput() throws Exception {
         String[] args = new String[] {"-v"};
         JavaToWS.main(args);
         assertNotNull(getStdOut());
     }
 
-    @Ignore
+    @Test
     public void testFlagWSDL() throws Exception {
         String[] args = new String[] {"-wsdl", "-o", output.getPath() + "/tmp.wsdl",
                                       "-d", output.getPath(), "-client", "-server",
@@ -81,9 +81,39 @@
         assertTrue("wsdl is not generated", wsdlFile.exists());
     }
     
+    //org.apache.cxf.tools.fortest
+    
+    @Test
+    public void testClassNoWebServiceAnno() throws Exception {
+        String[] args = new String[] {"-wsdl", "-o", output.getPath() + "/tmp.wsdl", "-verbose",
+                                      "-d", output.getPath(),
+                                      "-frontend", "jaxws",
+                                      "-client", "-server",
+                                      "org.apache.cxf.tools.fortest.Hello"};
+        JavaToWS.main(args);
+        File wsdlFile = new File(output.getPath() + "/tmp.wsdl");
+        assertTrue("wsdl is not generated", wsdlFile.exists());
+        assertTrue("Class does not carry WebService error should be detected"
+                   , getStdErr().indexOf("does not carry a WebService annotation") > -1);
+    }
+    
+    @Test
+    public void testClassWithRMI() throws Exception {
+        String[] args = new String[] {"-wsdl", "-o", output.getPath() + "/tmp.wsdl", "-verbose",
+                                      "-d", output.getPath(),
+                                      "-frontend", "jaxws",
+                                      "-client", "-server",
+                                      "org.apache.cxf.tools.fortest.HelloRMI"};
+        JavaToWS.main(args);
+        File wsdlFile = new File(output.getPath() + "/tmp.wsdl");
+        assertTrue("wsdl is not generated", wsdlFile.exists());
+        assertTrue("Parameter or return type implemented java.rmi.Remote interface error
should be detected", 
+                   getStdErr().indexOf("implemented the java.rmi.Remote interface") >
-1);
+    }
+    
     
     
-    @Ignore 
+    @Ignore
     
     public void testGenServerAndClient() throws Exception {
         String[] args = new String[] {"-d", output.getPath(), "-client", "-server",
@@ -119,7 +149,7 @@
         assertTrue("GreeterImpl.java is not generated", impl.exists());
     }
     
-    @Ignore
+    @Test
     public void testGenWrapperBean() throws Exception {
         String[] args = new String[] {"-d", output.getPath(),
                                       "-wrapperbean",
@@ -129,7 +159,7 @@
     }
     
     
-    @Ignore
+    @Test
     public void testInvalidFlag() throws Exception {
         String[] args = new String[] {"-frontend", "tmp", "-wsdl", "-o", output.getPath()
+ "/tmp.wsdl",
                                       "org.apache.hello_world_soap12_http.Greeter"};
@@ -141,7 +171,7 @@
         assertTrue("wsdl is not generated", wsdlFile.exists());
     }
 
-    @Ignore
+    @Test
     public void testInvalidFlag2() throws Exception {
         String[] args = new String[] {"-frontend", "simple", "-wrapperbean", "-wsdl",
                                       "-o", output.getPath() + "/tmp.wsdl",

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/WSDLGeneratorFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/WSDLGeneratorFactoryTest.java?rev=573528&r1=573527&r2=573528&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/WSDLGeneratorFactoryTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/WSDLGeneratorFactoryTest.java
Fri Sep  7 03:17:18 2007
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.tools.java2wsdl.generator;
 
-import org.apache.cxf.tools.java2wsdl.generator.AbstractGenerator;
-import org.apache.cxf.tools.java2wsdl.generator.WSDLGeneratorFactory;
 import org.apache.cxf.tools.java2wsdl.generator.wsdl11.WSDL11Generator;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.junit.Assert;



Mime
View raw message