CAMEL-7701 Fixed the CS errors and added the content-type header back as it 
could be used later


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/94efbceb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/94efbceb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/94efbceb

Branch: refs/heads/master
Commit: 94efbceb989224c8bb9dbe1fd16ef2bb03188bc7
Parents: 29c40d5
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Fri Aug 15 12:27:28 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Fri Aug 15 12:27:28 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsProducer.java      |  16 +-
 .../cxf/jaxrs/DefaultCxfRsBinding.java          |   1 +
 .../component/cxf/jaxrs/CxfRsRelayTest.java     | 202 +++++++++----------
 .../component/cxf/jaxrs/UploadService.java      |  35 ----
 4 files changed, 108 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/94efbceb/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index 4f365e7..804a51cf 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -281,16 +281,20 @@ public class CxfRsProducer extends DefaultProducer {
         return answer;
     }
 
-    private Method findRightMethod(List<Class<?>> resourceClasses, String 
methodName, Class<?>[] parameterTypes) throws NoSuchMethodException {
+    private Method findRightMethod(List<Class<?>> resourceClasses, String 
methodName,
+                                   Class<?>[] parameterTypes) throws 
NoSuchMethodException {
         for (Class<?> clazz : resourceClasses) {
             try {
                 Method[] m = clazz.getMethods();
-                iterate_on_methods: for (Method method : m) {
-                    if (!method.getName().equals(methodName))
+            iterate_on_methods:
+                for (Method method : m) {
+                    if (!method.getName().equals(methodName)) {
                         continue;
+                    }
                     Class<?>[] params = method.getParameterTypes();
-                    if (params.length != parameterTypes.length)
+                    if (params.length != parameterTypes.length) {
                         continue;
+                    }
                     for (int i = 0; i < parameterTypes.length; i++) {
                         if (!params[i].isAssignableFrom(parameterTypes[i])) {
                             continue iterate_on_methods;
@@ -302,7 +306,9 @@ public class CxfRsProducer extends DefaultProducer {
                 // keep looking
             }
         }
-        throw new NoSuchMethodException("Cannot find method with name: " + 
methodName + " having parameters assignable from: " + 
arrayToString(parameterTypes));
+        throw new NoSuchMethodException("Cannot find method with name: " + 
methodName
+                                        + " having parameters assignable from: 
"
+                                        + arrayToString(parameterTypes));
     }
 
     private Class<?>[] getParameterTypes(Object[] objects) {

http://git-wip-us.apache.org/repos/asf/camel/blob/94efbceb/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
index 54f5e93..e31cdac 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/DefaultCxfRsBinding.java
@@ -59,6 +59,7 @@ public class DefaultCxfRsBinding implements CxfRsBinding, 
HeaderFilterStrategyAw
         camelToCxfHeaderMap.put(Exchange.HTTP_URI, 
org.apache.cxf.message.Message.REQUEST_URI);
         camelToCxfHeaderMap.put(Exchange.HTTP_METHOD, 
org.apache.cxf.message.Message.HTTP_REQUEST_METHOD);
         camelToCxfHeaderMap.put(Exchange.HTTP_PATH, 
org.apache.cxf.message.Message.PATH_INFO);
+        camelToCxfHeaderMap.put(Exchange.CONTENT_TYPE, 
org.apache.cxf.message.Message.CONTENT_TYPE);
         camelToCxfHeaderMap.put(Exchange.HTTP_CHARACTER_ENCODING, 
org.apache.cxf.message.Message.ENCODING);
         camelToCxfHeaderMap.put(Exchange.HTTP_QUERY, 
org.apache.cxf.message.Message.QUERY_STRING);
         camelToCxfHeaderMap.put(Exchange.ACCEPT_CONTENT_TYPE, 
org.apache.cxf.message.Message.ACCEPT_CONTENT_TYPE);

http://git-wip-us.apache.org/repos/asf/camel/blob/94efbceb/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRelayTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRelayTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRelayTest.java
index c6dbe91..1e05ff4 100644
--- 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRelayTest.java
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRelayTest.java
@@ -41,116 +41,106 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.junit.Test;
 
 public class CxfRsRelayTest extends TestSupport {
-       /**
-        * A sample service "interface" (technically, it is a class since we 
will
-        * use proxy-client. That interface exposes three methods over-loading 
each
-        * other : we are testing the appropriate one will be chosen at runtime.
-        * 
-        */
-       @WebService
-       @Path("/rootpath")
-       @Consumes("multipart/form-data")
-       @Produces("application/xml")
-       public static class UploadService {
-               @WebMethod
-               @POST
-               @Path("/path1")
-               @Consumes("multipart/form-data")
-               public void upload(
-                               @Multipart(value = "content", type = 
"application/octet-stream") java.lang.Number content,
-                               @Multipart(value = "name", type = "text/plain") 
String name) {
-               }
+    /**
+     * A sample service "interface" (technically, it is a class since we will
+     * use proxy-client. That interface exposes three methods over-loading each
+     * other : we are testing the appropriate one will be chosen at runtime.
+     * 
+     */
+    @WebService
+    @Path("/rootpath")
+    @Consumes("multipart/form-data")
+    @Produces("application/xml")
+    public static class UploadService {
+        @WebMethod
+        @POST
+        @Path("/path1")
+        @Consumes("multipart/form-data")
+        public void upload(@Multipart(value = "content", type = 
"application/octet-stream") java.lang.Number content,
+                           @Multipart(value = "name", type = "text/plain") 
String name) {
+        }
 
-               @WebMethod
-               @GET
-               @Path("/path2")
-               @Consumes("text/plain")
-               private void upload() {
-               }
+        @WebMethod
+        @GET
+        @Path("/path2")
+        @Consumes("text/plain")
+        private void upload() {
+        }
 
-               @WebMethod
-               @POST
-               @Path("/path3")
-               @Consumes("multipart/form-data")
-               public void upload(
-                               @Multipart(value = "content", type = 
"application/octet-stream") InputStream content,
-                               @Multipart(value = "name", type = "text/plain") 
String name) {
-               }
+        @WebMethod
+        @POST
+        @Path("/path3")
+        @Consumes("multipart/form-data")
+        public void upload(@Multipart(value = "content", type = 
"application/octet-stream") InputStream content,
+                           @Multipart(value = "name", type = "text/plain") 
String name) {
+        }
 
-       }
+    }
 
-       private static final String SAMPLE_CONTENT_PATH = 
"/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml";
-       private static final String SAMPLE_NAME = "CxfRsSpringRelay.xml";
-       private static final CountDownLatch latch = new CountDownLatch(1);
-       private static String content;
-       private static String name;
+    private static final String SAMPLE_CONTENT_PATH = 
"/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml";
+    private static final String SAMPLE_NAME = "CxfRsSpringRelay.xml";
+    private static final CountDownLatch LATCH = new CountDownLatch(1);
+    private static String content;
+    private static String name;
 
-       /**
-        * That test builds a route chaining two cxfrs endpoints. It shows a 
request
-        * sent to the first one will be correctly transferred and consumed by 
the
-        * other one.
-        */
-       @Test
-       public void test() throws Exception {
-               final Main main = new Main();
-               try {
-                       
main.setApplicationContextUri("org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml");
-                       main.start();
-                       latch.await(10, TimeUnit.SECONDS);
-                       assertEquals(SAMPLE_NAME, name);
-                       StringWriter writer = new StringWriter();
-                       IOUtils.copyAndCloseInput(
-                                       new 
InputStreamReader(CamelRouteBuilder.class
-                                                       
.getResourceAsStream(SAMPLE_CONTENT_PATH)), writer);
-                       assertEquals(writer.toString(), content);
-               } finally {
-                       main.stop();
-               }
-       }
+    /**
+     * That test builds a route chaining two cxfrs endpoints. It shows a 
request
+     * sent to the first one will be correctly transferred and consumed by the
+     * other one.
+     */
+    @Test
+    public void testJaxrsRelayRoute() throws Exception {
+        final Main main = new Main();
+        try {
+            
main.setApplicationContextUri("org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml");
+            main.start();
+            LATCH.await(10, TimeUnit.SECONDS);
+            assertEquals(SAMPLE_NAME, name);
+            StringWriter writer = new StringWriter();
+            IOUtils.copyAndCloseInput(new 
InputStreamReader(CamelRouteBuilder.class
+                                          
.getResourceAsStream(SAMPLE_CONTENT_PATH)), writer);
+            assertEquals(writer.toString(), content);
+        } finally {
+            main.stop();
+        }
+    }
 
-       /**
-        * Route builder to be used with
-        * org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml
-        * 
-        */
-       public static class CamelRouteBuilder extends RouteBuilder {
-               @Override
-               public void configure() throws InterruptedException {
-                       from("upload1").process(new Processor() {
-                               @Override
-                               public void process(Exchange arg0) throws 
Exception {
-                                       // 
arg0.getIn().removeHeader(Exchange.CONTENT_TYPE);
-                               }
-                       }).to("upload2Client");
-                       from("upload2").process(new Processor() {
-                               @Override
-                               public void process(Exchange exchange) throws 
Exception {
-                                       // once the message arrives in the 
second endpoint, stores
-                                       // the message components and warns 
results can be compared
-                                       content = 
(exchange.getIn().getHeader("content", String.class));
-                                       name = 
(exchange.getIn().getHeader("name", String.class));
-                                       latch.countDown();
-                               }
-                       });
-                       Thread t = new Thread(new Runnable() {
-                               /**
-                                * Sends a request to the first endpoint in the 
route
-                                */
-                               public void run() {
-                                       try {
-                                               JAXRSClientFactory
-                                                               
.create(getContext().getEndpoint("upload1", CxfRsEndpoint.class).getAddress(),
-                                                                               
UploadService.class)
-                                                               
.upload(CamelRouteBuilder.class
-                                                                               
.getResourceAsStream(SAMPLE_CONTENT_PATH),
-                                                                               
SAMPLE_NAME);
-                                       } catch (Exception e) {
-                                               e.printStackTrace();
-                                               throw new RuntimeException(e);
-                                       }
-                               }
-                       });
-                       t.start();
-               }
-       }
+    /**
+     * Route builder to be used with
+     * org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml
+     * 
+     */
+    public static class CamelRouteBuilder extends RouteBuilder {
+        @Override
+        public void configure() throws InterruptedException {
+            
from("upload1").removeHeader(Exchange.CONTENT_TYPE).to("upload2Client");
+            from("upload2").process(new Processor() {
+                @Override
+                public void process(Exchange exchange) throws Exception {
+                    // once the message arrives in the second endpoint, stores
+                    // the message components and warns results can be compared
+                    content = exchange.getIn().getHeader("content", 
String.class);
+                    name = exchange.getIn().getHeader("name", String.class);
+                    LATCH.countDown();
+                }
+            });
+            Thread t = new Thread(new Runnable() {
+                /**
+                 * Sends a request to the first endpoint in the route
+                 */
+                public void run() {
+                    try {
+                        
JAXRSClientFactory.create(getContext().getEndpoint("upload1", 
CxfRsEndpoint.class)
+                                                      .getAddress(), 
UploadService.class)
+                            
.upload(CamelRouteBuilder.class.getResourceAsStream(SAMPLE_CONTENT_PATH),
+                                    SAMPLE_NAME);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+            t.start();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/94efbceb/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/UploadService.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/UploadService.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/UploadService.java
deleted file mode 100644
index a9c65be..0000000
--- 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/UploadService.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.camel.component.cxf.jaxrs;
-
-import javax.jws.WebMethod;
-import javax.jws.WebService;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-
-import org.apache.cxf.jaxrs.ext.multipart.Multipart;
-
-@WebService
-@Path("/cms")
-@Consumes("multipart/form-data")
-@Produces("application/xml")
-public  class UploadService {
-       @WebMethod
-       @POST
-       @Path("/upload2")
-       @Consumes("multipart/form-data")
-       public void addVideo(
-                       @Multipart(value = "contenu", type = 
"application/octet-stream") java.lang.Number video,
-                       @Multipart(value = "nom", type = "text/plain") String 
nom) {
-       }
-
-       @WebMethod
-       @POST
-       @Path("/upload")
-       @Consumes("multipart/form-data")
-       public void addVideo(
-                       @Multipart(value = "contenu", type = 
"application/octet-stream") java.io.InputStream video,
-                       @Multipart(value = "nom", type = "text/plain") String 
nom) {
-       }
-
-}
\ No newline at end of file

Reply via email to