Or just use one ServletContextHandler and setup an Alternate DefaultServlet
to serve static content.
Server server = new Server();
int securePort = 8180;
HttpConfiguration https = new HttpConfiguration();
https.setSecurePort(securePort); // <-- *IMPORTANT*
https.addCustomizer(new SecureRequestCustomizer());
SslContextFactory ssl = new SslContextFactory();
ssl.setKeyStorePath(getKeyStorePath());
ssl.setKeyStoreType("JKS");
ssl.setKeyStorePassword("password");
ssl.setKeyManagerPassword("password");
ServerConnector connector = new ServerConnector(server, new
SslConnectionFactory(ssl, HttpVersion.HTTP_1_1.toString()), new
HttpConnectionFactory(https));
connector.setPort(securePort);
connector.setIdleTimeout(500000);
server.addConnector(connector);
HashSessionManager session_manager = new HashSessionManager();
session_manager.setMaxInactiveInterval(3600);
SessionHandler session_handler = new
SessionHandler(session_manager);
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/"); // <-- *IMPORTANT*
context.setResourceBase("/path/to/main/resource/base"); // <--
*IMPORTANT*
context.setHandler(session_handler);
context.addFilter(new FilterHolder(SessionFilter.class), "/*",
EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
context.addServlet(AppServlet.class, "/Echo");
// Fist, add special pathspec of "/static/" content mapped to the
staticPath
ServletHolder holderStatic = new ServletHolder("static",
DefaultServlet.class);
holderStatic.setInitParameter("resourceBase",System.getProperty("user.dir")
+ File.separator + "static" + File.separator);
holderStatic.setInitParameter("dirAllowed","true");
holderStatic.setInitParameter("pathInfoOnly","true");
context.addServlet(holderStatic,"/static/*");
server.setHandler(context);
try
{
server.start();
server.dump(System.err); // <-- *Provides useful information
for us to help troubleshoot*
server.join();
}
catch (Throwable t)
{
t.printStackTrace(System.err);
}
Or don't use the alternate DefaultServlet and just restructure your static
resource a little bit (directory wise)
Start with a new empty directory, and copy the /static/ folder into it.
Then use this new directory (with just /static/ in it) as your main
resource base with normal DefaultServlet.
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setResourceBase(System.getProperty("main.resource.dir"));
context.setHandler(session_handler);
context.addFilter(new FilterHolder(SessionFilter.class), "/*",
EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
context.addServlet(AppServlet.class, "/Echo");
context.addServlet(DefaultServlet.class, "/");
server.setHandler(context);
This is probably the more sane approach, and you can then also setup some
niceties for your website to help with analytics of your traffic (such as
the various root path analytics company registration files). or use the
root path resources for other web things like the your favicon or website
icon (think chrome and firefox bookmark manager large format icons). could
even use it for the sitemap (boost those google search results!).
Joakim Erdfelt / [email protected]
On Wed, Aug 26, 2015 at 3:35 AM, Lothar Kimmeringer <[email protected]>
wrote:
> Am 25.08.2015 um 17:02 schrieb Bryan Coleman:
> > Any thoughts on the code below and its relation to the HTTP ERROR 404
> > when upgrading to version 9.3.2?
>
> Can you do a System.out.println(server.dump()) after the setup
> of the server? If you see a ServletHandler$Default404Servlet
> in the dump, you might have the same effect I had when I started
> the thread with MID <[email protected]>.
>
> I helped myself with manually removing that servlet from the
> handler (which wasn't fun but does at least work). Maybe Jetty 9.3
> gives you a way to tell the server to not add the 404-servlet
> automatically (which isn't possible with 9.2), so you might
> be able to get around the (really ugly) hack.
>
>
> Cheers, Lothar
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users