1   /*
2    * $Id: ETagComponent.java 11836 2008-05-22 12:12:40Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.util.StringUtils;
15  import org.mule.api.MuleEventContext;
16  import org.mule.api.MuleMessage;
17  import org.mule.transport.DefaultMessageAdapter;
18  import org.mule.transport.http.HttpConnector;
19  import org.mule.transport.http.HttpConstants;
20  
21  public class ETagComponent implements org.mule.api.lifecycle.Callable
22  {
23      String ETAG_VALUE = "0123456789";
24      
25      public Object onCall(MuleEventContext eventContext) throws Exception
26      {
27          MuleMessage msg = eventContext.getMessage();
28          
29          String etag = msg.getStringProperty(HttpConstants.HEADER_IF_NONE_MATCH, null);
30          if (etag != null && etag.equals(ETAG_VALUE))
31          {
32             DefaultMessageAdapter res = new DefaultMessageAdapter(StringUtils.EMPTY);
33             res.setIntProperty(HttpConnector.HTTP_STATUS_PROPERTY, 304);
34             msg = new DefaultMuleMessage(res);
35          }
36          
37          msg.setProperty(HttpConstants.HEADER_ETAG, ETAG_VALUE);
38          
39          return msg;
40      }
41  
42  }
43  
44