• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package java.net;
18 
19 import java.io.IOException;
20 import java.util.List;
21 import java.util.Map;
22 
23 /**
24  * This class provides a way to manage cookies with a HTTP protocol handler.
25  */
26 public abstract class CookieHandler {
27 
28     private static CookieHandler systemWideCookieHandler;
29 
30     /**
31      * Returns the system-wide cookie handler or {@code null} if not set.
32      */
getDefault()33     public static CookieHandler getDefault() {
34         return systemWideCookieHandler;
35     }
36 
37     /**
38      * Sets the system-wide cookie handler.
39      */
setDefault(CookieHandler cHandler)40     public static void setDefault(CookieHandler cHandler) {
41         systemWideCookieHandler = cHandler;
42     }
43 
44     /**
45      * Gets all cookies for a specific URI from the cookie cache.
46      *
47      * @param uri
48      *            a URI to search for applicable cookies.
49      * @param requestHeaders
50      *            a list of request headers.
51      * @return an unchangeable map of all appropriate cookies.
52      * @throws IOException
53      *             if an error occurs during the I/O operation.
54      */
get(URI uri, Map<String, List<String>> requestHeaders)55     public abstract Map<String, List<String>> get(URI uri,
56             Map<String, List<String>> requestHeaders) throws IOException;
57 
58     /**
59      * Sets all cookies of a specific URI in the {@code responseHeaders} into
60      * the cookie cache.
61      *
62      * @param uri
63      *            the origin URI of the cookies.
64      * @param responseHeaders
65      *            a list of request headers.
66      * @throws IOException
67      *             if an error occurs during the I/O operation.
68      */
put(URI uri, Map<String, List<String>> responseHeaders)69     public abstract void put(URI uri, Map<String, List<String>> responseHeaders)
70             throws IOException;
71 }
72