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  /**
31   * HttpContext represents execution state of an HTTP process. It is a structure
32   * that can be used to map an attribute name to an attribute value.
33   * <p>
34   * The primary purpose of the HTTP context is to facilitate information sharing
35   * among various  logically related components. HTTP context can be used
36   * to store a processing state for one message or several consecutive messages.
37   * Multiple logically related messages can participate in a logical session
38   * if the same context is reused between consecutive messages.
39   * </p>
40   * <p>
41   * IMPORTANT: Please note HTTP context implementation, even when thread safe,
42   * may not be used concurrently by multiple threads, as the context may contain
43   * thread unsafe attributes.
44   * </p>
45   *
46   * @since 4.0
47   */
48  public interface HttpContext {
49  
50      /** The prefix reserved for use by HTTP components. "http." */
51      String RESERVED_PREFIX  = "http.";
52  
53      /**
54       * Obtains attribute with the given name.
55       *
56       * @param id the attribute name.
57       * @return attribute value, or {@code null} if not set.
58       */
59      Object getAttribute(String id);
60  
61      /**
62       * Sets value of the attribute with the given name.
63       *
64       * @param id the attribute name.
65       * @param obj the attribute value.
66       */
67      void setAttribute(String id, Object obj);
68  
69      /**
70       * Removes attribute with the given name from the context.
71       *
72       * @param id the attribute name.
73       * @return attribute value, or {@code null} if not set.
74       */
75      Object removeAttribute(String id);
76  
77  }