cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r469376 - in /incubator/cxf/trunk/rt: core/src/main/java/org/apache/cxf/interceptor/ frontend/jaxws/src/test/java/org/apache/cxf/jaxws/
Date Tue, 31 Oct 2006 05:35:01 GMT
Author: mmao
Date: Mon Oct 30 21:35:01 2006
New Revision: 469376

URL: http://svn.apache.org/viewvc?view=rev&rev=469376
Log:
URIMappingInterceptor unit test update

* Get the parameter class type through reflection instead of messagepartinfo due to the api
changes.
* Enable the parameter checking in unit test.
* Added parameter checker and log if failed.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java?view=diff&rev=469376&r1=469375&r2=469376
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/URIMappingInterceptor.java
Mon Oct 30 21:35:01 2006
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.interceptor;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashMap;
@@ -27,14 +29,16 @@
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
+import javax.jws.WebParam;
+
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.factory.MethodDispatcher;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.MessageInfo;
-import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.ServiceModelUtil;
 
 public class URIMappingInterceptor extends AbstractInDatabindingInterceptor {
@@ -70,15 +74,55 @@
         message.setContent(List.class, getParameters(message, op));
     }
 
+    private Method getMethod(Message message, BindingOperationInfo operation) {
+        MethodDispatcher md = (MethodDispatcher) message.getExchange().
+            get(Service.class).get(MethodDispatcher.class.getName());
+        return md.getMethod(operation);
+    }
+    
+    private boolean isValidParameter(Annotation[][] parameterAnnotation, int index, String
parameterName) {
+        if (parameterAnnotation == null || parameterAnnotation.length < index) {
+            return true;
+        }
+        Annotation[] annotations = parameterAnnotation[index];
+        if (annotations == null || annotations.length < 1) {
+            return true;
+        }
+        WebParam webParam = null;
+        for (Annotation annotation : annotations) {
+            if (annotation.annotationType() == WebParam.class) {
+                webParam = (WebParam) annotation;
+            }
+        }
+        if (webParam == null 
+            || StringUtils.isEmpty(webParam.name()) 
+            || webParam.name().equals(parameterName)) {
+            return true;
+        }
+        LOG.warning("The parameter name [" + parameterName 
+                    + "] is not match the one defined in the WebParam name [" + webParam.name()
+ "]");
+        return false;
+    }
+    
     protected List<Object> getParameters(Message message, BindingOperationInfo operation)
{
         List<Object> parameters = new ArrayList<Object>();
-        MessageInfo msg = operation.getOperationInfo().getInput();
         int idx = parameters.size();
 
-        Map<String, String> queries = getQueries(message);
+        Map<String, String> queries = getQueries(message);        
+        
+        Method method = getMethod(message, operation);        
+        
+        Class[] types = method.getParameterTypes();
+        
+        Annotation[][] parameterAnnotation = method.getParameterAnnotations();
+        
         for (String key : queries.keySet()) {
-            MessagePartInfo p = msg.getMessageParts().get(idx);
-            if (p == null) {
+            Class<?> type = types[idx];
+            
+            // Do we need to fail the processing if the parameter not match the WebParam?
+            isValidParameter(parameterAnnotation, idx, key);
+            
+            if (type == null) {
                 LOG.warning("URIMappingInterceptor MessagePartInfo NULL ");
                 throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", BUNDLE,

                                                                        "index: " + idx +
" on key " + key));
@@ -86,8 +130,7 @@
 
             // TODO check the parameter name here
             Object param = null;
-            Class type = (Class)p.getProperty(Class.class.getName());
-            
+                        
             if (type != null && type.isPrimitive()) {
                 param = PrimitiveUtils.read(queries.get(key), type);
             } else {
@@ -96,15 +139,16 @@
             if (param != null) {
                 parameters.add(param);
             } else {
-                throw new RuntimeException(p.getName() + " can not be unmarshalled");
+                throw new RuntimeException(type.getName() + " can not be unmarshalled");
             }
-        }        
+            idx = parameters.size();
+        }
         return parameters;
     }
 
     protected Map<String, String> getQueries(Message message) {
         Map<String, String> queries = new LinkedHashMap<String, String>();
-        String query = (String)message.get(Message.QUERY_STRING);   
+        String query = (String)message.get(Message.QUERY_STRING);
         if (!StringUtils.isEmpty(query)) {
             List<String> parts = Arrays.asList(query.split("&"));
             for (String part : parts) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java?view=diff&rev=469376&r1=469375&r2=469376
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorDocLitTest.java
Mon Oct 30 21:35:01 2006
@@ -74,7 +74,8 @@
         
         EndpointInfo endpointInfo = service.getServiceInfo().getEndpoint(new QName(ns, "CalculatorPort"));
         Endpoint endpoint = new EndpointImpl(getBus(), service, endpointInfo);
-        exchange.put(Endpoint.class, endpoint);
+        exchange.put(Service.class, service);
+        exchange.put(Endpoint.class, endpoint);        
     }
     
     public void testGetAddFromPath() throws Exception {
@@ -88,12 +89,12 @@
         Object parameters = message.getContent(List.class);
         assertNotNull(parameters);
         assertEquals(2, ((List)parameters).size());
-        // TODO: should return int, service factory is broken, check it later.
-        //        Integer value = (Integer) ((List)parameters).get(0);
-        //        assertEquals(1, value.intValue());
-        //        
-        //        value = (Integer) ((List)parameters).get(1);        
-        //        assertEquals(2, value.intValue());
+         
+        Integer value = (Integer) ((List)parameters).get(0);
+        assertEquals(1, value.intValue());
+        
+        value = (Integer) ((List)parameters).get(1);        
+        assertEquals(2, value.intValue());
         
         BindingOperationInfo boi = message.getExchange().get(BindingOperationInfo.class);
         assertNotNull(boi);
@@ -112,11 +113,10 @@
         Object parameters = message.getContent(List.class);
         assertNotNull(parameters);
         assertEquals(2, ((List)parameters).size());
-        
-        // TODO: should return int
-        //        Integer value = (Integer) ((List)parameters).get(0);       
-        //        assertEquals(1, value.intValue());
-        //        value = (Integer) ((List)parameters).get(1);
-        //        assertEquals(2, value.intValue());
+                 
+        Integer value = (Integer) ((List)parameters).get(0);       
+        assertEquals(1, value.intValue());
+        value = (Integer) ((List)parameters).get(1);
+        assertEquals(2, value.intValue());
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java?view=diff&rev=469376&r1=469375&r2=469376
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/URIMappingInterceptorRPCTest.java
Mon Oct 30 21:35:01 2006
@@ -73,6 +73,7 @@
         
         EndpointInfo endpointInfo = service.getServiceInfo().getEndpoint(new QName(ns, "SoapPortRPCLit"));
         Endpoint endpoint = new EndpointImpl(getBus(), service, endpointInfo);
+        exchange.put(Service.class, service);
         exchange.put(Endpoint.class, endpoint);
     }
     



Mime
View raw message