Skip to content

Commit

Permalink
BZ-1100150 - Cannot open 'Process & Task Dashboard' under NAT environ…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
dgutierr committed Sep 3, 2014
1 parent 9b81fe8 commit 706052e
Showing 1 changed file with 22 additions and 48 deletions.
Expand Up @@ -8,10 +8,7 @@
import javax.enterprise.context.ApplicationScoped;

import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;

@Service
@ApplicationScoped
Expand All @@ -26,22 +23,15 @@ public class DashboardRendererServiceImpl implements DashboardRendererService {
@Override
public ConnectionStatus getAppStatus(String theUrl) {
ConnectionStatus connectionStatus = new ConnectionStatus();

// Get a list of the urls to check for the given url
List<String> urls = explodeUrl(theUrl);
Exception exc = null;
for (String anUrl : urls) {
try {
// Check whether the service is available
int status = pingUrl(anUrl);
connectionStatus.setStatus(status);
return connectionStatus;
} catch (Exception e) {
exc = e;
}
try {
// Check whether the service is available
String targetUrl = resolveUrl(theUrl);
int status = pingUrl(targetUrl);
connectionStatus.setStatus(status);
} catch (Exception e) {
e.printStackTrace();
connectionStatus.setStatus(-1);
}
if (exc != null) exc.printStackTrace();
connectionStatus.setStatus(-1);
return connectionStatus;
}

Expand All @@ -58,37 +48,21 @@ protected int pingUrl(String anUrl) throws Exception {
return urlConnection.getResponseCode();
}

protected List<String> explodeUrl(String anUrl) {
List<String> results = new ArrayList<String>();

// Add the target URL
results.add(anUrl);

try {
// Get the new address (defaults to localhost).
String bindAddress = System.getProperty("dashbuilder.bind.address");
String bindPort = System.getProperty("dashbuilder.bind.port");
if (StringUtils.isBlank(bindAddress)) {
bindAddress = InetAddress.getLocalHost().getHostAddress();
}
protected String resolveUrl(String anUrl) throws Exception {
// Get the bind address/port.
String bindAddress = System.getProperty("dashbuilder.bind.address");
String bindPort = System.getProperty("dashbuilder.bind.port");

URL url = new URL(anUrl);
String host = url.getHost();
int port = url.getPort();
String newUrl = anUrl;
if (!host.equals(bindAddress)) {
newUrl = newUrl.replace(host, bindAddress);
}
if (!StringUtils.isBlank(bindPort) && port != Integer.parseInt(bindPort)) {
newUrl = newUrl.replace(Integer.toString(port), bindPort);
}
if (!anUrl.equals(newUrl)) {
results.add(newUrl);
}
} catch (Exception e) {
e.printStackTrace();
URL url = new URL(anUrl);
String host = url.getHost();
int port = url.getPort();
String targetUrl = anUrl;
if (!StringUtils.isBlank(bindAddress) && !host.equals(bindAddress)) {
targetUrl = targetUrl.replace(host, bindAddress);
}
if (!StringUtils.isBlank(bindPort) && port != Integer.parseInt(bindPort)) {
targetUrl = targetUrl.replace(Integer.toString(port), bindPort);
}
return results;
return !anUrl.equals(targetUrl) ? targetUrl :anUrl;
}

}

0 comments on commit 706052e

Please sign in to comment.