Lines 26-31
Link Here
|
26 |
import java.net.ProxySelector; |
26 |
import java.net.ProxySelector; |
27 |
import java.net.SocketAddress; |
27 |
import java.net.SocketAddress; |
28 |
import java.net.URI; |
28 |
import java.net.URI; |
|
|
29 |
import java.net.URISyntaxException; |
29 |
import java.nio.ByteBuffer; |
30 |
import java.nio.ByteBuffer; |
30 |
import java.nio.channels.AsynchronousChannelGroup; |
31 |
import java.nio.channels.AsynchronousChannelGroup; |
31 |
import java.nio.channels.AsynchronousSocketChannel; |
32 |
import java.nio.channels.AsynchronousSocketChannel; |
Lines 98-103
Link Here
|
98 |
private volatile long defaultMaxSessionIdleTimeout = 0; |
99 |
private volatile long defaultMaxSessionIdleTimeout = 0; |
99 |
private int backgroundProcessCount = 0; |
100 |
private int backgroundProcessCount = 0; |
100 |
private int processPeriod = Constants.DEFAULT_PROCESS_PERIOD; |
101 |
private int processPeriod = Constants.DEFAULT_PROCESS_PERIOD; |
|
|
102 |
private final Set<URI> redirectSet = new HashSet<>(Constants.MAX_REDIRECTIONS); |
101 |
|
103 |
|
102 |
private InstanceManager instanceManager; |
104 |
private InstanceManager instanceManager; |
103 |
|
105 |
|
Lines 340-347
Link Here
|
340 |
writeRequest(channel, request, timeout); |
342 |
writeRequest(channel, request, timeout); |
341 |
|
343 |
|
342 |
HttpResponse httpResponse = processResponse(response, channel, timeout); |
344 |
HttpResponse httpResponse = processResponse(response, channel, timeout); |
343 |
// TODO: Handle redirects |
345 |
|
344 |
if (httpResponse.status != 101) { |
346 |
if (httpResponse.status != 101) { |
|
|
347 |
if(isRedirectStatus(httpResponse.status)){ |
348 |
if (!Constants.REDIRECT_ENABLED) { |
349 |
throw new DeploymentException(sm.getString("wsWebSocketContainer.redirectDisabled", |
350 |
Integer.toString(httpResponse.status))); |
351 |
} |
352 |
|
353 |
List<String> locationHeader = httpResponse.getHandshakeResponse().getHeaders() |
354 |
.get(Constants.LOCATION_HEADER_NAME); |
355 |
|
356 |
if (locationHeader == null || locationHeader.isEmpty() || locationHeader.get(0) == null |
357 |
|| locationHeader.get(0).isEmpty()) { |
358 |
throw new DeploymentException(sm.getString("wsWebSocketContainer.missingLocationHeader", |
359 |
Integer.toString(httpResponse.status))); |
360 |
} |
361 |
|
362 |
URI redirectLocation = URI.create(locationHeader.get(0)).normalize(); |
363 |
|
364 |
if (!redirectLocation.isAbsolute()) { |
365 |
redirectLocation = path.resolve(redirectLocation); |
366 |
} |
367 |
|
368 |
String redirectScheme = redirectLocation.getScheme().toLowerCase(); |
369 |
|
370 |
if (redirectScheme.startsWith("http")) { |
371 |
redirectLocation = new URI(redirectScheme.replace("http", "ws"), |
372 |
redirectLocation.getUserInfo(), redirectLocation.getHost(), |
373 |
redirectLocation.getPort(), redirectLocation.getPath(), |
374 |
redirectLocation.getQuery(), redirectLocation.getFragment()); |
375 |
} |
376 |
|
377 |
if (!redirectSet.add(redirectLocation) || redirectSet.size() > Constants.MAX_REDIRECTIONS) { |
378 |
throw new DeploymentException(sm.getString("wsWebSocketContainer.redirectThreshold", |
379 |
redirectLocation, Integer.toString(redirectSet.size()), |
380 |
Integer.toString(Constants.MAX_REDIRECTIONS))); |
381 |
} |
382 |
|
383 |
return connectToServer(endpoint, clientEndpointConfiguration, redirectLocation); |
384 |
|
385 |
} |
345 |
throw new DeploymentException(sm.getString("wsWebSocketContainer.invalidStatus", |
386 |
throw new DeploymentException(sm.getString("wsWebSocketContainer.invalidStatus", |
346 |
Integer.toString(httpResponse.status))); |
387 |
Integer.toString(httpResponse.status))); |
347 |
} |
388 |
} |
Lines 390-396
Link Here
|
390 |
|
431 |
|
391 |
success = true; |
432 |
success = true; |
392 |
} catch (ExecutionException | InterruptedException | SSLException | |
433 |
} catch (ExecutionException | InterruptedException | SSLException | |
393 |
EOFException | TimeoutException e) { |
434 |
EOFException | TimeoutException | URISyntaxException e) { |
394 |
throw new DeploymentException( |
435 |
throw new DeploymentException( |
395 |
sm.getString("wsWebSocketContainer.httpRequestFailed"), e); |
436 |
sm.getString("wsWebSocketContainer.httpRequestFailed"), e); |
396 |
} finally { |
437 |
} finally { |
Lines 446-453
Link Here
|
446 |
toWrite -= thisWrite.intValue(); |
487 |
toWrite -= thisWrite.intValue(); |
447 |
} |
488 |
} |
448 |
} |
489 |
} |
|
|
490 |
|
491 |
|
492 |
private static boolean isRedirectStatus(int httpResponseCode) { |
449 |
|
493 |
|
|
|
494 |
boolean isRedirect = false; |
450 |
|
495 |
|
|
|
496 |
switch (httpResponseCode) { |
497 |
case Constants.MULTIPLE_CHOICES: |
498 |
case Constants.MOVED_PERMANENTLY: |
499 |
case Constants.FOUND: |
500 |
case Constants.SEE_OTHER: |
501 |
case Constants.USE_PROXY: |
502 |
case Constants.TEMPORARY_REDIRECT: |
503 |
isRedirect = true; |
504 |
break; |
505 |
default: |
506 |
break; |
507 |
} |
508 |
|
509 |
return isRedirect; |
510 |
} |
511 |
|
451 |
private static ByteBuffer createProxyRequest(String host, int port) { |
512 |
private static ByteBuffer createProxyRequest(String host, int port) { |
452 |
StringBuilder request = new StringBuilder(); |
513 |
StringBuilder request = new StringBuilder(); |
453 |
request.append("CONNECT "); |
514 |
request.append("CONNECT "); |