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
33 class WebSocketCookieStore implements CookieStore {
34
35 private final WebClient webClient_;
36
37 WebSocketCookieStore(final WebClient webClient) {
38 webClient_ = webClient;
39 }
40
41
42
43
44 @Override
45 public void add(final URI uri, final HttpCookie cookie) {
46 throw new UnsupportedOperationException();
47 }
48
49
50
51
52 @Override
53 public List<HttpCookie> get(final URI uri) {
54 final List<HttpCookie> cookies = new ArrayList<>();
55 try {
56 final String urlString = uri.toString().replace("ws://", "http://").replace("wss://", "https://");
57 final java.net.URL url = new java.net.URL(urlString);
58 for (final Cookie cookie : webClient_.getCookies(url)) {
59 final HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue());
60 httpCookie.setVersion(0);
61 cookies.add(httpCookie);
62 }
63 }
64 catch (final Exception e) {
65 throw new RuntimeException(e);
66 }
67 return cookies;
68 }
69
70
71
72
73 @Override
74 public List<HttpCookie> getCookies() {
75 throw new UnsupportedOperationException();
76 }
77
78
79
80
81 @Override
82 public List<URI> getURIs() {
83 throw new UnsupportedOperationException();
84 }
85
86
87
88
89 @Override
90 public boolean remove(final URI uri, final HttpCookie cookie) {
91 throw new UnsupportedOperationException();
92 }
93
94
95
96
97 @Override
98 public boolean removeAll() {
99 return false;
100 }
101 }