View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.util;
20  
21  import java.net.CookieManager;
22  import java.net.CookieStore;
23  import java.net.HttpCookie;
24  import java.net.URI;
25  import java.util.Collections;
26  import java.util.List;
27  
28  /**
29   * Implementation of {@link CookieStore} that delegates to an instance created by {@link CookieManager}
30   * via {@link CookieManager#getCookieStore()}.
31   */
32  public class HttpCookieStore implements CookieStore
33  {
34      private final CookieStore delegate;
35  
36      public HttpCookieStore()
37      {
38          delegate = new CookieManager().getCookieStore();
39      }
40  
41      @Override
42      public void add(URI uri, HttpCookie cookie)
43      {
44          delegate.add(uri, cookie);
45      }
46  
47      @Override
48      public List<HttpCookie> get(URI uri)
49      {
50          return delegate.get(uri);
51      }
52  
53      @Override
54      public List<HttpCookie> getCookies()
55      {
56          return delegate.getCookies();
57      }
58  
59      @Override
60      public List<URI> getURIs()
61      {
62          return delegate.getURIs();
63      }
64  
65      @Override
66      public boolean remove(URI uri, HttpCookie cookie)
67      {
68          return delegate.remove(uri, cookie);
69      }
70  
71      @Override
72      public boolean removeAll()
73      {
74          return delegate.removeAll();
75      }
76  
77      public static class Empty implements CookieStore
78      {
79          @Override
80          public void add(URI uri, HttpCookie cookie)
81          {
82          }
83  
84          @Override
85          public List<HttpCookie> get(URI uri)
86          {
87              return Collections.emptyList();
88          }
89  
90          @Override
91          public List<HttpCookie> getCookies()
92          {
93              return Collections.emptyList();
94          }
95  
96          @Override
97          public List<URI> getURIs()
98          {
99              return Collections.emptyList();
100         }
101 
102         @Override
103         public boolean remove(URI uri, HttpCookie cookie)
104         {
105             return false;
106         }
107 
108         @Override
109         public boolean removeAll()
110         {
111             return false;
112         }
113     }
114 }