View Javadoc

1   /*
2    * $Id: ETagComponent.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.http.functional;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleEventContext;
15  import org.mule.api.MuleMessage;
16  import org.mule.transport.http.HttpConnector;
17  import org.mule.transport.http.HttpConstants;
18  import org.mule.util.StringUtils;
19  
20  public class ETagComponent implements org.mule.api.lifecycle.Callable
21  {
22      private static String ETAG_VALUE = "0123456789";
23      
24      public Object onCall(MuleEventContext eventContext) throws Exception
25      {
26          MuleMessage message = eventContext.getMessage();
27  
28          String etag = message.getOutboundProperty(HttpConstants.HEADER_IF_NONE_MATCH);
29          if ((etag != null) && etag.equals(ETAG_VALUE))
30          {
31              message = new DefaultMuleMessage(StringUtils.EMPTY, eventContext.getMuleContext());
32              message.setOutboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, HttpConstants.SC_NOT_MODIFIED);
33          }
34          
35          message.setOutboundProperty(HttpConstants.HEADER_ETAG, ETAG_VALUE);        
36          return message;
37      }
38  }
39  
40