Java Code Examples for org.eclipse.jetty.server.handler.ResourceHandler#setResourceBase()

The following examples show how to use org.eclipse.jetty.server.handler.ResourceHandler#setResourceBase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationServerDriver.java    From candybean with GNU Affero General Public License v3.0 7 votes vote down vote up
public static void main (String args[]) throws Exception{
	logger.info("Starting JETTY server");
    Server server = new Server(8080);
    
       ResourceHandler resourceHandler = new ResourceHandler();
       resourceHandler.setDirectoriesListed(true);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");
       
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");
       context.addServlet(new ServletHolder(new ConfigurationServlet()),"/cfg");
       context.addServlet(new ServletHolder(new SaveConfigurationServlet()),"/cfg/save");
       context.addServlet(new ServletHolder(new LoadConfigurationServlet()),"/cfg/load");
       
       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resourceHandler, context });
       server.setHandler(handlers);

       server.start();
	logger.info("Configuration server started at: http://localhost:8080/cfg");
       server.join();
}
 
Example 2
Source File: Main.java    From stepic_java_webserver with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example 3
Source File: Application.java    From vk-java-sdk with MIT License 6 votes vote down vote up
private static void initServer(Properties properties) throws Exception {
    Integer port = Integer.valueOf(properties.getProperty("server.port"));
    String host = properties.getProperty("server.host");

    Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
    String clientSecret = properties.getProperty("client.secret");

    HandlerCollection handlers = new HandlerCollection();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());

    VkApiClient vk = new VkApiClient(new HttpTransportClient());
    handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});

    Server server = new Server(port);
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example 4
Source File: GraphQlServer.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  // Embedded Jetty server
  Server server = new Server(HTTP_PORT);
  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setWelcomeFiles(new String[] {"index.html"});
  resourceHandler.setDirectoriesListed(true);
  // resource base is relative to the WORKSPACE file
  resourceHandler.setResourceBase("./src/main/resources");
  HandlerList handlerList = new HandlerList();
  handlerList.setHandlers(
      new Handler[] {resourceHandler, new GraphQlHandler(), new DefaultHandler()});
  server.setHandler(handlerList);
  server.start();
  logger.info("Server running on port " + HTTP_PORT);
  server.join();
}
 
Example 5
Source File: ApiServer.java    From lancoder with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
	try {
		Properties jettyShutUpProperties = new Properties();
		jettyShutUpProperties.setProperty("org.eclipse.jetty.LEVEL", "WARN");
		StdErrLog.setProperties(jettyShutUpProperties);

		server = new Server(master.getConfig().getApiServerPort());

		// static resources handler
		ContextHandler ctxStatic = new ContextHandler("/");
		ResourceHandler staticHandler = new ResourceHandler();
		staticHandler.setResourceBase(this.getClass().getClassLoader().getResource(WEB_DIR).toExternalForm());
		// staticHandler.setResourceBase("src/main/web/web_resources");
		staticHandler.setDirectoriesListed(true);
		ctxStatic.setHandler(staticHandler);

		// api handler
		ContextHandler ctxApi = buildServletContextHandler();
		ctxApi.setContextPath("/api");

		ContextHandlerCollection contexts = new ContextHandlerCollection();
		contexts.setHandlers(new Handler[] { ctxStatic, ctxApi });
		server.setHandler(contexts);

		server.start();
		server.join();
	} catch (Exception e) {
		// TODO alert master api server api crashed
		e.printStackTrace();
	}
}
 
Example 6
Source File: JettyServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    sb.serviceUnder(
            "/jsp/",
            JettyService.builder()
                        .handler(newWebAppContext())
                        .configurator(s -> jettyBeans.addAll(s.getBeans()))
                        .build()
                        .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/default/",
            JettyService.builder()
                        .handler(new DefaultHandler())
                        .build());

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(webAppRoot().getPath());
    sb.serviceUnder(
            "/resources/",
            JettyService.builder()
                        .handler(resourceHandler)
                        .build());
}
 
