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   * IMPORTANT: Please note HTTP context implementation, even when thread safe,
41   * may not be used concurrently by multiple threads, as the context may contain
42   * thread unsafe attributes.
43   *
44   * @since 4.0
45   */
46  public interface HttpContext {
47  
48      /** The prefix reserved for use by HTTP components. "http." */
49      public static final String RESERVED_PREFIX  = "http.";
50  
51      /**
52       * Obtains attribute with the given name.
53       *
54       * @param id the attribute name.
55       * @return attribute value, or {@code null} if not set.
56       */
57      Object getAttribute(String id);
58  
59      /**
60       * Sets value of the attribute with the given name.
61       *
62       * @param id the attribute name.
63       * @param obj the attribute value.
64       */
65      void setAttribute(String id, Object obj);
66  
67      /**
68       * Removes attribute with the given name from the context.
69       *
70       * @param id the attribute name.
71       * @return attribute value, or {@code null} if not set.
72       */
73      Object removeAttribute(String id);
74  
75  }