Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Correct package name for JettyMain

  • Loading branch information...
commit 4d7f9447710d283144b335dafac5d8d01dc73ea9 1 parent 89abf1a
Howard M. Lewis Ship authored
138 tapx-heroku/src/main/java/com/howardlewiship/tapx/heroku/JettyMain.java
... ... @@ -1,143 +1,15 @@
1 1 package com.howardlewiship.tapx.heroku;
2 2
3   -import com.mongodb.DB;
4   -import com.mongodb.DBCollection;
5   -import com.mongodb.MongoURI;
6   -import org.apache.commons.cli.*;
7   -import org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager;
8   -import org.eclipse.jetty.nosql.mongodb.MongoSessionManager;
9   -import org.eclipse.jetty.server.Server;
10   -import org.eclipse.jetty.server.SessionIdManager;
11   -import org.eclipse.jetty.server.session.HashSessionManager;
12   -import org.eclipse.jetty.server.session.SessionHandler;
13   -import org.eclipse.jetty.webapp.WebAppContext;
14 3
15 4 /**
16   - * Launches Jetty to service the web application at {@code src/main/webapp}.
  5 + * Temporary shim; when first published and described on <a href="">James Ward's Blog</a>, the package name was off (missing an 's').
  6 + * This has been corrected, and this shim makes the older, invalid package name work. It may be removed at some time in the next few months.
  7 + *
  8 + * @deprecated Use {@link com.howardlewisship.tapx.heroku.JettyMain} instead
17 9 */
18 10 public class JettyMain {
19 11
20   - private final String webappFolder;
21   -
22   - private final String mongoURL;
23   -
24   - private final String sessionCollectionName;
25   -
26   - public JettyMain(String webappFolder, String mongoURL, String sessionCollectionName) {
27   - this.webappFolder = webappFolder;
28   - this.mongoURL = mongoURL;
29   - this.sessionCollectionName = sessionCollectionName;
30   - }
31   -
32   - private static boolean isBlank(String s) {
33   - return s == null || s.trim().length() == 0;
34   - }
35   -
36   - private static String firstEnvValue(String... envNames) {
37   - for (String name : envNames) {
38   - String value = System.getenv(name);
39   -
40   - if (!isBlank(name)) {
41   - return value;
42   - }
43   - }
44   -
45   - return null;
46   - }
47   -
48   - public void startServer() throws Exception {
49   -
50   - String webPort = System.getenv("PORT");
51   -
52   - int port = isBlank(webPort) ? 8080 : Integer.parseInt(webPort);
53   -
54   -
55   - Server server = new Server(port);
56   - WebAppContext root = new WebAppContext();
57   -
58   -
59   - SessionHandler sessionHandler = new SessionHandler();
60   -
61   - if (mongoURL != null) {
62   -
63   - System.out.printf("Starting Jetty server, port %d, for '%s', using MongoDB URL '%s' (session collection '%s').\n", port, webappFolder, mongoURL, sessionCollectionName);
64   -
65   - MongoURI mongoURI = new MongoURI(mongoURL);
66   - DB connectedDB = mongoURI.connectDB();
67   -
68   - if (mongoURI.getUsername() != null) {
69   - connectedDB.authenticate(mongoURI.getUsername(), mongoURI.getPassword());
70   - }
71   -
72   - DBCollection sessions = connectedDB.getCollection(sessionCollectionName);
73   -
74   - SessionIdManager sessionIdManager = new MongoSessionIdManager(server, sessions);
75   -
76   - MongoSessionManager manager = new MongoSessionManager();
77   -
78   - manager.setSessionIdManager(sessionIdManager);
79   -
80   - sessionHandler.setSessionManager(manager);
81   -
82   - } else {
83   - System.out.printf("Starting Jetty server, port %d, for '%s', using in-memory sessions only.\n", port, webappFolder);
84   -
85   - sessionHandler.setSessionManager(new HashSessionManager());
86   - }
87   -
88   - root.setSessionHandler(sessionHandler);
89   -
90   - root.setContextPath("/");
91   - root.setDescriptor(webappFolder + "/WEB-INF/web.xml");
92   - root.setResourceBase(webappFolder);
93   - root.setParentLoaderPriority(true);
94   -
95   - server.setHandler(root);
96   -
97   - server.start();
98   - server.join();
99   - }
100   -
101   -
102 12 public static void main(String[] args) throws Exception {
103   -
104   - CommandLineParser parser = new PosixParser();
105   -
106   - Options options = new Options();
107   - options.addOption("w", "web-app-folder", true, "Root folder of web application");
108   - options.addOption("m", "mongo-url", true, "MongoDB URL");
109   - options.addOption("c", "session-collection", true, "Name of MongoDB collection storing session data");
110   - options.addOption("h", "help", false, "Show command usage");
111   -
112   - try {
113   - CommandLine commandLine = parser.parse(options, args, true);
114   -
115   - if (!commandLine.getArgList().isEmpty()) {
116   - throw new ParseException("Unexpected command line arguments.");
117   - }
118   -
119   - if (commandLine.hasOption("help")) {
120   - showHelp(options);
121   - System.exit(0);
122   - }
123   -
124   - JettyMain main = new JettyMain(
125   - commandLine.getOptionValue("web-app-folder", "src/main/webapp"),
126   - commandLine.getOptionValue("mongo-url", firstEnvValue("MONGOHQ_URL", "MONGOLAB_URL")),
127   - commandLine.getOptionValue("session-collection", "sessions"));
128   - main.startServer();
129   -
130   - } catch (ParseException ex) {
131   - System.err.println(ex.getMessage());
132   - showHelp(options);
133   - System.exit(-1);
134   - }
135   -
  13 + com.howardlewisship.tapx.heroku.JettyMain.main(args);
136 14 }
137   -
138   - private static void showHelp(Options options) {
139   - HelpFormatter helpFormatter = new HelpFormatter();
140   - helpFormatter.printHelp(JettyMain.class.getName(), options);
141   - }
142   -
143 15 }

0 comments on commit 4d7f944

Please sign in to comment.
Something went wrong with that request. Please try again.