Example 7
Source File: Starter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void start() {

		Server server = new Server(9080);
		ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
		servletContextHandler.setContextPath("/");
		servletContextHandler.setResourceBase("src/main/webapp");

		final String webAppDirectory = JumbuneInfo.getHome() + "modules/webapp";
		final ResourceHandler resHandler = new ResourceHandler();
		resHandler.setResourceBase(webAppDirectory);
		final ContextHandler ctx = new ContextHandler("/");
		ctx.setHandler(resHandler);
		servletContextHandler.setSessionHandler(new SessionHandler());

		ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/apis/*");
		servletHolder.setInitOrder(0);
		servletHolder.setAsyncSupported(true);
		servletHolder.setInitParameter("jersey.config.server.provider.packages", "org.jumbune.web.services");
		servletHolder.setInitParameter("jersey.config.server.provider.classnames",
				"org.glassfish.jersey.media.multipart.MultiPartFeature");

		try {
			server.insertHandler(servletContextHandler);
			server.insertHandler(resHandler);
			server.start();
			server.join();
		} catch (Exception e) {
			LOGGER.error("Error occurred while starting Jetty", e);
			System.exit(1);
		}
	}
 
Example 8
Source File: WebServer.java    From pf4j-update with Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
    server = new Server(port);
    server.setStopAtShutdown(true);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(resourceBase);
    resourceHandler.setDirectoriesListed(true);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
}
 
Example 9
Source File: RemoteRepositoryConnectivityCheckTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
protected Server buildStaticServer( Path path )
{
    Server repoServer = new Server(  );

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed( true );
    resourceHandler.setWelcomeFiles( new String[]{ "index.html" } );
    resourceHandler.setResourceBase( path.toAbsolutePath().toString() );

    HandlerList handlers = new HandlerList();
    handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
    repoServer.setHandler( handlers );

    return repoServer;
}
 
Example 10
Source File: JettyServer.java    From sumk with Apache License 2.0 5 votes vote down vote up
protected synchronized void init() {
	try {
		buildJettyProperties();
		server = new Server(new ExecutorThreadPool(HttpExcutors.getThreadPool()));
		ServerConnector connector = this.createConnector();
		Logs.http().info("listen port: {}", port);
		String host = StartContext.httpHost();
		if (host != null && host.length() > 0) {
			connector.setHost(host);
		}
		connector.setPort(port);

		server.setConnectors(new Connector[] { connector });
		ServletContextHandler context = createServletContextHandler();
		context.setContextPath(AppInfo.get("sumk.jetty.web.root", "/"));
		context.addEventListener(new SumkLoaderListener());
		addUserListener(context, Arrays.asList(ServletContextListener.class, ContextScopeListener.class));
		String resourcePath = AppInfo.get("sumk.jetty.resource");
		if (StringUtil.isNotEmpty(resourcePath)) {
			ResourceHandler resourceHandler = JettyHandlerSupplier.resourceHandlerSupplier().get();
			if (resourceHandler != null) {
				resourceHandler.setResourceBase(resourcePath);
				context.insertHandler(resourceHandler);
			}
		}

		if (AppInfo.getBoolean("sumk.jetty.session.enable", false)) {
			SessionHandler h = JettyHandlerSupplier.sessionHandlerSupplier().get();
			if (h != null) {
				context.insertHandler(h);
			}
		}
		server.setHandler(context);
	} catch (Throwable e) {
		Log.printStack("sumk.http", e);
		System.exit(1);
	}

}
 
Example 11
Source File: BaseIntTest.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
@BeforeAll
@BeforeClass
public static void startTestPageServer() throws Exception {
    server = new Server(TEST_PAGE_SERVER_PORT);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(getTestResourceFolder().getCanonicalPath());
    server.setHandler(resourceHandler);
    server.start();
}
 
Example 12
Source File: Main.java    From stepic_java_webserver with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        logger.error("Use port as the first argument");
        System.exit(1);
    }

    String portString = args[0];
    int port = Integer.valueOf(portString);

    logger.info("Starting at http://127.0.0.1:" + portString);

    AccountServerI accountServer = new AccountServer(1);

    AccountServerControllerMBean serverStatistics = new AccountServerController(accountServer);
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("ServerManager:type=AccountServerController");
    mbs.registerMBean(serverStatistics, name);

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new HomePageServlet(accountServer)), HomePageServlet.PAGE_URL);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("static");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    logger.info("Server started");

    server.join();
}
 
Example 13
Source File: ReportOpen.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Set up server for report directory.
 */
private Server setUpServer() {
    Server server = new Server(port);
    ResourceHandler handler = new ResourceHandler();
    handler.setDirectoriesListed(true);
    handler.setWelcomeFiles(new String[]{"index.html"});
    handler.setResourceBase(getReportDirectoryPath().toAbsolutePath().toString());
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{handler, new DefaultHandler()});
    server.setStopAtShutdown(true);
    server.setHandler(handlers);
    return server;
}
 
