[ 
https://issues.apache.org/jira/browse/CAMEL-12429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16432715#comment-16432715
 ] 

ASF GitHub Bot commented on CAMEL-12429:
----------------------------------------

davsclaus closed pull request #2285: CAMEL-12429: use Restlet HeaderUtils to 
apply response headers
URL: https://github.com/apache/camel/pull/2285
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 9b04512e6ed..b74adb58cc1 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 @@ private void 
configureRestletRequestStandardHeaders(Exchange exchange, Request r
         }
     }
 
-    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 void populateRestletResponseFromExchange(Exchange 
exchange, Response resp
         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) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Avoid restlet response header warnings by using Restlet HeaderUtils
> -------------------------------------------------------------------
>
>                 Key: CAMEL-12429
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12429
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-restlet
>    Affects Versions: 2.20.2
>            Reporter: Anton Koscejev
>            Priority: Minor
>             Fix For: 2.20.4, 2.21.1, 2.22.0
>
>
> Camel still prints warnings such as this:
>  {code}
> Addition of the standard response header "ETag" is not allowed. Please use 
> the equivalent property in the Restlet API.
> {code}
> However, these headers are actually easy to set by using Restlet's own 
> HeaderUtils, specifically via: 
> {code}
> HeaderUtils.copyResponseTransportHeaders(standardHeaders, response);
> HeaderUtils.extractEntityHeaders(standardHeaders, response.getEntity());
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to