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 Jul 25, 2014
1 parent 82edbc7 commit d7ae4f1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
Expand Up @@ -45,11 +45,13 @@ public static String getDashboardURL(String preffix, String suffix, String local
if (localeName != null) {
if (!preffix.endsWith(SLASH)) result.append(SLASH);
if (GWT_DEFAULT_LOCALE.equals(localeName)) localeName = DASHBUILDER_DEFAULT_LOCALE;
result. append(localeName);
result.append(localeName);
}

if (suffix != null) {
if (!result.toString().endsWith(SLASH)) result.append(SLASH);
if (!result.toString().endsWith(SLASH) && !suffix.startsWith(SLASH)) {
result.append(SLASH);
}
result.append(suffix);
}

Expand Down
Expand Up @@ -7,23 +7,59 @@
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
public class DashboardRendererServiceImpl implements DashboardRendererService {

@Override
public ConnectionStatus getAppStatus(String anUrl) {
public ConnectionStatus getAppStatus(String theUrl) {
ConnectionStatus connectionStatus = new ConnectionStatus();
try{
URL url = new URL(anUrl);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
connectionStatus.setStatus(urlConnection.getResponseCode()) ;
}catch (Exception e){
e.printStackTrace();
connectionStatus.setStatus(-1);

// 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;
}
}
if (exc != null) exc.printStackTrace();
connectionStatus.setStatus(-1);
return connectionStatus;
}

protected int pingUrl(String anUrl) throws Exception {
URL url = new URL(anUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
return urlConnection.getResponseCode();
}

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

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

// Add the "localhost" version
try {
String host = new URL(anUrl).getHost();
String localHost = InetAddress.getLocalHost().getHostAddress();
if (!host.equals(localHost)) {
results.add(anUrl.replace(host, localHost));
}
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
}

0 comments on commit d7ae4f1

Please sign in to comment.