1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.websocket;
16
17 import java.net.CookieStore;
18 import java.net.HttpCookie;
19 import java.net.URI;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.htmlunit.WebClient;
24 import org.htmlunit.javascript.host.WebSocket;
25 import org.htmlunit.util.Cookie;
26
27
28
29
30
31
32 class WebSocketCookieStore implements CookieStore {
33
34 private final WebClient webClient_;
35
36 WebSocketCookieStore(final WebClient webClient) {
37 webClient_ = webClient;
38 }
39
40
41
42
43 @Override
44 public void add(final URI uri, final HttpCookie cookie) {
45 throw new UnsupportedOperationException();
46 }
47
48
49
50
51 @Override
52 public List<HttpCookie> get(final URI uri) {
53 final List<HttpCookie> cookies = new ArrayList<>();
54 try {
55 final String urlString = uri.toString().replace("ws://", "http://").replace("wss://", "https://");
56 final java.net.URL url = new java.net.URL(urlString);
57 for (final Cookie cookie : webClient_.getCookies(url)) {
58 final HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue());
59 httpCookie.setVersion(0);
60 cookies.add(httpCookie);
61 }
62 }
63 catch (final Exception e) {
64 throw new RuntimeException(e);
65 }
66 return cookies;
67 }
68
69
70
71
72 @Override
73 public List<HttpCookie> getCookies() {
74 throw new UnsupportedOperationException();
75 }
76
77
78
79
80 @Override
81 public List<URI> getURIs() {
82 throw new UnsupportedOperationException();
83 }
84
85
86
87
88 @Override
89 public boolean remove(final URI uri, final HttpCookie cookie) {
90 throw new UnsupportedOperationException();
91 }
92
93
94
95
96 @Override
97 public boolean removeAll() {
98 return false;
99 }
100 }