CAMEL-10665: Fixed restlet warning about empty response should use 204 instead of 200 as response code
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ffc745dd Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ffc745dd Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ffc745dd Branch: refs/heads/master Commit: ffc745ddc1e202e85816f107fd1943112e0bdd5e Parents: cef6626 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Oct 5 13:14:42 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Oct 5 13:37:17 2017 +0200 ---------------------------------------------------------------------- .../camel/component/restlet/DefaultRestletBinding.java | 4 ++++ .../camel/component/restlet/RestRestletHttpOptionsTest.java | 8 ++++---- .../org/apache/camel/component/restlet/RestletQueryTest.java | 4 ++-- .../apache/camel/component/restlet/RestletTestSupport.java | 4 +++- .../camel/component/restlet/RestletValidUriQueryTest.java | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ffc745dd/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 5c7ed1f..4ec60bc 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 @@ -445,6 +445,10 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate if (body == null) { // empty response response.setEntity("", MediaType.TEXT_PLAIN); + // if empty response and status is OK, then set it to NO_CONTENT which is more correct + if (Status.SUCCESS_OK.equals(response.getStatus())) { + response.setStatus(Status.SUCCESS_NO_CONTENT); + } } else if (body instanceof Response) { // its already a restlet response, so dont do anything LOG.debug("Using existing Restlet Response from exchange body: {}", body); http://git-wip-us.apache.org/repos/asf/camel/blob/ffc745dd/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java index c1cea45..037ddce 100644 --- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletHttpOptionsTest.java @@ -35,14 +35,14 @@ public class RestRestletHttpOptionsTest extends RestletTestSupport { } }); - assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); + assertEquals(204, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); assertEquals("GET, OPTIONS", exchange.getOut().getHeader("ALLOW")); - assertEquals("", exchange.getOut().getBody(String.class)); + assertEquals(null, exchange.getOut().getBody(String.class)); exchange = fluentTemplate.to("http://localhost:" + portNum + "/users/v1/123").withHeader(Exchange.HTTP_METHOD, "OPTIONS").send(); - assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); + assertEquals(204, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); assertEquals("OPTIONS, PUT", exchange.getOut().getHeader("ALLOW")); - assertEquals("", exchange.getOut().getBody(String.class)); + assertEquals(null, exchange.getOut().getBody(String.class)); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/ffc745dd/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java index bc9b6cc..2096864 100644 --- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletQueryTest.java @@ -53,7 +53,7 @@ public class RestletQueryTest extends RestletTestSupport { public void testPostBody() throws Exception { HttpResponse response = doExecute(new HttpGet("http://localhost:" + portNum + "/users/homer?" + QUERY_STRING)); - assertHttpResponse(response, 200, "text/plain"); + assertHttpResponse(response, 204, "text/plain"); } @@ -67,7 +67,7 @@ public class RestletQueryTest extends RestletTestSupport { } }); - assertEquals(200, ex.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); + assertEquals(204, ex.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/ffc745dd/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletTestSupport.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletTestSupport.java index e1df106..876e545 100644 --- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletTestSupport.java +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletTestSupport.java @@ -52,7 +52,9 @@ public abstract class RestletTestSupport extends CamelTestSupport { CloseableHttpClient client = HttpClientBuilder.create().build(); try { HttpResponse response = client.execute(method); - response.setEntity(new BufferedHttpEntity(response.getEntity())); + if (response.getEntity() != null) { + response.setEntity(new BufferedHttpEntity(response.getEntity())); + } return response; } finally { client.close(); http://git-wip-us.apache.org/repos/asf/camel/blob/ffc745dd/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletValidUriQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletValidUriQueryTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletValidUriQueryTest.java index 1e8c974..c419af5 100644 --- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletValidUriQueryTest.java +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletValidUriQueryTest.java @@ -53,7 +53,7 @@ public class RestletValidUriQueryTest extends RestletTestSupport { public void testGet() throws Exception { HttpResponse response = doExecute(new HttpGet("http://localhost:" + portNum + "/users/homer?" + QUERY_STRING)); - assertHttpResponse(response, 200, "text/plain"); + assertHttpResponse(response, 204, "text/plain"); } @@ -67,6 +67,6 @@ public class RestletValidUriQueryTest extends RestletTestSupport { } }); - assertEquals(200, ex.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); + assertEquals(204, ex.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); } } \ No newline at end of file