Resolving the redirect is OK to fail
@@ -74,14 +74,7 @@ public class FullDuplexHttpStream {
throw new IllegalArgumentException(relativeTarget);
}
- // As this transport mode is using POST, it is necessary to resolve possible redirections using GET first.
- HttpURLConnection con = (HttpURLConnection) base.openConnection();
- if (authorization != null) {
- System.out.println("Auth added: " + authorization);
- con.addRequestProperty("Authorization", authorization);
- }
- con.getInputStream().close();
- this.base = con.getURL();
+ this.base = tryToResolveRedirects(base, authorization);
this.authorization = authorization;
URL target = new URL(this.base, relativeTarget);
@@ -91,7 +84,7 @@ public class FullDuplexHttpStream {
UUID uuid = UUID.randomUUID(); // so that the server can correlate those two connections
// server->client
- con = (HttpURLConnection) target.openConnection();
+ HttpURLConnection con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST to avoid caching
con.setRequestMethod("POST");
con.addRequestProperty("Session", uuid.toString());
@@ -127,6 +120,24 @@ public class FullDuplexHttpStream {
output = con.getOutputStream();
}
+ // As this transport mode is using POST, it is necessary to resolve possible redirections using GET first.
+ private URL tryToResolveRedirects(URL base, String authorization) {
+ try {
+ HttpURLConnection con = (HttpURLConnection) base.openConnection();
+ if (authorization != null) {
+ con.addRequestProperty("Authorization", authorization);
+ }
+ con.getInputStream().close();
+ base = con.getURL();
+ } catch (Exception ex) {
+ // Do not obscure the problem propagating the exception. If the problem is real it will manifest during the
+ // actual exchange so will be reported properly there. If it is not real (no permission in UI but sufficient
+ // for CLI connection using one of its mechanisms), there is no reason to bother user about it.
+ LOGGER.log(Level.FINE, "Failed to resolve potential redirects", ex);
+ }
+ return base;
+ }
+
static final int BLOCK_SIZE = 1024;
static final Logger LOGGER = Logger.getLogger(FullDuplexHttpStream.class.getName());