Example 14
Source File: JettyHttpServer.java    From cloudhopper-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a directory for resources such as files containing html, images, etc.
 * to be served up automatically be this server.<br>
 * CAUTION: A resource base can only be added BEFORE the server is started.
 * @param resourceBaseDir The directory containing resources (basically the
 *      web root)
 */
public void addResourceBase(String resourceBaseDir) {
    // handles resources like images, files, etc..
    logger.info("HttpServer [{}] adding resource base dir [{}]", configuration.safeGetName(), resourceBaseDir);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(resourceBaseDir);
    handlers.addHandler(resourceHandler);
}
 
Example 15
Source File: ManagerApiMicroService.java    From apiman with Apache License 2.0 4 votes vote down vote up
/**
 * Configure the web application(s).
 * @param handlers
 * @throws Exception
 */
protected void addModulesToJetty(HandlerCollection handlers) throws Exception {
	/* *************
     * Manager API
     * ************* */
    ServletContextHandler apiManServer = new ServletContextHandler(ServletContextHandler.SESSIONS);
    addSecurityHandler(apiManServer);
    apiManServer.setContextPath("/apiman");
    apiManServer.addEventListener(new Listener());
    apiManServer.addEventListener(new BeanManagerResourceBindingListener());
    apiManServer.addEventListener(new ResteasyBootstrap());
    apiManServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(ApimanCorsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(DisableCachingFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    addAuthFilter(apiManServer);
    apiManServer.addFilter(DefaultSecurityContextFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(RootResourceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    apiManServer.addFilter(ManagerApiMicroServiceTxWatchdogFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    ServletHolder resteasyServlet = new ServletHolder(new HttpServletDispatcher());
    resteasyServlet.setInitParameter("javax.ws.rs.Application", ManagerApiMicroServiceApplication.class.getName());
    apiManServer.addServlet(resteasyServlet, "/*");

    apiManServer.setInitParameter("resteasy.injector.factory", "org.jboss.resteasy.cdi.CdiInjectorFactory");
    apiManServer.setInitParameter("resteasy.scan", "true");
    apiManServer.setInitParameter("resteasy.servlet.mapping.prefix", "");

    handlers.addHandler(apiManServer);

    /* ********** *
     * Manager UI *
     * ********** */
    ResourceHandler apimanUiServer = new ResourceHandler() {
        /**
         * @see org.eclipse.jetty.server.handler.ResourceHandler#getResource(java.lang.String)
         */
        @Override
        public Resource getResource(String path) {
            Resource resource = null;

            if (path == null || path.equals("/") || path.equals("/index.html")) {
                path = "/index.html";
            }
            if (path.startsWith("/apimanui/api-manager") || path.equals("/apimanui") || path.equals("/apimanui/")) {
                path = "/apimanui/index.html";
            }
            if (path.equals("/apimanui/apiman/config.js")) {
                resource = getConfigResource(path);
            }
            if (path.equals("/apimanui/apiman/translations.js")) {
                resource = getTranslationsResource(path);
            }

            if (resource == null) {
                URL url = getClass().getResource(path);
                if (url != null) {
                    resource = new ApimanResource(url);
                }
            }

            return resource;
        }
    };
    apimanUiServer.setResourceBase("/apimanui/");
    apimanUiServer.setWelcomeFiles(new String[] { "index.html" });
    handlers.addHandler(apimanUiServer);
}
 
Example 16
Source File: Activator.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
public void start(BundleContext context) throws Exception {
	super.start(context);

	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	String webappRoot = workspace.getRoot().getLocation().toString().concat("/webapp");
	new File(webappRoot).mkdirs();

	Activator.WEB_APP_WORKSPACE = webappRoot;

	// create the server on a free port
	Server server = new Server(0);

	// Configure the ResourceHandler. Setting the resource base indicates where the
	// files should be served out of.
	ResourceHandler resource_handler = new ResourceHandler();
	resource_handler.setDirectoriesListed(true);
	resource_handler.setResourceBase(webappRoot);

	// Add the ResourceHandler to the server.
	HandlerCollection handlers = new HandlerCollection(true);
	handlers.addHandler(resource_handler);

	server.setHandler(handlers);

	// Start server up.
	try {
		server.start();
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	// Get the URI of the server and set it global for the
	// diagram handlers to access
	if (null != server && null != server.getURI()) {
		String localhost = server.getURI().toString();
		Activator.URL = localhost;
	}

	writeVegaFiles();

	plugin = this;
}
 
Example 17
Source File: DemoApp.java    From bromium with MIT License 4 votes vote down vote up
public void runOnSeparateThread() throws Exception {
    for (String resource: resourcesToBeExtractedInDirectory) {
        InputStream resourceAsStream = this.getClass().getResourceAsStream("/" + resource);
        File outputFile = Paths.get(baseOutputDirectory.getAbsolutePath(), resource).toFile();
        FileOutputStream fileOutputStream =  FileUtils.openOutputStream(outputFile);
        IOUtils.copy(resourceAsStream, fileOutputStream);
    }

    ResourceConfig config = new ResourceConfig();
    config.packages("com.hribol.bromium.demo.app");
    ServletHolder servlet = new ServletHolder(new ServletContainer(config));

    server = new Server(0);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(baseOutputDirectory.getAbsolutePath());
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[] {
            "index.html"
    });

    ServletContextHandler context = new ServletContextHandler(server, "/*");
    context.addServlet(servlet, "/*");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {
            resourceHandler,
            context
    });
    server.setHandler(handlers);

    server.start();
    this.port = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
    logger.info("Server started on port " + port);

    new Thread(() -> {
        try {
            server.join();
        } catch (InterruptedException e) {
            logger.info("Interrupted!", e);
        }
    }).start();
}
 
Example 18
Source File: ServerLauncher.java    From xtext-web with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	Server server = new Server(new InetSocketAddress("localhost", 8080));
	RewriteHandler rewriteHandler = new RewriteHandler();
	server.setHandler(rewriteHandler);
	RewriteRegexRule rule = new RewriteRegexRule();
	rule.setRegex("/xtext/@xtext-version-placeholder@/(.*)");
	rule.setReplacement("/xtext/$1");
	rule.setTerminating(false);
	rewriteHandler.addRule(rule);
	HandlerList handlerList = new HandlerList();
	ResourceHandler resourceHandler1 = new ResourceHandler();
	resourceHandler1.setResourceBase("src/main/webapp");
	resourceHandler1.setWelcomeFiles(new String[] { "index.html" });
	ResourceHandler resourceHandler2 = new ResourceHandler();
	resourceHandler2.setResourceBase("../org.eclipse.xtext.web/src/main/css");
	WebAppContext webAppContext = new WebAppContext();
	webAppContext.setResourceBase("../org.eclipse.xtext.web/src/main/js");
	webAppContext.setContextPath("/");
	webAppContext.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebXmlConfiguration(),
			new WebInfConfiguration(), new MetaInfConfiguration() });
	webAppContext.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN,
			".*/org\\.eclipse\\.xtext\\.web.*,.*/org.webjars.*");

	handlerList.setHandlers(new Handler[] { resourceHandler1, resourceHandler2, webAppContext });
	rewriteHandler.setHandler(handlerList);
	Slf4jLog log = new Slf4jLog(ServerLauncher.class.getName());
	try {
		server.start();
		log.info("Server started " + server.getURI() + "...");
		new Thread() {

			public void run() {
				try {
					log.info("Press enter to stop the server...");
					int key = System.in.read();
					if (key != -1) {
						server.stop();
					} else {
						log.warn(
								"Console input is not available. In order to stop the server, you need to cancel process manually.");
					}
				} catch (Exception e) {
					log.warn(e);
				}
			}

		}.start();
		server.join();
	} catch (Exception exception) {
		log.warn(exception.getMessage());
		System.exit(1);
	}
}
 
