You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by le...@apache.org on 2014/09/30 02:37:00 UTC
svn commit: r1628342 - in /nutch/branches/2.x: CHANGES.txt
src/java/org/apache/nutch/webui/NutchUiServer.java
Author: lewismc
Date: Tue Sep 30 00:37:00 2014
New Revision: 1628342
URL: http://svn.apache.org/r1628342
Log:
NUTCH-1859 Make Nutch webapp port configurable
Modified:
nutch/branches/2.x/CHANGES.txt
nutch/branches/2.x/src/java/org/apache/nutch/webui/NutchUiServer.java
Modified: nutch/branches/2.x/CHANGES.txt
URL: http://svn.apache.org/viewvc/nutch/branches/2.x/CHANGES.txt?rev=1628342&r1=1628341&r2=1628342&view=diff
==============================================================================
--- nutch/branches/2.x/CHANGES.txt (original)
+++ nutch/branches/2.x/CHANGES.txt Tue Sep 30 00:37:00 2014
@@ -2,6 +2,8 @@ Nutch Change Log
Current Development
+* NUTCH-1859 Make Nutch webapp port configurable (Nima Falaki via lewismc)
+
* NUTCH-1848 Bug in DashboardPage.html instances counter (Nima Falaki via lewismc)
* NUTCH-841 Create a Wicket-based Web Application for Nutch (Fjodor Vershinin via lewismc)
Modified: nutch/branches/2.x/src/java/org/apache/nutch/webui/NutchUiServer.java
URL: http://svn.apache.org/viewvc/nutch/branches/2.x/src/java/org/apache/nutch/webui/NutchUiServer.java?rev=1628342&r1=1628341&r2=1628342&view=diff
==============================================================================
--- nutch/branches/2.x/src/java/org/apache/nutch/webui/NutchUiServer.java (original)
+++ nutch/branches/2.x/src/java/org/apache/nutch/webui/NutchUiServer.java Tue Sep 30 00:37:00 2014
@@ -16,6 +16,14 @@
*/
package org.apache.nutch.webui;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.hadoop.util.StringUtils;
import org.apache.wicket.protocol.http.WicketFilter;
import org.apache.wicket.spring.SpringWebApplicationFactory;
import org.mortbay.jetty.Handler;
@@ -29,15 +37,36 @@ import org.springframework.web.context.r
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
public class NutchUiServer {
- private static final String APP_FACTORY_NAME = SpringWebApplicationFactory.class.getName();
+ private static final String APP_FACTORY_NAME = SpringWebApplicationFactory.class
+ .getName();
private static final String CONFIG_LOCATION = "org.apache.nutch.webui";
+ private static final String CMD_PORT = "port";
+ private static Integer port = 8080;
public static void main(String[] args) throws Exception {
+ CommandLineParser parser = new GnuParser();
+ Options options = createWebAppOptions();
+ CommandLine commandLine = null;
+ HelpFormatter formatter = new HelpFormatter();
+ try {
+ commandLine = parser.parse(options, args);
+ } catch (Exception e) {
+ formatter.printHelp("NutchUiServer", options, true);
+ StringUtils.stringifyException(e);
+ }
+
+ if (commandLine.hasOption("help")) {
+ formatter.printHelp("NutchUiServer", options, true);
+ return;
+ }
+ if (commandLine.hasOption(CMD_PORT)) {
+ port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
+ }
startServer();
}
private static void startServer() throws Exception, InterruptedException {
- Server server = new Server(8080);
+ Server server = new Server(port);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(DefaultServlet.class, "/*");
@@ -61,4 +90,15 @@ public class NutchUiServer {
return context;
}
+ private static Options createWebAppOptions() {
+ Options options = new Options();
+ Option helpOpt = new Option("h", "help", false, "show this help message");
+ OptionBuilder.withDescription("Port to run the WebApplication on.");
+ OptionBuilder.hasOptionalArg();
+ OptionBuilder.withArgName("port number");
+ options.addOption(OptionBuilder.create(CMD_PORT));
+ options.addOption(helpOpt);
+ return options;
+ }
+
}