cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6200] Adding another test, making it easier to deal with the main case where a default model class is used to match only
Date Mon, 09 Feb 2015 11:30:29 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 9592ef449 -> 76a91535f


[CXF-6200] Adding another test, making it easier to deal with the main case where a default
model class is used to match only


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/76a91535
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/76a91535
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/76a91535

Branch: refs/heads/3.0.x-fixes
Commit: 76a91535fe0cf6109e14472a4b3eff9fad0011c3
Parents: 9592ef4
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Feb 9 11:26:42 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Feb 9 11:30:07 2015 +0000

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  2 +-
 ...AXRSClientServerUserResourceDefaultTest.java | 40 ++++++++++++++++++--
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/76a91535/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 8341e7c..c3dec62 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -764,7 +764,7 @@ public final class JAXRSUtils {
         Class<?>[] parameterTypes = ori.getInParameterTypes();
         List<Parameter> paramsInfo = ori.getParameters();  
         boolean preferModelParams = paramsInfo.size() > parameterTypes.length 
-            && PropertyUtils.isTrue(message.getContextualProperty("org.apache.cxf.preferModelParameters"));
+            && !PropertyUtils.isTrue(message.getContextualProperty("org.apache.cxf.preferMethodParameters"));
         
         int parameterTypesLengh = preferModelParams ? paramsInfo.size() : parameterTypes.length;
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/76a91535/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceDefaultTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceDefaultTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceDefaultTest.java
index 259a114..8801b93 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceDefaultTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceDefaultTest.java
@@ -34,11 +34,14 @@ import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.Source;
+import javax.xml.transform.sax.SAXSource;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.GetMethod;
@@ -91,9 +94,18 @@ public class JAXRSClientServerUserResourceDefaultTest extends AbstractBusClientS
             op2.setVerb("POST");
             op2.setParameters(Collections.singletonList(new Parameter(ParameterType.REQUEST_BODY,
null)));
             
+            UserOperation op3 = new UserOperation();
+            op3.setPath("echobookdefault");
+            op3.setName("echoDefault");
+            op3.setVerb("POST");
+            Parameter echoDefaultParam = new Parameter(ParameterType.REQUEST_BODY, null);
+            echoDefaultParam.setJavaType(SAXSource.class);
+            op3.setParameters(Collections.singletonList(echoDefaultParam));
+            
             List<UserOperation> ops = new ArrayList<UserOperation>();
             ops.add(op);
             ops.add(op2);
+            ops.add(op3);
             
             ur.setOperations(ops);
             
@@ -149,6 +161,14 @@ public class JAXRSClientServerUserResourceDefaultTest extends AbstractBusClientS
         assertEquals(333L, b.getId());
     }
     
+    @Test
+    public void testEchoBookDefault() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/default/echobookdefault");
+        Book b = wc.type("application/xml").accept("application/xml").post(new Book("echo",
444L), Book.class);
+        assertEquals("echo", b.getName());
+        assertEquals(444L, b.getId());
+    }
+    
     private void getAndCompare(String address, 
                                String acceptType,
                                int expectedStatus,
@@ -204,13 +224,18 @@ public class JAXRSClientServerUserResourceDefaultTest extends AbstractBusClientS
         public Object invoke(Exchange exchange, Object request, Object resourceObject) {
             MessageContext mc = new MessageContextImpl(exchange.getInMessage());
             List<Object> params = CastUtils.cast((List<?>)request);
-            if (params.size() == 1 && "999".equals(params.get(0))) {
+            String path = mc.getUriInfo().getPath();
+            if ("default/books/999".equals(path)) {
                 Long bookId = Long.valueOf(params.get(0).toString());
                 Book book = new Book("CXF in Action", bookId);
                 Response r = Response.ok(book, 
                                          mc.getHttpHeaders().getAcceptableMediaTypes().get(0)).build();
                 return new MessageContentsList(r);
-            } else { 
+            } else if ("default/echobookdefault".equals(path)) {
+                Source source = (Source)params.get(0);
+                Response r = Response.ok(source, MediaType.APPLICATION_ATOM_XML_TYPE).build();
+                return new MessageContentsList(r);
+            } else {
                 return super.invoke(exchange, request, resourceObject);
             }
             
@@ -219,8 +244,15 @@ public class JAXRSClientServerUserResourceDefaultTest extends AbstractBusClientS
     @PreMatching
     private static class PreMatchContainerRequestFilter implements ContainerRequestFilter
{
         public void filter(ContainerRequestContext context) throws IOException {
-            if (context.getUriInfo().getRequestUri().toString().endsWith("999")) {
-                JAXRSUtils.getCurrentMessage().put("org.apache.cxf.preferModelParameters",
true);
+            String path = context.getUriInfo().getPath();
+            if (path.endsWith("123")) {
+                // Setting this property makes sense only if we have a user model,
+                // default service class, a number of method parameters described 
+                // in the model not matching a number of the matched method's parameters,
+                // and this method is actually expected to be invoked (testGetBookInvokeService)
+                // which is rare for a model-only case, typically a custom invoker would
manage
+                // the actual processing of the request
+                JAXRSUtils.getCurrentMessage().put("org.apache.cxf.preferMethodParameters",
true);
             }
         }
         


Mime
View raw message