Example 19
Source File: RestRouteBuilder.java    From Ardulink-2 with Apache License 2.0 4 votes vote down vote up
private ResourceHandler resourceHandler(URI resourceURI) throws URISyntaxException {
	ResourceHandler rh = new ResourceHandler();
	rh.setResourceBase(resourceURI.toASCIIString());
	return rh;
}
 
Example 20
Source File: PhrasalService.java    From phrasal with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Start the service.
   * 
   * @param args
   */
  public static void main(String[] args) {
    Properties options = StringUtils.argsToProperties(args, optionArgDefs());
    int port = PropertiesUtils.getInt(options, "p", DEFAULT_HTTP_PORT);
    boolean loadMockServlet = PropertiesUtils.getBool(options, "m", false);
    boolean localHost = PropertiesUtils.getBool(options, "l", false);
    String uiFile = options.getProperty("u", "debug.html");
    String resourcePath = options.getProperty("r", ".");

    // Parse arguments
    String argList = options.getProperty("",null);
    String[] parsedArgs = argList == null ? null : argList.split("\\s+");
    if (parsedArgs == null || parsedArgs.length != 1) {
      System.out.println(usage());
      System.exit(-1);
    }
    String phrasalIniFile = parsedArgs[0];
    
    // Setup the jetty server
    Server server = new Server();

    // Jetty 8 way of configuring the server
//    Connector connector = new SelectChannelConnector();
//    connector.setPort(port);
//    server.addConnector(connector);

//  Jetty9 way of configuring the server
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);

    if (localHost) {
      connector.setHost(DEBUG_URL);
    }
    
    // Setup the servlet context
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
 
    // Add Phrasal servlet
    PhrasalServlet servlet = loadMockServlet ? new PhrasalServlet() : new PhrasalServlet(phrasalIniFile);
    context.addServlet(new ServletHolder(servlet), SERVLET_ROOT);

    // TODO(spenceg): gzip compression causes an encoding problem for unicode characters
    // on the client. Not sure if the compression or decompression is the problem.
//    EnumSet<DispatcherType> dispatches = EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC);
//    context.addFilter(new FilterHolder(new IncludableGzipFilter()), "/t", dispatches);

    // Add debugging web-page
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[]{ uiFile });
    resourceHandler.setResourceBase(resourcePath);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resourceHandler, context });
    server.setHandler(handlers);
    
    // Start the service
    try {
      logger.info("Starting PhrasalService on port: " + String.valueOf(port));
      server.start();
      server.join();
    } catch (Exception e) {
      logger.error("Servlet crashed. Service shutting down.");
      e.printStackTrace();
    }
  }