Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BDAF3DD37 for ; Thu, 14 Feb 2013 14:53:07 +0000 (UTC) Received: (qmail 46820 invoked by uid 500); 14 Feb 2013 14:53:06 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 46449 invoked by uid 500); 14 Feb 2013 14:53:01 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Delivered-To: moderator for dev@camel.apache.org Received: (qmail 22426 invoked by uid 99); 14 Feb 2013 14:49:32 -0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Date: Thu, 14 Feb 2013 06:49:05 -0800 (PST) From: apatel To: dev@camel.apache.org Message-ID: <1360853345436-5727602.post@n5.nabble.com> Subject: Camel-restlet:setting Cache-Control metadata MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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. application/json max-age=20 { "status":"SUCCESS" } 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.