This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch sandbox/camel-3.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit c5778f5cc01f47c2f521ae26328c8f4b6c333c00 Author: Robert Gründler <[email protected]> AuthorDate: Fri Nov 16 15:02:34 2018 +0100 UPDATED RestBindingAdvice - Support for the catchAll */* MimeType - Added some logs to ease debugging when clientRequestValidation is turned on --- .../java/org/apache/camel/processor/RestBindingAdvice.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 95ddb3d..3d09b08 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 @@ -34,6 +34,8 @@ import org.apache.camel.spi.RestConfiguration; import org.apache.camel.support.ExchangeHelper; import org.apache.camel.support.MessageHelper; import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A {@link CamelInternalProcessorAdvice} that binds the REST DSL incoming @@ -47,6 +49,8 @@ import org.apache.camel.util.ObjectHelper; * @see CamelInternalProcessor */ public class RestBindingAdvice implements CamelInternalProcessorAdvice<Map<String, Object>> { + + private static final Logger LOG = LoggerFactory.getLogger(RestBindingAdvice.class); private static final String STATE_KEY_DO_MARSHAL = "doMarshal"; private static final String STATE_KEY_ACCEPT = "accept"; private static final String STATE_JSON = "json"; @@ -198,6 +202,7 @@ public class RestBindingAdvice implements CamelInternalProcessorAdvice<Map<Strin if (clientRequestValidation) { // check if the content-type is accepted according to consumes if (!isValidOrAcceptedContentType(consumes, contentType)) { + LOG.trace("Consuming content type does not match contentType header {}. Stopping routing.", contentType); // the content-type is not something we can process so its a HTTP_ERROR 415 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 415); // stop routing and return @@ -207,6 +212,7 @@ public class RestBindingAdvice implements CamelInternalProcessorAdvice<Map<Strin // check if what is produces is accepted by the client if (!isValidOrAcceptedContentType(produces, accept)) { + LOG.trace("Produced content type does not match accept header {}. Stopping routing.", contentType); // the response type is not accepted by the client so its a HTTP_ERROR 406 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 406); // stop routing and return @@ -507,6 +513,12 @@ public class RestBindingAdvice implements CamelInternalProcessorAdvice<Map<Strin return true; } + // Any MIME type + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept#Directives + if ("*/*".equals(target)) { + return true; + } + boolean isXml = valid.toLowerCase(Locale.ENGLISH).contains("xml"); boolean isJson = valid.toLowerCase(Locale.ENGLISH).contains("json");
