camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-8270: camel-restlet should support CORS again.
Date Sun, 22 Nov 2015 14:50:01 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 92a6514ff -> 28bbd8e61
  refs/heads/master 4caa5c127 -> 54cd88f55


CAMEL-8270: camel-restlet should support CORS again.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/54cd88f5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/54cd88f5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/54cd88f5

Branch: refs/heads/master
Commit: 54cd88f5540de3cf934e9fd07822a070a76752b6
Parents: 4caa5c1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Nov 22 15:49:27 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Nov 22 15:49:27 2015 +0100

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          | 77 +++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/54cd88f5/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 264093c..d0882f7 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
@@ -26,9 +26,12 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import javax.xml.transform.dom.DOMSource;
 
@@ -40,6 +43,7 @@ import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.restlet.Request;
 import org.restlet.Response;
 import org.restlet.data.CacheDirective;
@@ -359,7 +363,7 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
     }
 
     @SuppressWarnings("unchecked")
-    protected boolean setResponseHeader(Exchange exchange, org.restlet.Message message, String
header, Object value) {
+    protected boolean setResponseHeader(Exchange exchange, org.restlet.Response message,
String header, Object value) {
         // there must be a value going forward
         if (value == null) {
             return true;
@@ -370,6 +374,77 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
 
         // special for certain headers
         if (message.getEntity() != null) {
+            // arfg darn restlet you make using your api harder for end users with all this
trick just to set those ACL headers
+            if (header.equalsIgnoreCase(HeaderConstants.HEADER_ACCESS_CONTROL_ALLOW_CREDENTIAL))
{
+                Boolean bool = exchange.getContext().getTypeConverter().tryConvertTo(Boolean.class,
value);
+                if (bool != null) {
+                    message.setAccessControlAllowCredential(bool);
+                }
+                return true;
+            }
+            if (header.equalsIgnoreCase(HeaderConstants.HEADER_ACCESS_CONTROL_ALLOW_HEADERS))
{
+                Set set;
+                if (value instanceof Set) {
+                    set = (Set) value;
+                } else {
+                    set = new LinkedHashSet();
+                    Iterator it = ObjectHelper.createIterator(value);
+                    while (it.hasNext()) {
+                        Object next = it.next();
+                        String text = exchange.getContext().getTypeConverter().tryConvertTo(String.class,
next);
+                        if (text != null) {
+                            set.add(text);
+                        }
+                    }
+                }
+                message.setAccessControlAllowHeaders(set);
+                return true;
+            }
+            if (header.equalsIgnoreCase(HeaderConstants.HEADER_ACCESS_CONTROL_ALLOW_METHODS))
{
+                Set set;
+                if (value instanceof Set) {
+                    set = (Set) value;
+                } else {
+                    set = new LinkedHashSet();
+                    Iterator it = ObjectHelper.createIterator(value);
+                    while (it.hasNext()) {
+                        Object next = it.next();
+                        String text = exchange.getContext().getTypeConverter().tryConvertTo(String.class,
next);
+                        if (text != null) {
+                            Method method = new Method(text);
+                            set.add(method);
+                        }
+                    }
+                }
+                message.setAccessControlAllowMethods(set);
+                return true;
+            }
+            if (header.equalsIgnoreCase(HeaderConstants.HEADER_ACCESS_CONTROL_ALLOW_ORIGIN))
{
+                String text = exchange.getContext().getTypeConverter().tryConvertTo(String.class,
value);
+                if (text != null) {
+                    message.setAccessControlAllowOrigin(text);
+                }
+                return true;
+            }
+            if (header.equalsIgnoreCase(HeaderConstants.HEADER_ACCESS_CONTROL_EXPOSE_HEADERS))
{
+                Set set;
+                if (value instanceof Set) {
+                    set = (Set) value;
+                } else {
+                    set = new LinkedHashSet();
+                    Iterator it = ObjectHelper.createIterator(value);
+                    while (it.hasNext()) {
+                        Object next = it.next();
+                        String text = exchange.getContext().getTypeConverter().tryConvertTo(String.class,
next);
+                        if (text != null) {
+                            Method method = new Method(text);
+                            set.add(method);
+                        }
+                    }
+                }
+                message.setAccessControlExposeHeaders(set);
+                return true;
+            }
             if (header.equalsIgnoreCase(HeaderConstants.HEADER_CACHE_CONTROL)) {
                 if (value instanceof List) {
                     message.setCacheDirectives((List<CacheDirective>) value);


Mime
View raw message