| .. | .. |
|---|
| 5 | 5 |
|
|---|
| 6 | 6 | import javax.inject.Inject;
|
|---|
| 7 | 7 | import javax.inject.Named;
|
|---|
| 8 | | -import javax.ws.rs.core.MediaType;
|
|---|
| 9 | | -import javax.ws.rs.core.Response;
|
|---|
| 10 | | -import javax.ws.rs.ext.ExceptionMapper;
|
|---|
| 11 | | -import javax.ws.rs.ext.Provider;
|
|---|
| 12 | 8 |
|
|---|
| 13 | 9 | import net.curisit.securis.ioc.RequestsModule;
|
|---|
| 14 | 10 | import net.curisit.securis.ioc.SecurisModule;
|
|---|
| .. | .. |
|---|
| 17 | 13 | import org.eclipse.jetty.server.Server;
|
|---|
| 18 | 14 | import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|---|
| 19 | 15 | import org.eclipse.jetty.server.handler.ResourceHandler;
|
|---|
| 16 | +import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
|---|
| 20 | 17 | import org.eclipse.jetty.servlet.FilterHolder;
|
|---|
| 21 | 18 | import org.eclipse.jetty.servlet.ServletContextHandler;
|
|---|
| 22 | 19 | import org.eclipse.jetty.servlet.ServletHolder;
|
|---|
| .. | .. |
|---|
| 35 | 32 |
|
|---|
| 36 | 33 | public class MainApp {
|
|---|
| 37 | 34 |
|
|---|
| 38 | | - private static final Logger log = LoggerFactory.getLogger(MainApp.class);
|
|---|
| 35 | + static final Logger log = LoggerFactory.getLogger(MainApp.class);
|
|---|
| 39 | 36 |
|
|---|
| 40 | 37 | private static Server server;
|
|---|
| 41 | 38 | private static Injector injector = null;
|
|---|
| .. | .. |
|---|
| 74 | 71 |
|
|---|
| 75 | 72 | context.setInitParameter("resteasy.role.based.security", "true");
|
|---|
| 76 | 73 | context.setInitParameter("resteasy.providers", DefaultExceptionHandler.class.getName());
|
|---|
| 77 | | - context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 74 | + // context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 78 | 75 | context.addFilter(new FilterHolder(injector.getInstance(PersistFilter.class)), "/*", null);
|
|---|
| 79 | 76 | ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 80 | 77 | sh.setName("resteasy");
|
|---|
| .. | .. |
|---|
| 86 | 83 | { "/main.html" });
|
|---|
| 87 | 84 | context.setHandler(staticResources);
|
|---|
| 88 | 85 |
|
|---|
| 89 | | - // ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 90 | | - // context.setErrorHandler(errorHandler);
|
|---|
| 86 | + ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
|---|
| 87 | + context.setErrorHandler(errorHandler);
|
|---|
| 91 | 88 | // errorHandler.addErrorPage(HttpResponseCodes.SC_FORBIDDEN, "/login");
|
|---|
| 92 | 89 | // errorHandler.addErrorPage(HttpResponseCodes.SC_NOT_FOUND, "/");
|
|---|
| 93 | 90 | // errorHandler.addErrorPage(javax.ws.rs.NotFoundException.class, "/");
|
|---|
| 94 | 91 | // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class, "/");
|
|---|
| 95 | 92 | // errorHandler.addErrorPage(javax.ws.rs.ForbiddenException.class.getCanonicalName(), "/");
|
|---|
| 96 | 93 | // errorHandler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/");
|
|---|
| 97 | | - context.setWelcomeFiles(new String[]
|
|---|
| 98 | | - { "/index" });
|
|---|
| 99 | 94 | log.info("Error Handlers: " + context.getErrorHandler());
|
|---|
| 100 | 95 | ContextHandlerCollection contexts = new ContextHandlerCollection();
|
|---|
| 101 | 96 |
|
|---|
| .. | .. |
|---|
| 107 | 102 | server.start();
|
|---|
| 108 | 103 | server.join();
|
|---|
| 109 | 104 | log.info("Started server in: http://127.0.0.1:9997/");
|
|---|
| 110 | | - }
|
|---|
| 111 | | -
|
|---|
| 112 | | - @Provider
|
|---|
| 113 | | - public static class DefaultExceptionHandler implements ExceptionMapper<Exception> {
|
|---|
| 114 | | -
|
|---|
| 115 | | - public DefaultExceptionHandler() {
|
|---|
| 116 | | - log.info("Creating DefaultExceptionHandler ");
|
|---|
| 117 | | - }
|
|---|
| 118 | | -
|
|---|
| 119 | | - @Override
|
|---|
| 120 | | - public Response toResponse(Exception e) {
|
|---|
| 121 | | - // log.info("Creating DefaultExceptionHandler ");
|
|---|
| 122 | | - e.printStackTrace();
|
|---|
| 123 | | - // For simplicity I am preparing error xml by hand.
|
|---|
| 124 | | - // Ideally we should create an ErrorResponse class to hold the error info.
|
|---|
| 125 | | - StringBuilder response = new StringBuilder("<response>");
|
|---|
| 126 | | - response.append("<status>ERROR</status>");
|
|---|
| 127 | | - response.append("<message>" + e.getMessage() + "</message>");
|
|---|
| 128 | | - response.append("</response>");
|
|---|
| 129 | | - return Response.serverError().entity(response.toString()).type(MediaType.APPLICATION_XML).build();
|
|---|
| 130 | | - }
|
|---|
| 131 | 105 | }
|
|---|
| 132 | 106 |
|
|---|
| 133 | 107 | }
|
|---|