01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 is ready for managing a stateful cookie with HTTP protocol
25: */
26: public abstract class CookieHandler {
27:
28: private static CookieHandler systemWideCookieHandler;
29:
30: private final static NetPermission getCookieHandlerPermission = new NetPermission(
31: "getCookieHandler"); //$NON-NLS-1$
32:
33: private final static NetPermission setCookieHandlerPermission = new NetPermission(
34: "setCookieHandler"); //$NON-NLS-1$
35:
36: /**
37: * Returns a system-wide cookie handler, or null if not set
38: *
39: * @return a cookie handler
40: */
41: public static CookieHandler getDefault() {
42: SecurityManager sm = System.getSecurityManager();
43: if (null != sm) {
44: sm.checkPermission(getCookieHandlerPermission);
45: }
46: return systemWideCookieHandler;
47: }
48:
49: /**
50: * sets a system-wide cookie handler
51: *
52: * @param cHandler
53: * the cookie handler to set
54: */
55: public static void setDefault(CookieHandler cHandler) {
56: SecurityManager sm = System.getSecurityManager();
57: if (null != sm) {
58: sm.checkPermission(setCookieHandlerPermission);
59: }
60: systemWideCookieHandler = cHandler;
61: }
62:
63: /**
64: * Searchs and gets all cookies in the cache by the specified uri in the
65: * request header.
66: *
67: * @param uri
68: * the specified uri to search for
69: * @param requestHeaders
70: * a list of request headers
71: * @return a map that record all such cookies, the map is unchangeable
72: * @throws IOException
73: * if some error of I/O operation occurs
74: */
75: public abstract Map<String, List<String>> get(URI uri,
76: Map<String, List<String>> requestHeaders)
77: throws IOException;
78:
79: /**
80: * Sets cookies according to uri and responseHeaders
81: *
82: * @param uri
83: * the specified uri
84: * @param responseHeaders
85: * a list of request headers
86: * @throws IOException
87: * if some error of I/O operation occurs
88: */
89: public abstract void put(URI uri,
90: Map<String, List<String>> responseHeaders)
91: throws IOException;
92: }
|