This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c55060  UPDATED RestBindingAdvice
4c55060 is described below

commit 4c55060b8ce277504296bab92c2ef3a8543be7bd
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 7b401ac..90fe9d4 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.util.ExchangeHelper;
 import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A {@link org.apache.camel.processor.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");
 

Reply via email to