View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.protocol;
29  
30  import java.util.HashMap;
31  
32  /**
33   * HttpContext represents execution state of an HTTP process. It is a structure
34   * that can be used to map an attribute name to an attribute value. Internally
35   * HTTP context implementations are usually backed by a {@link HashMap}.
36   * <p>
37   * The primary purpose of the HTTP context is to facilitate information sharing
38   * among various  logically related components. HTTP context can be used
39   * to store a processing state for one message or several consecutive messages.
40   * Multiple logically related messages can participate in a logical session
41   * if the same context is reused between consecutive messages.
42   *
43   * @since 4.0
44   */
45  public interface HttpContext {
46  
47      /** The prefix reserved for use by HTTP components. "http." */
48      public static final String RESERVED_PREFIX  = "http.";
49  
50      /**
51       * Obtains attribute with the given name.
52       *
53       * @param id the attribute name.
54       * @return attribute value, or <code>null</code> if not set.
55       */
56      Object getAttribute(String id);
57  
58      /**
59       * Sets value of the attribute with the given name.
60       *
61       * @param id the attribute name.
62       * @param obj the attribute value.
63       */
64      void setAttribute(String id, Object obj);
65  
66      /**
67       * Removes attribute with the given name from the context.
68       *
69       * @param id the attribute name.
70       * @return attribute value, or <code>null</code> if not set.
71       */
72      Object removeAttribute(String id);
73  
74  }