camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1003431 - in /camel/trunk/components/camel-restlet/src: main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java
Date Fri, 01 Oct 2010 08:34:54 GMT
Author: davsclaus
Date: Fri Oct  1 08:34:53 2010
New Revision: 1003431

URL: http://svn.apache.org/viewvc?rev=1003431&view=rev
Log:
CAMEL-3185: Fixed restlet producer not setting status code.

Added:
    camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java
      - copied, changed from r1003390, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java
Modified:
    camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java

Modified: camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java?rev=1003431&r1=1003430&r2=1003431&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
(original)
+++ camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
Fri Oct  1 08:34:53 2010
@@ -222,8 +222,8 @@ public class DefaultRestletBinding imple
         response.setEntity(text, mediaType);
 
         if (exchange.getProperty(Exchange.CHARSET_NAME) != null) {
-            response.getEntity().setCharacterSet(CharacterSet.valueOf(exchange.getProperty(Exchange.CHARSET_NAME,
-                    String.class)));
+            CharacterSet cs = CharacterSet.valueOf(exchange.getProperty(Exchange.CHARSET_NAME,
String.class));
+            response.getEntity().setCharacterSet(cs);
         }
     }
 
@@ -238,16 +238,21 @@ public class DefaultRestletBinding imple
             }
         }
 
+        // set response code
+        int responseCode = response.getStatus().getCode();
+        exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
+
+        // get content type
+        MediaType mediaType = response.getEntity().getMediaType();
+        if (mediaType != null) {
+            exchange.getOut().setHeader(Exchange.CONTENT_TYPE, mediaType.toString());
+        }
+
         String text = response.getEntity().getText();
         if (LOG.isDebugEnabled()) {
             LOG.debug("Populate exchange from Restlet response: " + text);
         }
-
-        if (exchange.getPattern().isOutCapable()) {
-            exchange.getOut().setBody(text);
-        } else {
-            throw new RuntimeCamelException("Exchange is incapable of receiving response:
" + exchange + " with pattern: " + exchange.getPattern());
-        }
+        exchange.getOut().setBody(text);
     }
 
     public HeaderFilterStrategy getHeaderFilterStrategy() {

Copied: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java
(from r1003390, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java?p2=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java&p1=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java&r1=1003390&r2=1003431&rev=1003431&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java
(original)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetResponseCodeTest.java
Fri Oct  1 08:34:53 2010
@@ -25,7 +25,7 @@ import org.junit.Test;
 /**
  * @version $Revision$
  */
-public class RestletProducerGetTest extends CamelTestSupport {
+public class RestletProducerGetResponseCodeTest extends CamelTestSupport {
 
     @Test
     public void testRestletProducerGet() throws Exception {
@@ -38,7 +38,14 @@ public class RestletProducerGetTest exte
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("restlet:http://localhost:9080/users/123/basic");
+                from("direct:start")
+                    .to("restlet:http://localhost:9080/users/123/basic")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            assertEquals(200, exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE));
+                            assertEquals("text/plain", exchange.getIn().getHeader(Exchange.CONTENT_TYPE));
+                        }
+                    });
 
                 from("restlet:http://localhost:9080/users/{id}/basic")
                     .process(new Processor() {



Mime
View raw message