[
https://issues.apache.org/jira/browse/CAMEL-12552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16499447#comment-16499447
]
ASF GitHub Bot commented on CAMEL-12552:
----------------------------------------
aldettinger closed pull request #2356: CAMEL-12552: Sent an error reason in the
response body for HTTP 400 e…
URL: https://github.com/apache/camel/pull/2356
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/camel-core/src/main/java/org/apache/camel/processor/RestBindingAdvice.java
b/camel-core/src/main/java/org/apache/camel/processor/RestBindingAdvice.java
index 6619d2c935c..7b401ac19c3 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RestBindingAdvice.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RestBindingAdvice.java
@@ -263,6 +263,7 @@ private void unmarshal(Exchange exchange, Map<String,
Object> state) throws Exce
if (body == null) {
// this is a bad request, the client did not include a
message body
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
400);
+ exchange.getOut().setBody("The request body is missing.");
// stop routing and return
exchange.setProperty(Exchange.ROUTE_STOP, true);
return;
@@ -271,6 +272,7 @@ private void unmarshal(Exchange exchange, Map<String,
Object> state) throws Exce
if (requiredQueryParameters != null &&
!exchange.getIn().getHeaders().keySet().containsAll(requiredQueryParameters)) {
// this is a bad request, the client did not include some of
the required query parameters
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ exchange.getOut().setBody("Some of the required query
parameters are missing.");
// stop routing and return
exchange.setProperty(Exchange.ROUTE_STOP, true);
return;
@@ -278,6 +280,7 @@ private void unmarshal(Exchange exchange, Map<String,
Object> state) throws Exce
if (requiredHeaders != null &&
!exchange.getIn().getHeaders().keySet().containsAll(requiredHeaders)) {
// this is a bad request, the client did not include some of
the required http headers
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ exchange.getOut().setBody("Some of the required HTTP headers
are missing.");
// stop routing and return
exchange.setProperty(Exchange.ROUTE_STOP, true);
return;
diff --git
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredBodyTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredBodyTest.java
index 6c338e96cec..1fd56f1a8bd 100644
---
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredBodyTest.java
+++
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredBodyTest.java
@@ -51,7 +51,7 @@ public void testJettyInvalid() throws Exception {
} catch (CamelExecutionException e) {
HttpOperationFailedException cause =
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(400, cause.getStatusCode());
- assertEquals("", cause.getResponseBody());
+ assertEquals("The request body is missing.",
cause.getResponseBody());
}
}
diff --git
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredHttpHeaderTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredHttpHeaderTest.java
index 61222b79743..dbc1bc847b1 100644
---
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredHttpHeaderTest.java
+++
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredHttpHeaderTest.java
@@ -53,7 +53,7 @@ public void testJettyInvalid() throws Exception {
} catch (CamelExecutionException e) {
HttpOperationFailedException cause =
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(400, cause.getStatusCode());
- assertEquals("", cause.getResponseBody());
+ assertEquals("Some of the required HTTP headers are missing.",
cause.getResponseBody());
}
}
diff --git
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredQueryParameterTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredQueryParameterTest.java
index 2627f00e6f7..6d7798db135 100644
---
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredQueryParameterTest.java
+++
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyRequiredQueryParameterTest.java
@@ -52,7 +52,7 @@ public void testJettyInvalid() throws Exception {
} catch (CamelExecutionException e) {
HttpOperationFailedException cause =
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(400, cause.getStatusCode());
- assertEquals("", cause.getResponseBody());
+ assertEquals("Some of the required query parameters are missing.",
cause.getResponseBody());
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> camel-rest - Send the error reason in the resonse body
> ------------------------------------------------------
>
> Key: CAMEL-12552
> URL: https://issues.apache.org/jira/browse/CAMEL-12552
> Project: Camel
> Issue Type: Task
> Components: camel-core
> Reporter: Alex Dettinger
> Assignee: Alex Dettinger
> Priority: Minor
>
> CAMEL-11162 added some checks that could end up with HTTP 400, on invalid
> headers/params and empty body.
> It could be interesting to return the reason of failed status code. So that
> client knows how to modify there requests before sending again.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)