cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r610365 - in /incubator/cxf/trunk/tools/javato/ws/src: main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ test/java/org/apache/cxf/tools/fortest/refparam/ test/java/org/apache/cxf/tools/java2wsdl/processor/
Date Wed, 09 Jan 2008 12:26:23 GMT
Author: mmao
Date: Wed Jan  9 04:26:04 2008
New Revision: 610365

URL: http://svn.apache.org/viewvc?rev=610365&view=rev
Log:
CXF-1380
  * Set the namepace into XmlElement if we can get the targetNamespace from the WebParam


Added:
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersException.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersImpl.java
Modified:
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java?rev=610365&r1=610364&r2=610365&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
Wed Jan  9 04:26:04 2008
@@ -25,6 +25,7 @@
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
+import javax.jws.WebParam;
 
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.service.model.MessageInfo;
@@ -66,14 +67,16 @@
         String type = "Object";
 
         final Type[] paramClasses = method.getGenericParameterTypes();
+        final Annotation[][] paramAnnotations = method.getParameterAnnotations();
+
         for (MessagePartInfo mpi : message.getMessageParts()) {
             int idx = mpi.getIndex();
             name = mpi.getName().getLocalPart();
             Type t = paramClasses[idx];
 
-
+            Class clz = null;
             if (t instanceof Class) {
-                Class clz = (Class) t;
+                clz = (Class) t;
                 if (clz.isArray()) {
                     if (isBuiltInTypes(clz.getComponentType())) {
                         type = clz.getComponentType().getSimpleName() + "[]";
@@ -87,18 +90,38 @@
                 ParameterizedType pt = (ParameterizedType) t;
                 if (pt.getActualTypeArguments().length > 0
                     && pt.getActualTypeArguments()[0] instanceof Class) {
-                    type = ((Class)pt.getActualTypeArguments()[0]).getName();
+                    clz = (Class)pt.getActualTypeArguments()[0];
+                    type = clz.getName();
                 }
             }
 
             JavaField field = new JavaField(name, type, "");
-            field.setTargetNamespace("");
+
+            if (paramAnnotations != null 
+                && paramAnnotations.length == paramClasses.length) {
+                WebParam wParam = getWebParamAnnotation(paramAnnotations[idx]);
+                if (wParam != null && !StringUtils.isEmpty(wParam.targetNamespace()))
{
+                    field.setTargetNamespace(wParam.targetNamespace());
+                } else {
+                    field.setTargetNamespace("");
+                }
+            }
+
             List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx);
             field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
             fields.add(field);
         }
 
         return fields;
+    }
+
+    private WebParam getWebParamAnnotation(final Annotation[] annotations) {
+        for (Annotation annotation : annotations) {
+            if (annotation instanceof WebParam) {
+                return (WebParam) annotation;
+            }
+        }
+        return null;
     }
 
     @Override

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersException.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersException.java?rev=610365&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersException.java
(added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersException.java
Wed Jan  9 04:26:04 2008
@@ -0,0 +1,33 @@
+/**
+ * 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.refparam;
+
+public class AddNumbersException extends Exception {
+    String detail;
+
+    public AddNumbersException(String message, String detail) {
+        super(message);
+        this.detail = detail;
+    }
+
+    public String getDetail() {
+        return detail;
+    }
+}

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersImpl.java?rev=610365&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersImpl.java
(added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/refparam/AddNumbersImpl.java
Wed Jan  9 04:26:04 2008
@@ -0,0 +1,61 @@
+/**
+ * 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.refparam;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.xml.ws.Action;
+import javax.xml.ws.soap.Addressing;
+
+@WebService(
+    name = "AddNumbersPortType",
+    portName = "AddNumbersPort",
+    serviceName = "AddNumbersService",
+    targetNamespace = "http://example.com"
+)
+@Addressing(enabled = true, required = true)
+
+public class AddNumbersImpl {
+    @Action(input = "addInAction", output = "addOutAction")
+    public int addNumbers(
+                          @WebParam(name = "number1", targetNamespace = "http://example.com")
+                          int number1,
+                          @WebParam(name = "number2", targetNamespace = "http://example.com")
+                          int number2) throws AddNumbersException {
+        return doStuff(number1, number2);
+    }
+
+    public int addNumbersAndPassString(@WebParam(name = "number1", targetNamespace = "http://example.com")
+                                       int number1,
+                                       @WebParam(name = "number2", targetNamespace = "http://example.com")
+                                       int number2,
+                                       @WebParam(name = "testString", targetNamespace = "http://example.com")
+                                       String testString) throws AddNumbersException {
+        return doStuff(number1, number2);
+    }
+
+    int doStuff(int number1, int number2) throws AddNumbersException {
+        if (number1 < 0 || number2 < 0) {
+            throw new AddNumbersException("Negative numbers can't be added!",
+                                          "Numbers: " + number1 + ", " + number2);
+        }
+        return number1 + number2;
+    }
+}

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=610365&r1=610364&r2=610365&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Wed Jan  9 04:26:04 2008
@@ -517,18 +517,24 @@
         assertTrue(getStringFromFile(wsdlFile).indexOf("name=\"bye\"") != -1);
     }
 
-//     @Test
-//     public void testWSARefParam() throws Exception {
-//         env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/refparam.wsdl");
-//         env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.refparam.AddNumbersImpl");
-//         env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
-//         env.put(ToolConstants.CFG_WRAPPERBEAN, ToolConstants.CFG_WRAPPERBEAN);
-//         try {
-//             processor.setEnvironment(env);
-//             processor.process();
-//         } catch (Exception e) {
-//             e.printStackTrace();
-//         }
-//     }
+    @Test
+    public void testWSARefParam() throws Exception {
+        env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/refparam.wsdl");
+        env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.refparam.AddNumbersImpl");
+        env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+        env.put(ToolConstants.CFG_WRAPPERBEAN, ToolConstants.CFG_WRAPPERBEAN);
+        try {
+            processor.setEnvironment(env);
+            processor.process();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
+        String pkgBase = "org/apache/cxf/tools/fortest/refparam/jaxws";
+        File requestWrapperClass = new File(output, pkgBase + "/AddNumbers.java");
+        assertTrue(requestWrapperClass.exists());
+
+        String expectedString = "@XmlElement(name  =  \"number2\",  namespace  =  \"http://example.com\")";
+        assertTrue(getStringFromFile(requestWrapperClass).indexOf(expectedString) != -1);
+    }
 }



Mime
View raw message