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