Skip to content

Commit

Permalink
WebServer related fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahad Rana authored and Ahad Rana committed Nov 14, 2011
1 parent 595cd94 commit 61efd5a
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions src/org/commoncrawl/server/WebServer.java
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.Semaphore;
Expand Down Expand Up @@ -177,22 +178,10 @@ public WebServer(CommonCrawlServer hostServer, String bindAddress, int port,
String logDir = System.getProperty("commoncrawl.log.dir");

// set up the context for "/" jsp files
String webappDir = null;
File webappDir = null;

if (hostServer.getWebAppName() != null) {
try {
webappDir = getWebAppsPath("webapps" + File.separator
+ hostServer.getWebAppName() + "/");
} catch (FileNotFoundException e) {
// Retry. Resource may be inside jar on a windows machine.
webappDir = getWebAppsPath("webapps/" + hostServer.getWebAppName()
+ "/");
}

URL webAppURL = null;
if (webappDir != null) {
webAppURL = new URL(webappDir);
}
webappDir = getWebAppsPath();

LOG.info("WebApps Dir is:" + webappDir);

Expand All @@ -207,11 +196,11 @@ public WebServer(CommonCrawlServer hostServer, String bindAddress, int port,

webAppContext.setContextPath("/");

((WebAppContext) this.webAppContext).setWar(webappDir);
((WebAppContext) this.webAppContext).setWar(webappDir.getAbsolutePath());

// if (webAppURL != null) {
// set up the context for "/static/*"
File webAppStaticDir = new File(webAppURL.getPath(), "/static");
File webAppStaticDir = new File(webappDir, "/static");

File files[] = webAppStaticDir.listFiles();
boolean hasStaticFilesInRoot = false;
Expand Down Expand Up @@ -328,22 +317,19 @@ public Object getAttribute(String name) {
*
* @return the pathname as a URL
*/
public static String getWebAppsPath() throws IOException {
return getWebAppsPath("webapps");
}
public File getWebAppsPath() throws IOException {
String webAppName = _hostServer.getWebAppName();

/**
* Get the pathname to the <code>patch</code> files.
*
* @param path
* Path to find.
* @return the pathname as a URL
*/
public static String getWebAppsPath(final String path) throws IOException {
URL url = WebServer.class.getClassLoader().getResource(path);
URL url = WebServer.class.getClassLoader().getResource(webAppName);
if (url == null)
throw new IOException("webapps not found in CLASSPATH");
return url.toExternalForm();
throw new IOException("webapps path not found in CLASSPATH");

try {
return new File(url.toURI());
} catch (URISyntaxException e) {
LOG.error(CCStringUtils.stringifyException(e));
throw new IOException(e);
}
}

/**
Expand Down

0 comments on commit 61efd5a

Please sign in to comment.