You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/04/10 18:18:53 UTC

[camel] branch master updated: CAMEL-12429: use Restlet HeaderUtils to apply response headers

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

davsclaus 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 16ad8db  CAMEL-12429: use Restlet HeaderUtils to apply response headers
16ad8db is described below

commit 16ad8db43f88e183156aa68146e314999c09569e
Author: Anton Koscejev <an...@zoomint.com>
AuthorDate: Tue Apr 10 13:11:02 2018 +0200

    CAMEL-12429: use Restlet HeaderUtils to apply response headers
---
 .../component/restlet/DefaultRestletBinding.java   | 52 ++--------------------
 1 file changed, 3 insertions(+), 49 deletions(-)

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 9b04512..b74adb5 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
@@ -392,54 +392,6 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         }
     }
 
-    private void configureRestletResponseStandardHeaders(Exchange exchange, Response response, Series standardHeaders) {
-        Iterator it = standardHeaders.iterator();
-        while (it.hasNext()) {
-            Header h = (Header) it.next();
-            String key = h.getName();
-            String value = h.getValue();
-
-
-            // ignore these headers
-            if ("Host".equalsIgnoreCase(key) || "Accept".equalsIgnoreCase(key) || "Accept-encoding".equalsIgnoreCase(key)
-                || "User-Agent".equalsIgnoreCase(key) || "Referer".equalsIgnoreCase(key) || "Connection".equalsIgnoreCase(key)
-                || "Cookie".equalsIgnoreCase(key)) {
-                continue;
-            }
-            if ("Content-Type".equalsIgnoreCase(key)) {
-                MediaType mediaType = exchange.getContext().getTypeConverter().tryConvertTo(MediaType.class, exchange, value);
-                if (mediaType != null) {
-                    response.getEntity().setMediaType(mediaType);
-                }
-            } else if ("Server".equalsIgnoreCase(key)) {
-                response.getServerInfo().setAgent(value);
-            } else if ("Age".equalsIgnoreCase(key)) {
-                Integer age = exchange.getContext().getTypeConverter().tryConvertTo(Integer.class, exchange, value);
-                if (age != null) {
-                    response.setAge(age);
-                }
-            } else if ("Expires".equalsIgnoreCase(key)) {
-                Date date = exchange.getContext().getTypeConverter().tryConvertTo(Date.class, exchange, value);
-                if (date != null) {
-                    response.getEntity().setExpirationDate(date);
-                }
-            } else if ("Date".equalsIgnoreCase(key)) {
-                Date d = exchange.getContext().getTypeConverter().tryConvertTo(Date.class, exchange, value);
-                if (d != null) {
-                    response.setDate(d);
-                }
-            } else if ("Access-Control-Max-Age".equalsIgnoreCase(key)) {
-                Integer accessControlMaxAge = exchange.getContext().getTypeConverter().tryConvertTo(Integer.class, exchange, value);
-                if (accessControlMaxAge != null) {
-                    response.setAccessControlMaxAge(accessControlMaxAge);
-                }
-            } else {
-                // TODO: implement all the other restlet standard headers
-                LOG.warn("Addition of the standard response header \"{}\" is not allowed. Please use the equivalent property in the Restlet API.", key);
-            }
-        }
-    }
-
     public void populateRestletResponseFromExchange(Exchange exchange, Response response) throws Exception {
         Message out;
         if (exchange.isFailed()) {
@@ -555,7 +507,9 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         LOG.debug("Detected {} response extension headers", extensionHeaders.getHeaders().size());
         LOG.debug("Detected {} response standard headers", standardHeaders.size());
 
-        configureRestletResponseStandardHeaders(exchange, response, standardHeaders);
+        // use Restlet utils for standard headers
+        HeaderUtils.copyResponseTransportHeaders(standardHeaders, response);
+        HeaderUtils.extractEntityHeaders(standardHeaders, response.getEntity());
 
         // include the extension headers on the response
         if (extensionHeaders.getHeaders().size() > 0) {

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.