1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel.socket.http;
17
18 import java.util.Map;
19 import java.util.Map.Entry;
20
21 import javax.net.ssl.SSLContext;
22 import javax.net.ssl.SSLEngine;
23 import javax.net.ssl.SSLSession;
24
25 import org.jboss.netty.buffer.ChannelBufferFactory;
26 import org.jboss.netty.channel.ChannelConfig;
27 import org.jboss.netty.channel.ChannelPipelineFactory;
28 import org.jboss.netty.channel.socket.SocketChannel;
29 import org.jboss.netty.channel.socket.SocketChannelConfig;
30 import org.jboss.netty.util.internal.ConversionUtil;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public final class HttpTunnelingSocketChannelConfig implements SocketChannelConfig {
60
61 private final HttpTunnelingClientSocketChannel channel;
62 private volatile String serverName;
63 private volatile String serverPath = "/netty-tunnel";
64 private volatile SSLContext sslContext;
65 private volatile String[] enabledSslCipherSuites;
66 private volatile String[] enabledSslProtocols;
67 private volatile boolean enableSslSessionCreation = true;
68
69
70
71
72 HttpTunnelingSocketChannelConfig(HttpTunnelingClientSocketChannel channel) {
73 this.channel = channel;
74 }
75
76
77
78
79
80 public String getServerName() {
81 return serverName;
82 }
83
84
85
86
87
88 public void setServerName(String serverName) {
89 this.serverName = serverName;
90 }
91
92
93
94
95
96 public String getServerPath() {
97 return serverPath;
98 }
99
100
101
102
103
104 public void setServerPath(String serverPath) {
105 if (serverPath == null) {
106 throw new NullPointerException("serverPath");
107 }
108 this.serverPath = serverPath;
109 }
110
111
112
113
114
115 public SSLContext getSslContext() {
116 return sslContext;
117 }
118
119
120
121
122
123 public void setSslContext(SSLContext sslContext) {
124 this.sslContext = sslContext;
125 }
126
127
128
129
130
131
132
133 public String[] getEnabledSslCipherSuites() {
134 String[] suites = enabledSslCipherSuites;
135 if (suites == null) {
136 return null;
137 } else {
138 return suites.clone();
139 }
140 }
141
142
143
144
145
146
147
148 public void setEnabledSslCipherSuites(String[] suites) {
149 if (suites == null) {
150 enabledSslCipherSuites = null;
151 } else {
152 enabledSslCipherSuites = suites.clone();
153 }
154 }
155
156
157
158
159
160
161 public String[] getEnabledSslProtocols() {
162 String[] protocols = enabledSslProtocols;
163 if (protocols == null) {
164 return null;
165 } else {
166 return protocols.clone();
167 }
168 }
169
170
171
172
173
174
175 public void setEnabledSslProtocols(String[] protocols) {
176 if (protocols == null) {
177 enabledSslProtocols = null;
178 } else {
179 enabledSslProtocols = protocols.clone();
180 }
181 }
182
183
184
185
186
187
188
189 public boolean isEnableSslSessionCreation() {
190 return enableSslSessionCreation;
191 }
192
193
194
195
196
197
198
199 public void setEnableSslSessionCreation(boolean flag) {
200 enableSslSessionCreation = flag;
201 }
202
203 public void setOptions(Map<String, Object> options) {
204 for (Entry<String, Object> e: options.entrySet()) {
205 setOption(e.getKey(), e.getValue());
206 }
207 }
208
209 public boolean setOption(String key, Object value) {
210 if (channel.realChannel.getConfig().setOption(key, value)) {
211 return true;
212 }
213
214 if (key.equals("serverName")) {
215 setServerName(String.valueOf(value));
216 } else if (key.equals("serverPath")) {
217 setServerPath(String.valueOf(value));
218 } else if (key.equals("sslContext")) {
219 setSslContext((SSLContext) value);
220 } else if (key.equals("enabledSslCipherSuites")) {
221 setEnabledSslCipherSuites(ConversionUtil.toStringArray(value));
222 } else if (key.equals("enabledSslProtocols")) {
223 setEnabledSslProtocols(ConversionUtil.toStringArray(value));
224 } else if (key.equals("enableSslSessionCreation")) {
225 setEnableSslSessionCreation(ConversionUtil.toBoolean(value));
226 } else {
227 return false;
228 }
229
230 return true;
231 }
232
233 public int getReceiveBufferSize() {
234 return channel.realChannel.getConfig().getReceiveBufferSize();
235 }
236
237 public int getSendBufferSize() {
238 return channel.realChannel.getConfig().getSendBufferSize();
239 }
240
241 public int getSoLinger() {
242 return channel.realChannel.getConfig().getSoLinger();
243 }
244
245 public int getTrafficClass() {
246 return channel.realChannel.getConfig().getTrafficClass();
247 }
248
249 public boolean isKeepAlive() {
250 return channel.realChannel.getConfig().isKeepAlive();
251 }
252
253 public boolean isReuseAddress() {
254 return channel.realChannel.getConfig().isReuseAddress();
255 }
256
257 public boolean isTcpNoDelay() {
258 return channel.realChannel.getConfig().isTcpNoDelay();
259 }
260
261 public void setKeepAlive(boolean keepAlive) {
262 channel.realChannel.getConfig().setKeepAlive(keepAlive);
263 }
264
265 public void setPerformancePreferences(
266 int connectionTime, int latency, int bandwidth) {
267 channel.realChannel.getConfig().setPerformancePreferences(connectionTime, latency, bandwidth);
268 }
269
270 public void setReceiveBufferSize(int receiveBufferSize) {
271 channel.realChannel.getConfig().setReceiveBufferSize(receiveBufferSize);
272 }
273
274 public void setReuseAddress(boolean reuseAddress) {
275 channel.realChannel.getConfig().setReuseAddress(reuseAddress);
276 }
277
278 public void setSendBufferSize(int sendBufferSize) {
279 channel.realChannel.getConfig().setSendBufferSize(sendBufferSize);
280
281 }
282
283 public void setSoLinger(int soLinger) {
284 channel.realChannel.getConfig().setSoLinger(soLinger);
285 }
286
287 public void setTcpNoDelay(boolean tcpNoDelay) {
288 channel.realChannel.getConfig().setTcpNoDelay(tcpNoDelay);
289 }
290
291 public void setTrafficClass(int trafficClass) {
292 channel.realChannel.getConfig().setTrafficClass(trafficClass);
293 }
294
295 public ChannelBufferFactory getBufferFactory() {
296 return channel.realChannel.getConfig().getBufferFactory();
297 }
298
299 public int getConnectTimeoutMillis() {
300 return channel.realChannel.getConfig().getConnectTimeoutMillis();
301 }
302
303 public ChannelPipelineFactory getPipelineFactory() {
304 return channel.realChannel.getConfig().getPipelineFactory();
305 }
306
307 public void setBufferFactory(ChannelBufferFactory bufferFactory) {
308 channel.realChannel.getConfig().setBufferFactory(bufferFactory);
309 }
310
311 public void setConnectTimeoutMillis(int connectTimeoutMillis) {
312 channel.realChannel.getConfig().setConnectTimeoutMillis(connectTimeoutMillis);
313 }
314
315 public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
316 channel.realChannel.getConfig().setPipelineFactory(pipelineFactory);
317 }
318 }