| 1 |
/* CheckingCookies.java |
| 2 |
Confirms that a test cookie is in the cookie store |
| 3 |
|
| 4 |
Copyright (C) 2012 Red Hat, Inc. |
| 5 |
|
| 6 |
This file is part of IcedTea. |
| 7 |
|
| 8 |
IcedTea is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation, version 2. |
| 11 |
|
| 12 |
IcedTea is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with IcedTea; see the file COPYING. If not, write to |
| 19 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 |
02110-1301 USA. |
| 21 |
|
| 22 |
Linking this library statically or dynamically with other modules is |
| 23 |
making a combined work based on this library. Thus, the terms and |
| 24 |
conditions of the GNU General Public License cover the whole |
| 25 |
combination. |
| 26 |
|
| 27 |
As a special exception, the copyright holders of this library give you |
| 28 |
permission to link this library with independent modules to produce an |
| 29 |
executable, regardless of the license terms of these independent |
| 30 |
modules, and to copy and distribute the resulting executable under |
| 31 |
terms of your choice, provided that you also meet, for each linked |
| 32 |
independent module, the terms and conditions of the license of that |
| 33 |
module. An independent module is a module which is not derived from |
| 34 |
or based on this library. If you modify this library, you may extend |
| 35 |
this exception to your version of the library, but you are not |
| 36 |
obligated to do so. If you do not wish to do so, delete this |
| 37 |
exception statement from your version. |
| 38 |
*/ |
| 39 |
import java.applet.Applet; |
| 40 |
import java.io.IOException; |
| 41 |
import java.net.CookieHandler; |
| 42 |
import java.net.CookieManager; |
| 43 |
import java.net.CookiePolicy; |
| 44 |
import java.net.URI; |
| 45 |
import java.net.URISyntaxException; |
| 46 |
import java.net.URL; |
| 47 |
import java.util.HashMap; |
| 48 |
import java.util.List; |
| 49 |
import java.util.Map; |
| 50 |
|
| 51 |
public class CheckingCookies extends Applet { |
| 52 |
static class Killer extends Thread { |
| 53 |
|
| 54 |
public int n = 2000; |
| 55 |
|
| 56 |
@Override |
| 57 |
public void run() { |
| 58 |
try { |
| 59 |
Thread.sleep(n); |
| 60 |
System.out.println("Applet killing itself after " + n + " ms of life"); |
| 61 |
System.exit(0); |
| 62 |
} catch (Exception ex) { |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
static private void printCookieInfo(URI uri) throws IOException { |
| 68 |
CookieHandler handler = CookieHandler.getDefault(); |
| 69 |
Map<String, List<String>> cookieMap = null; |
| 70 |
|
| 71 |
if (handler == null) { |
| 72 |
System.out.println("Failing due to lack of CookieHandler class!"); |
| 73 |
return; |
| 74 |
} |
| 75 |
System.out.println("Using CookieHandler class: " + handler.getClass().getCanonicalName()); |
| 76 |
|
| 77 |
cookieMap = handler.get(uri, new HashMap<String, List<String>>()); |
| 78 |
for (Map.Entry<String, List<String>> entry : cookieMap.entrySet()) { |
| 79 |
System.out.println("Iterating cookiemap with " + entry.getKey() + " => " + entry.getValue()); |
| 80 |
if (entry.getKey().contains("Cookie")) { |
| 81 |
for (String cookie : entry.getValue()) { |
| 82 |
System.out.println("Found cookie: " + cookie); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* If a show-document param was set, go there */ |
| 89 |
private void gotoNextDocument() { |
| 90 |
URL baseURL = getCodeBase(); |
| 91 |
String nextDocument = getParameter("show-document"); |
| 92 |
if (nextDocument != null) { |
| 93 |
try { |
| 94 |
System.out.println("Calling showDocument(" + nextDocument + ")"); |
| 95 |
getAppletContext().showDocument(new URL(baseURL.toString() + nextDocument)); |
| 96 |
} catch (Exception e) { |
| 97 |
e.printStackTrace(); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public void start() { |
| 104 |
System.out.println("Entered CheckingCookies.java"); |
| 105 |
try { |
| 106 |
printCookieInfo(getCodeBase().toURI()); |
| 107 |
} catch (Exception e) { |
| 108 |
e.printStackTrace(); |
| 109 |
} |
| 110 |
System.out.println("Finished CheckingCookies.java"); |
| 111 |
|
| 112 |
gotoNextDocument(); |
| 113 |
} |
| 114 |
} |