2
votes

I'm embedding Jetty 9 in my java application like this:

    Server server = new Server(8080);
    ResourceHandler handler = new ResourceHandler();

    handler.setDirectoriesListed(false);
    handler.setWelcomeFiles(new String[]{"index.html"});
    handler.setResourceBase(System.getProperty("user.home"));

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);

    server.setHandler(handlers);
    server.start();

This works fine except when serving .ogg audio files to webkit based browsers line Epiphany or SWT WebView. Those browsers require response code 206 (partial) rather than 200 (ok) and some header values like Content-Length, Accept-Ranges, Content-Range etc. Is there any handler doing so?

1

1 Answers

3
votes

I'm encountering the same issue. I've used this HttpServlet: https://code.google.com/p/uranged/source/browse/trunk/src/main/java/com/vg/http/MicroRangeServlet.java?r=2

I've added the handling in this way, so that it will be used only for the \media\ url:

ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/media");
    org.eclipse.jetty.servlet.ServletHolder holderHome = new org.eclipse.jetty.servlet.ServletHolder(new MicroRangeServlet(config, path+"/media"));               
    contextHandler.addServlet(holderHome,"/*");

In my code i've also added the path for media files in the constructor because they are not in the public folder.

Let me know if you find a more elegant solution.