You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/10/08 08:32:58 UTC

[1/2] git commit: CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle

Updated Branches:
  refs/heads/master 3e2dedfe4 -> 2119a095b


CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle


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

Branch: refs/heads/master
Commit: a81232e9b6b59619162b9703528daf13ce3f4aa3
Parents: 3e2dedf
Author: Willem Jiang <ni...@apache.org>
Authored: Tue Oct 8 13:14:36 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Tue Oct 8 13:14:36 2013 +0800

----------------------------------------------------------------------
 .../camel/test/blueprint/CamelBlueprintTestSupport.java      | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a81232e9/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
index cce7a8e..8c5bd00 100644
--- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
+++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
@@ -47,13 +47,19 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport {
     private static ThreadLocal<BundleContext> threadLocalBundleContext = new ThreadLocal<BundleContext>();
     private volatile BundleContext bundleContext;
     private final Set<ServiceRegistration<?>> services = new LinkedHashSet<ServiceRegistration<?>>();
+    
+    // CamelBlueprintTestSupport creates the test bundle which includes blueprint configuration files if the value is true
+    // You can override the return value to false if you already has the test bundle in your class path
+    protected boolean includeTestBundle() {
+        return true;
+    }
 
    
     @SuppressWarnings({"rawtypes", "unchecked"})
     protected BundleContext createBundleContext() throws Exception {
         String symbolicName = getClass().getSimpleName();
         BundleContext answer = CamelBlueprintHelper.createBundleContext(symbolicName, getBlueprintDescriptor(),
-                true, getBundleFilter(), getBundleVersion(), getBundleDirectives());
+            includeTestBundle(), getBundleFilter(), getBundleVersion(), getBundleDirectives());
 
         // must register override properties early in OSGi containers
         Properties extra = useOverridePropertiesWithPropertiesComponent();


Re: [1/2] git commit: CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle

Posted by Willem jiang <wi...@gmail.com>.
Good point, I will commit a quick fix for it shortly.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, October 8, 2013 at 2:37 PM, Claus Ibsen wrote:

> The comment on the method should be javadoc so people can find that
> information what the method does.
>  
>  
> On Tue, Oct 8, 2013 at 8:32 AM, <ningjiang@apache.org (mailto:ningjiang@apache.org)> wrote:
> > Updated Branches:
> > refs/heads/master 3e2dedfe4 -> 2119a095b
> >  
> >  
> > CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle
> >  
> >  
> > Project: http://git-wip-us.apache.org/repos/asf/camel/repo
> > Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a81232e9
> > Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a81232e9
> > Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a81232e9
> >  
> > Branch: refs/heads/master
> > Commit: a81232e9b6b59619162b9703528daf13ce3f4aa3
> > Parents: 3e2dedf
> > Author: Willem Jiang <ningjiang@apache.org (mailto:ningjiang@apache.org)>
> > Authored: Tue Oct 8 13:14:36 2013 +0800
> > Committer: Willem Jiang <ningjiang@apache.org (mailto:ningjiang@apache.org)>
> > Committed: Tue Oct 8 13:14:36 2013 +0800
> >  
> > ----------------------------------------------------------------------
> > .../camel/test/blueprint/CamelBlueprintTestSupport.java | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> > ----------------------------------------------------------------------
> >  
> >  
> > http://git-wip-us.apache.org/repos/asf/camel/blob/a81232e9/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> > ----------------------------------------------------------------------
> > diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> > index cce7a8e..8c5bd00 100644
> > --- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> > +++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> > @@ -47,13 +47,19 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport {
> > private static ThreadLocal<BundleContext> threadLocalBundleContext = new ThreadLocal<BundleContext>();
> > private volatile BundleContext bundleContext;
> > private final Set<ServiceRegistration<?>> services = new LinkedHashSet<ServiceRegistration<?>>();
> > +
> > + // CamelBlueprintTestSupport creates the test bundle which includes blueprint configuration files if the value is true
> > + // You can override the return value to false if you already has the test bundle in your class path
> > + protected boolean includeTestBundle() {
> > + return true;
> > + }
> >  
> >  
> > @SuppressWarnings({"rawtypes", "unchecked"})
> > protected BundleContext createBundleContext() throws Exception {
> > String symbolicName = getClass().getSimpleName();
> > BundleContext answer = CamelBlueprintHelper.createBundleContext(symbolicName, getBlueprintDescriptor(),
> > - true, getBundleFilter(), getBundleVersion(), getBundleDirectives());
> > + includeTestBundle(), getBundleFilter(), getBundleVersion(), getBundleDirectives());
> >  
> > // must register override properties early in OSGi containers
> > Properties extra = useOverridePropertiesWithPropertiesComponent();
>  
>  
>  
>  
>  
> --  
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com (mailto:cibsen@redhat.com)
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen




Re: [1/2] git commit: CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle

Posted by Claus Ibsen <cl...@gmail.com>.
The comment on the method should be javadoc so people can find that
information what the method does.


On Tue, Oct 8, 2013 at 8:32 AM,  <ni...@apache.org> wrote:
> Updated Branches:
>   refs/heads/master 3e2dedfe4 -> 2119a095b
>
>
> CAMEL-6835 CamelBlueprintTestSupport should provide option of not generating test bundle
>
>
> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a81232e9
> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a81232e9
> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a81232e9
>
> Branch: refs/heads/master
> Commit: a81232e9b6b59619162b9703528daf13ce3f4aa3
> Parents: 3e2dedf
> Author: Willem Jiang <ni...@apache.org>
> Authored: Tue Oct 8 13:14:36 2013 +0800
> Committer: Willem Jiang <ni...@apache.org>
> Committed: Tue Oct 8 13:14:36 2013 +0800
>
> ----------------------------------------------------------------------
>  .../camel/test/blueprint/CamelBlueprintTestSupport.java      | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/a81232e9/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> ----------------------------------------------------------------------
> diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> index cce7a8e..8c5bd00 100644
> --- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> +++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
> @@ -47,13 +47,19 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport {
>      private static ThreadLocal<BundleContext> threadLocalBundleContext = new ThreadLocal<BundleContext>();
>      private volatile BundleContext bundleContext;
>      private final Set<ServiceRegistration<?>> services = new LinkedHashSet<ServiceRegistration<?>>();
> +
> +    // CamelBlueprintTestSupport creates the test bundle which includes blueprint configuration files if the value is true
> +    // You can override the return value to false if you already has the test bundle in your class path
> +    protected boolean includeTestBundle() {
> +        return true;
> +    }
>
>
>      @SuppressWarnings({"rawtypes", "unchecked"})
>      protected BundleContext createBundleContext() throws Exception {
>          String symbolicName = getClass().getSimpleName();
>          BundleContext answer = CamelBlueprintHelper.createBundleContext(symbolicName, getBlueprintDescriptor(),
> -                true, getBundleFilter(), getBundleVersion(), getBundleDirectives());
> +            includeTestBundle(), getBundleFilter(), getBundleVersion(), getBundleDirectives());
>
>          // must register override properties early in OSGi containers
>          Properties extra = useOverridePropertiesWithPropertiesComponent();
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

[2/2] git commit: CAMEL-6834 camel-restlet supports to send the Representation object back

Posted by ni...@apache.org.
CAMEL-6834 camel-restlet supports to send the Representation object back


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

Branch: refs/heads/master
Commit: 2119a095b4b23ed732db3aaa76cd23ee4c5d90bd
Parents: a81232e
Author: Willem Jiang <ni...@apache.org>
Authored: Tue Oct 8 13:15:46 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Tue Oct 8 14:26:24 2013 +0800

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          |  3 ++
 .../component/restlet/RestletSetBodyTest.java   | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2119a095/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 3a7a9ae..f84511e 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -52,6 +52,7 @@ import org.restlet.data.Status;
 import org.restlet.engine.header.HeaderConstants;
 import org.restlet.representation.FileRepresentation;
 import org.restlet.representation.InputRepresentation;
+import org.restlet.representation.Representation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -230,6 +231,8 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         } else if (body instanceof Response) {
             // its already a restlet response, so dont do anything
             LOG.debug("Using existing Restlet Response from exchange body: {}", body);
+        } else if (body instanceof Representation) {
+            response.setEntity(out.getBody(Representation.class));
         } else if (body instanceof InputStream) {
             response.setEntity(new InputRepresentation(out.getBody(InputStream.class), mediaType));
         } else if (body instanceof File) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2119a095/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
index bb2ec77..a436ec5 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
@@ -16,8 +16,17 @@
  */
 package org.apache.camel.component.restlet;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
 import org.junit.Test;
+import org.restlet.data.MediaType;
+import org.restlet.representation.InputRepresentation;
 
 /**
  * @version 
@@ -29,6 +38,31 @@ public class RestletSetBodyTest extends RestletTestSupport {
         String response = template.requestBody("restlet:http://0.0.0.0:" + portNum + "/stock/ORCL?restletMethod=get", null, String.class);
         assertEquals("110", response);
     }
+    
+    @Test
+    public void testSetBodyRepresentation() throws Exception {
+        HttpGet get = new HttpGet("http://0.0.0.0:" + portNum + "/images/123");
+        HttpClient httpclient = new DefaultHttpClient();
+        InputStream is = null;
+        try {
+            HttpResponse response = httpclient.execute(get);
+            assertEquals(200, response.getStatusLine().getStatusCode());
+            assertEquals("image/png", response.getEntity().getContentType().getValue());
+            is = response.getEntity().getContent();
+            assertEquals("Get wrong available size", 10, is.available());
+            byte[] buffer = new byte[10];
+            is.read(buffer);
+            for (int i = 0; i < 10; i++) {
+                assertEquals(i + 1, buffer[i]);
+            }
+        } finally {
+            httpclient.getConnectionManager().shutdown();
+            if (is != null) {
+                is.close();
+            }
+        }
+    }
+    
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -37,6 +71,14 @@ public class RestletSetBodyTest extends RestletTestSupport {
             public void configure() throws Exception {
                 from("restlet:http://0.0.0.0:" + portNum + "/stock/{symbol}?restletMethods=get")
                     .setBody().constant("110");
+                // create ByteArrayRepresentation for response
+                byte[] image = new byte[10];
+                for (int i = 0; i < 10; i++) {
+                    image[i] = (byte)(i + 1);
+                }
+                ByteArrayInputStream inputStream = new ByteArrayInputStream(image);
+                from("restlet:http://0.0.0.0:" + portNum + "/images/{symbol}?restletMethods=get")
+                    .setBody().constant(new InputRepresentation(inputStream, MediaType.IMAGE_PNG, 10));
             }
         };
     }