| .. | .. |
|---|
| 32 | 32 |
|
|---|
| 33 | 33 | public class MainApp {
|
|---|
| 34 | 34 |
|
|---|
| 35 | | - private static final Logger LOG = LogManager.getLogger(MainApp.class);
|
|---|
| 35 | + private static final Logger LOG = LogManager.getLogger(MainApp.class);
|
|---|
| 36 | 36 |
|
|---|
| 37 | | - private static Server server;
|
|---|
| 38 | | - private static Injector injector = null;
|
|---|
| 37 | + private static Server server;
|
|---|
| 38 | + private static Injector injector = null;
|
|---|
| 39 | 39 |
|
|---|
| 40 | | - @Inject
|
|---|
| 41 | | - @Named("base-uri")
|
|---|
| 42 | | - private URI uri;
|
|---|
| 40 | + @Inject
|
|---|
| 41 | + @Named("base-uri")
|
|---|
| 42 | + private URI uri;
|
|---|
| 43 | 43 |
|
|---|
| 44 | | - public static void main(String[] args) throws Exception {
|
|---|
| 45 | | - LOG.info("SeCuris init...");
|
|---|
| 44 | + public static void main(String[] args) throws Exception {
|
|---|
| 45 | + LOG.info("SeCuris init...");
|
|---|
| 46 | 46 |
|
|---|
| 47 | | - SecurisModule securisModule = new SecurisModule();
|
|---|
| 48 | | - JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
|
|---|
| 49 | | - Properties props = new Properties();
|
|---|
| 50 | | - props.put("javax.persistence.jdbc.password", securisModule.getPassword());
|
|---|
| 51 | | - props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
|
|---|
| 52 | | - LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
|
|---|
| 53 | | - jpaPersistModule.properties(props);
|
|---|
| 47 | + SecurisModule securisModule = new SecurisModule();
|
|---|
| 48 | + JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
|
|---|
| 49 | + Properties props = new Properties();
|
|---|
| 50 | + props.put("javax.persistence.jdbc.password", securisModule.getPassword());
|
|---|
| 51 | + props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
|
|---|
| 52 | + LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
|
|---|
| 53 | + jpaPersistModule.properties(props);
|
|---|
| 54 | 54 |
|
|---|
| 55 | | - injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
|
|---|
| 56 | | - // injector.getInstance(JpaInitializer.class);
|
|---|
| 55 | + injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
|
|---|
| 57 | 56 |
|
|---|
| 58 | | - startServer(injector.getInstance(Key.get(URI.class, Names.named("base-uri"))));
|
|---|
| 59 | | - while (true) {
|
|---|
| 60 | | - Thread.currentThread().sleep(100);
|
|---|
| 61 | | - }
|
|---|
| 62 | | - }
|
|---|
| 57 | + startServer(injector.getInstance(Key.get(URI.class, Names.named("base-uri"))));
|
|---|
| 58 | + while (true) {
|
|---|
| 59 | + Thread.currentThread().sleep(100);
|
|---|
| 60 | + }
|
|---|
| 61 | + }
|
|---|
| 63 | 62 |
|
|---|
| 64 | | - private static void startServer(URI uri) throws Exception {
|
|---|
| 65 | | - System.out.println("Starting jetty...");
|
|---|
| 63 | + private static void startServer(URI uri) throws Exception {
|
|---|
| 64 | + System.out.println("Starting jetty...");
|
|---|
| 66 | 65 |
|
|---|
| 67 | | - server = new Server(9997);
|
|---|
| 68 | | - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
|---|
| 69 | | - context.setContextPath("/");
|
|---|
| 70 | | - context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
|
|---|
| 66 | + server = new Server(9997);
|
|---|
| 67 | + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
|---|
| 68 | + context.setContextPath("/");
|
|---|
| 69 | + context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
|
|---|
| 71 | 70 |
|
|---|
| 72 | | - context.setInitParameter("resteasy.role.based.security", "true");
|
|---|
| 73 | | - context.setInitParameter("resteasy.providers", DefaultExceptionHandler.class.getName());
|
|---|
| 74 | | - // context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 75 | | - context.addFilter(new FilterHolder(injector.getInstance(PersistFilter.class)), "/*", null);
|
|---|
| 76 | | - ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 77 | | - sh.setName("resteasy");
|
|---|
| 78 | | - context.addServlet(sh, "/*");
|
|---|
| 71 | + context.setInitParameter("resteasy.role.based.security", "true");
|
|---|
| 72 | + context.setInitParameter("resteasy.providers", DefaultExceptionHandler.class.getName());
|
|---|
| 73 | + context.addFilter(new FilterHolder(injector.getInstance(PersistFilter.class)), "/*", null);
|
|---|
| 74 | + ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 75 | + sh.setName("resteasy");
|
|---|
| 76 | + context.addServlet(sh, "/*");
|
|---|
| 79 | 77 |
|
|---|
| 80 | | - ResourceHandler staticResources = new ResourceHandler();
|
|---|
| 81 | | - staticResources.setBaseResource(Resource.newResource(MainApp.class.getResource("/static").toURI()));
|
|---|
| 82 | | - staticResources.setWelcomeFiles(new String[]
|
|---|
| 83 | | - { "/main.html" });
|
|---|
| 84 | | - context.setHandler(staticResources);
|
|---|
| 78 | + ResourceHandler staticResources = new ResourceHandler();
|
|---|
| 79 | + staticResources.setBaseResource(Resource.newResource(MainApp.class.getResource("/static").toURI()));
|
|---|
| 80 | + staticResources.setWelcomeFiles(new String[] { "/main.html" });
|
|---|
| 81 | + context.setHandler(staticResources);
|
|---|
| 85 | 82 |
|
|---|
| 86 | | - ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 87 | | - context.setErrorHandler(errorHandler);
|
|---|
| 88 | | - // errorHandler.addErrorPage(HttpResponseCodes.SC_FORBIDDEN, "/login");
|
|---|
| 89 | | - // errorHandler.addErrorPage(HttpResponseCodes.SC_NOT_FOUND, "/");
|
|---|
| 90 | | - // errorHandler.addErrorPage(javax.ws.rs.NotFoundException.class, "/");
|
|---|
| 91 | | - // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
|
|---|
| 92 | | - // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
|
|---|
| 93 | | - // errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
|
|---|
| 94 | | - LOG.info("Error Handlers: " + context.getErrorHandler());
|
|---|
| 95 | | - ContextHandlerCollection contexts = new ContextHandlerCollection();
|
|---|
| 83 | + ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 84 | + context.setErrorHandler(errorHandler);
|
|---|
| 85 | + LOG.info("Error Handlers: " + context.getErrorHandler());
|
|---|
| 86 | + ContextHandlerCollection contexts = new ContextHandlerCollection();
|
|---|
| 96 | 87 |
|
|---|
| 97 | | - contexts.setHandlers(new Handler[]
|
|---|
| 98 | | - { staticResources, context });
|
|---|
| 99 | | - // server.setHandler(contexts);
|
|---|
| 88 | + contexts.setHandlers(new Handler[] { staticResources, context });
|
|---|
| 100 | 89 |
|
|---|
| 101 | | - server.setHandler(context);
|
|---|
| 102 | | - server.start();
|
|---|
| 103 | | - server.join();
|
|---|
| 104 | | - LOG.info("Started server in: http://127.0.0.1:9997/");
|
|---|
| 105 | | - }
|
|---|
| 90 | + server.setHandler(context);
|
|---|
| 91 | + server.start();
|
|---|
| 92 | + server.join();
|
|---|
| 93 | + LOG.info("Started server in: http://127.0.0.1:9997/");
|
|---|
| 94 | + }
|
|---|
| 106 | 95 |
|
|---|
| 107 | 96 | }
|
|---|