0

I finally got video playback to work in chrome with seek feature using the headers Content-Range etc and status 206 returned. It worked well for smaller videos but fails with large videos. Just to note, I am not sending the actual byte ranges explicitly but deliver the entire stream to the webserver. I get the following errors:

org.eclipse.jetty.io.EofException,

this occurs in the backend dataserver that serves the entire inputstream to a servlet and jetty is the server being used. I am not sure how this process actually plays back and corrected the seek feature I needed but now the video fails after playing for a while. The following error also occurs in the browser debugger:

ERR_CONTENT_LENGTH_MISMATCH

I have an audio stream being requested at the same time and playedback as well since I do not know how to mix the two streams.

Any ideas or advice appreciated.

EDIT:

Thanks to the advice to change resourcehandler to defaultservlet; not sure where to do this so found the instances of where this is in the code:

   private void addHttpContexts(ConfigNode cnode) throws Exception {

      try {
        // get all the http context nodes
        ConfigNode[] httpContextNodes = cnode.getChildNode("HttpContextList").getChildNodes();

        for (int s = 0; s < httpContextNodes.length; s++) {
            String urlPath = httpContextNodes[s].getChildNode("ContextPath").getStringValueEx();
            String resourceBase = httpContextNodes[s].getChildNode("ResourceBase").getStringValueEx();

            ArrayList<String> welcomeFileList = new ArrayList<String>();
            if (httpContextNodes[s].hasChildNode("WelcomeFile")) {
                String welcomeFile = httpContextNodes[s].getChildNode("WelcomeFile").getStringValueEx();
                welcomeFileList.add(welcomeFile);
            }

            ContextHandler context = new ContextHandler(contexts, urlPath);
            ResourceHandler resourceHandler = new ResourceHandler();
            resourceHandler.setResourceBase(resourceBase);
            resourceHandler.setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));

            context.setHandler(resourceHandler);


    } catch (Exception ex) {
        trace.warning("Configuration of http contexts failed", ex);

        throw ex;
    }
}

What is the appropriate methods for setResourceBase(resourceBase) and setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));

This is the other place in the the same class I found DefaultSErvlet

ServletHolder holderDefault = new ServletHolder("default",DefaultServlet.class);
                holderDefault.setInitParameter("dirAllowed","false");

and also already defined in web.xml

 <servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
    <param-name>dirAllowed</param-name>
    <param-value>false</param-value>
</init-param>
</servlet>
vbNewbie
  • 3,291
  • 15
  • 71
  • 155
  • On Jetty, use `DefaultServlet`, not `ResourceHandler` to serve static content with support for ranges. – Joakim Erdfelt Feb 20 '18 at 13:47
  • Thanks @JoakimErdfelt; I added the edits where I found reference to this so not sure where to make a change if needed – vbNewbie Feb 21 '18 at 05:47
  • See https://stackoverflow.com/questions/20207477/serving-static-files-from-alternate-path-in-embedded-jetty/20223103#20223103 – Joakim Erdfelt Feb 21 '18 at 12:06
  • Thanks for the link to the post. When doing range requests, I assume that once you have a file / stream handled on the dataserver end, it needs to actually send the response in byte ranges and jetty does not handle the partial range requests itself using the headers you specify? Content-Range etc, Basically I am asking whether the stream has to actually return byte ranges to the webserver that returns it to the webclient. – vbNewbie Feb 23 '18 at 14:00

1 Answers1

1

By default, Jetty's DefaultServlet will handle range requests properly for static content served by Jetty itself.

No other component in Jetty handles range requests on its own.

If you have custom code, your own Servlets, your own Jetty Handlers, a REST endpoint, specialized Filters, spring-mvc setup, etc... then you have to handle the range request yourself.

This is because its very impractical for the webserver to support this for custom code. (It would have to request the entire content from the custom code, and then only send the specific byte range to the requesting client).

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136