GH-3283: HTTP Inbound handle SpEL errors (#3289)
* GH-3283: HTTP Inbound handle SpEL errors Fixes https://github.com/spring-projects/spring-integration/issues/3283 * Process all the request message preparation exceptions in the provided error channel to let target application to make a decision about an appropriate HTTP status instead of default 500 Server Error * * Rephrase `ResponseStatusException` doc in the http.adoc Co-authored-by: Gary Russell <grussell@vmware.com> Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
@@ -59,8 +59,10 @@ import org.springframework.integration.http.multipart.MultipartHttpInputMessage;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.integration.support.json.JacksonPresent;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -267,30 +269,46 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
|
||||
|
||||
Map<String, Object> headers = getHeaderMapper().toHeaders(httpEntity.getHeaders());
|
||||
Object payload = null;
|
||||
if (getPayloadExpression() != null) {
|
||||
// create payload based on SpEL
|
||||
payload = getPayloadExpression().getValue(evaluationContext);
|
||||
}
|
||||
Message<?> message = null;
|
||||
try {
|
||||
if (getPayloadExpression() != null) {
|
||||
// create payload based on SpEL
|
||||
payload = getPayloadExpression().getValue(evaluationContext);
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(getHeaderExpressions())) {
|
||||
headers.putAll(
|
||||
ExpressionEvalMap.from(getHeaderExpressions())
|
||||
.usingEvaluationContext(evaluationContext)
|
||||
.withRoot(httpEntity)
|
||||
.build());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(getHeaderExpressions())) {
|
||||
headers.putAll(
|
||||
ExpressionEvalMap.from(getHeaderExpressions())
|
||||
.usingEvaluationContext(evaluationContext)
|
||||
.withRoot(httpEntity)
|
||||
.build());
|
||||
}
|
||||
|
||||
if (payload == null) {
|
||||
if (httpEntity.getBody() != null) {
|
||||
payload = httpEntity.getBody();
|
||||
if (payload == null) {
|
||||
if (httpEntity.getBody() != null) {
|
||||
payload = httpEntity.getBody();
|
||||
}
|
||||
else {
|
||||
payload = requestParams;
|
||||
}
|
||||
}
|
||||
|
||||
message = prepareRequestMessage(servletRequest, httpEntity, headers, payload);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
MessageConversionException conversionException =
|
||||
new MessageConversionException("Cannot create request message", ex);
|
||||
MessageChannel errorChannel = getErrorChannel();
|
||||
if (errorChannel != null) {
|
||||
this.messagingTemplate.send(errorChannel,
|
||||
buildErrorMessage(null,
|
||||
conversionException));
|
||||
}
|
||||
else {
|
||||
payload = requestParams;
|
||||
throw conversionException;
|
||||
}
|
||||
}
|
||||
|
||||
Message<?> message = prepareRequestMessage(servletRequest, httpEntity, headers, payload);
|
||||
|
||||
Message<?> reply = null;
|
||||
if (isExpectReply()) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user