camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apatel <apa...@asg.bellsouth.net>
Subject Camel-restlet:setting Cache-Control metadata
Date Thu, 14 Feb 2013 14:49:05 GMT
We try to set the Cache-Control metadata in restlet route as below. But It
did not set Cache-Control on response. Also when i look at the code The
Restlet component Representation class does not have set Cache-Control
method.

Please help me to resolve this issue.


 <route xmlns="http://camel.apache.org/schema/spring" trace="true">
    <from
uri="restlet:/test/maxAgeCache?headerFilterStrategy=encoreRestletHeaderFilterStrategy"/>
    <setHeader headerName="Content-Type">
        <constant>application/json</constant>
    </setHeader>
    <setHeader headerName="Cache-Control">
        <constant>max-age=20</constant>
    </setHeader>
    <setBody>
        <constant>{ "status":"SUCCESS" }</constant>
    </setBody>
</route>

Struts2 also suggest to use the Cache-Control & Expires.
================================

Use the correct HTTP headers (Cache-Control & Expires).
When returning HTML views, make sure to add the correct headers so browsers
know how to cache them.

 http://struts.apache.org/development/2.x/docs/performance-tuning.html
=============================================
 
  
Below method in DefaultRestletBinding class only set the headers that set in
((Representation) message.getEntity()).setxxx methods.  I don't see the
Cache-Control sets anywhere.
 
 protected void setResponseHeader(Exchange exchange, org.restlet.Message
message, String header, Object value) {
        // put the header first
        message.getAttributes().put(header, value);
 
        // there must be a value going forward
        if (value == null) {
            return;
        }
 
        // special for certain headers
        if (message.getEntity() != null) {
            if (header.equalsIgnoreCase(HeaderConstants.HEADER_EXPIRES)) {
                if (value instanceof Calendar) {
                    message.getEntity().setExpirationDate(((Calendar)
value).getTime());
                } else if (value instanceof Date) {
                    message.getEntity().setExpirationDate((Date) value);
                } else if (value instanceof String) {
                    SimpleDateFormat format = new
SimpleDateFormat(RFC_2822_DATE_PATTERN, Locale.ENGLISH);
                    try {
                        Date date = format.parse((String) value);
                        message.getEntity().setExpirationDate(date);
                    } catch (ParseException e) {
                        LOG.debug("Header {} with value {} cannot be
converted as a Date. The value will be ignored.",
HeaderConstants.HEADER_EXPIRES, value);
                    }
                }
            }
 
            if
(header.equalsIgnoreCase(HeaderConstants.HEADER_LAST_MODIFIED)) {
                if (value instanceof Calendar) {
                    message.getEntity().setModificationDate(((Calendar)
value).getTime());
                } else if (value instanceof Date) {
                    message.getEntity().setModificationDate((Date) value);
                } else if (value instanceof String) {
                    SimpleDateFormat format = new
SimpleDateFormat(RFC_2822_DATE_PATTERN, Locale.ENGLISH);
                    try {
                        Date date = format.parse((String) value);
                        message.getEntity().setModificationDate(date);
                    } catch (ParseException e) {
                        LOG.debug("Header {} with value {} cannot be
converted as a Date. The value will be ignored.",
HeaderConstants.HEADER_LAST_MODIFIED, value);
                    }
                }
            }
 
            if
(header.equalsIgnoreCase(HeaderConstants.HEADER_CONTENT_LENGTH)) {
                if (value instanceof Long) {
                    message.getEntity().setSize((Long) value);
                } else if (value instanceof Integer) {
                    message.getEntity().setSize((Integer) value);
                } else {
                    Long num =
exchange.getContext().getTypeConverter().tryConvertTo(Long.class, value);
                    if (num != null) {
                        message.getEntity().setSize(num);
                    } else {
                        LOG.debug("Header {} with value {} cannot be
converted as a Long. The value will be ignored.",
HeaderConstants.HEADER_CONTENT_LENGTH, value);
                    }
                }
            }
 
            if
(header.equalsIgnoreCase(HeaderConstants.HEADER_CONTENT_TYPE)) {
                if (value instanceof MediaType) {
                    message.getEntity().setMediaType((MediaType) value);
                } else {
                    String type = value.toString();
                    MediaType media = MediaType.valueOf(type);
                    if (media != null) {
                        message.getEntity().setMediaType(media);
                    } else {
                        LOG.debug("Header {} with value {} cannot be
converted as a MediaType. The value will be ignored.",
HeaderConstants.HEADER_CONTENT_TYPE, value);
                    }
                }
            }
        }
    }
 



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-restlet-setting-Cache-Control-metadata-tp5727602.html
Sent from the Camel Development mailing list archive at Nabble.com.

Mime
View raw message