| .. | .. |
|---|
| 12 | 12 | import net.curisit.securis.ioc.RequestsModule;
|
|---|
| 13 | 13 | import net.curisit.securis.ioc.SecurisModule;
|
|---|
| 14 | 14 |
|
|---|
| 15 | +import org.eclipse.jetty.server.Handler;
|
|---|
| 15 | 16 | import org.eclipse.jetty.server.Server;
|
|---|
| 16 | | -import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
|---|
| 17 | +import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|---|
| 18 | +import org.eclipse.jetty.server.handler.ResourceHandler;
|
|---|
| 17 | 19 | import org.eclipse.jetty.servlet.FilterHolder;
|
|---|
| 18 | 20 | import org.eclipse.jetty.servlet.ServletContextHandler;
|
|---|
| 19 | 21 | import org.eclipse.jetty.servlet.ServletHolder;
|
|---|
| 22 | +import org.eclipse.jetty.util.resource.Resource;
|
|---|
| 20 | 23 | import org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener;
|
|---|
| 21 | 24 | import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
|
|---|
| 22 | | -import org.jboss.resteasy.util.HttpResponseCodes;
|
|---|
| 23 | 25 | import org.slf4j.Logger;
|
|---|
| 24 | 26 | import org.slf4j.LoggerFactory;
|
|---|
| 25 | 27 |
|
|---|
| .. | .. |
|---|
| 52 | 54 |
|
|---|
| 53 | 55 | private static void startServer(URI uri) throws Exception {
|
|---|
| 54 | 56 | System.out.println("Starting jetty...");
|
|---|
| 55 | | - // ResourceConfig rc = new PackagesResourceConfig("net.curisit.securis.services", "org.codehaus.jackson.jaxrs");
|
|---|
| 56 | | - // IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(rc, injector);
|
|---|
| 57 | +
|
|---|
| 57 | 58 | server = new Server(9997);
|
|---|
| 58 | 59 | ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
|---|
| 59 | 60 | context.setContextPath("/");
|
|---|
| .. | .. |
|---|
| 64 | 65 | context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 65 | 66 |
|
|---|
| 66 | 67 | ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 67 | | - // context.addServlet(DefaultServlet.class, "/*");
|
|---|
| 68 | | - context.addServlet(sh, "/");
|
|---|
| 69 | | - ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 70 | | - context.setErrorHandler(errorHandler);
|
|---|
| 71 | | - errorHandler.addErrorPage(HttpResponseCodes.SC_FORBIDDEN, "/login");
|
|---|
| 72 | | - errorHandler.addErrorPage(HttpResponseCodes.SC_NOT_FOUND, "/");
|
|---|
| 73 | | - errorHandler.addErrorPage(javax.ws.rs.NotFoundException.class, "/");
|
|---|
| 74 | | - errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
|
|---|
| 75 | | - errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
|
|---|
| 76 | | - errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
|
|---|
| 68 | + sh.setName("resteasy");
|
|---|
| 69 | + context.addServlet(sh, "/*");
|
|---|
| 77 | 70 |
|
|---|
| 71 | + ResourceHandler staticResources = new ResourceHandler();
|
|---|
| 72 | + staticResources.setBaseResource(Resource.newResource(MainApp.class.getResource("/static").toURI()));
|
|---|
| 73 | + staticResources.setWelcomeFiles(new String[]
|
|---|
| 74 | + { "/login.html" });
|
|---|
| 75 | + context.setHandler(staticResources);
|
|---|
| 76 | +
|
|---|
| 77 | + // ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 78 | + // context.setErrorHandler(errorHandler);
|
|---|
| 79 | + // errorHandler.addErrorPage(HttpResponseCodes.SC_FORBIDDEN, "/login");
|
|---|
| 80 | + // errorHandler.addErrorPage(HttpResponseCodes.SC_NOT_FOUND, "/");
|
|---|
| 81 | + // errorHandler.addErrorPage(javax.ws.rs.NotFoundException.class, "/");
|
|---|
| 82 | + // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
|
|---|
| 83 | + // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
|
|---|
| 84 | + // errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
|
|---|
| 85 | + context.setWelcomeFiles(new String[]
|
|---|
| 86 | + { "/index" });
|
|---|
| 78 | 87 | log.info("Error Handlers: " + context.getErrorHandler());
|
|---|
| 79 | | - server.setHandler(context);
|
|---|
| 88 | + ContextHandlerCollection contexts = new ContextHandlerCollection();
|
|---|
| 80 | 89 |
|
|---|
| 90 | + contexts.setHandlers(new Handler[]
|
|---|
| 91 | + { staticResources, context });
|
|---|
| 92 | + // server.setHandler(contexts);
|
|---|
| 93 | +
|
|---|
| 94 | + server.setHandler(context);
|
|---|
| 81 | 95 | server.start();
|
|---|
| 82 | 96 | server.join();
|
|---|
| 83 | | - // rc.packages("net.curisit.securis.services", "org.codehaus.jackson.jaxrs");
|
|---|
| 84 | | -
|
|---|
| 85 | | - // new CLStaticHttpHandler(new URLClassLoader(new URL[] {new URL("file:///home/username/staticfiles.jar")})), "/www")
|
|---|
| 86 | 97 |
|
|---|
| 87 | 98 | }
|
|---|
| 88 | 99 |
|
|---|
| .. | .. |
|---|
| 98 | 109 |
|
|---|
| 99 | 110 | @Override
|
|---|
| 100 | 111 | public Response toResponse(Exception e) {
|
|---|
| 112 | + // log.info("Creating DefaultExceptionHandler ");
|
|---|
| 113 | + e.printStackTrace();
|
|---|
| 101 | 114 | // For simplicity I am preparing error xml by hand.
|
|---|
| 102 | 115 | // Ideally we should create an ErrorResponse class to hold the error info.
|
|---|
| 103 | 116 | StringBuilder response = new StringBuilder("<response>");
|
|---|