Skip to content

Commit

Permalink
made port settable on standalone server
Browse files Browse the repository at this point in the history
  • Loading branch information
edanuff committed Dec 30, 2011
1 parent 1efb54d commit 329d87a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions standalone/src/main/java/org/usergrid/standalone/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.jasper.runtime.JspFactoryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;
import org.glassfish.grizzly.http.server.util.ClassLoaderUtil;
import org.glassfish.grizzly.servlet.ServletHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -67,6 +68,8 @@ public class Server implements ApplicationContextAware {

protected QueueManagerFactory qmf;

int port = NetworkListener.DEFAULT_NETWORK_PORT;

public Server() {
instance = this;
}
Expand Down Expand Up @@ -96,6 +99,14 @@ public void startServerFromCommandLine(String[] args) {
startDatabaseWithServer = line.hasOption("db");
initializeDatabaseOnStart = line.hasOption("init");

if (line.hasOption("port")) {
try {
port = ((Number) line.getParsedOptionValue("port")).intValue();
} catch (ParseException exp) {
printCliHelp("Parsing failed. Reason: " + exp.getMessage());
return;
}
}
startServer();
}

Expand All @@ -105,7 +116,7 @@ public synchronized void startServer() {
startCassandra();
}

httpServer = HttpServer.createSimpleServer();
httpServer = HttpServer.createSimpleServer(".", port);

ServletHandler handler = new ServletHandler();

Expand Down Expand Up @@ -307,8 +318,16 @@ public Options createOptions() {
OptionBuilder.withDescription("Start database");
Option dbOption = OptionBuilder.create("db");

OptionBuilder.withDescription("Http port");
OptionBuilder.hasArg();
OptionBuilder.withArgName("PORT");
OptionBuilder.withLongOpt("port");
OptionBuilder.withType(Number.class);
Option portOption = OptionBuilder.create('p');

options.addOption(initOption);
options.addOption(dbOption);
options.addOption(portOption);

return options;
}
Expand Down

0 comments on commit 329d87a

Please sign in to comment.