ProxyServlet stop working after migration from jetty 8 to jetty 9

女生的网名这么多〃 提交于 2019-12-07 21:11:04

问题


I have an eclipse plugin which uses jetty server with ProxyServlet. Basically, the implementation is the following:

    ServletHolder proxyServletHolder = new ServletHolder(new SubClassOfProxyServlet()); 
    proxyServletHolder.setAsyncSupported(true);
    ServletHandler proxyServletHandler = new ServletHandler();
    proxyServletHandler.addServletWithMapping(proxyServletHolder, "/mapping/url");

After that I add proxy handler to the handler list and set this list to the server:

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {
            . // Other Handlers
            .
            proxyServletHandler,
            .
            .
            .
            new DefaultHandler()
        });
    server.setHandler(handlers);

Everything worked like a charm against jetty 8 but after migration to jetty 9 I get the following error:

Caused by: java.lang.IllegalStateException: No server executor for proxy at org.eclipse.jetty.proxy.ProxyServlet.createHttpClient(ProxyServlet.java:279) at org.eclipse.jetty.proxy.ProxyServlet.init(ProxyServlet.java:123) ... 24 more

Has the mechanism of working with ProxyServer changed? Am I missing something?


回答1:


You need to update your SubClassOfProxyServlet class to include the various configurations that are now being passed from the Server to the Proxy which are then in turn used by the internal HttpClient

The particular error means you are not passing along the Executor properly.

You have 2 choices for the Executor specific piece (there might be more things for you to configure after this is addressed)

  1. Set the init-parameter maxThreads to a valid integer value.
  2. or Create an Executor, and set it in the servlet context attributes at ServletContext.setAttribute("org.eclipse.jetty.server.Executor", myExecutor) on application deployment / startup. - You could probably do this as well in your SubClassOfProxyServlet.init(ServletConfig config) method.



回答2:


I was able to get it working via the maxThreads method mentioned above, setting it on creation. Applying this to the original example would result in this:

ServletHolder proxyServletHolder = new ServletHolder(new SubClassOfProxyServlet()); 
proxyServletHolder.setAsyncSupported(true);
proxyServletHolder.setInitParameter("maxThreads", "2");
ServletHandler proxyServletHandler = new ServletHandler();
proxyServletHandler.addServletWithMapping(proxyServletHolder, "/mapping/url");



回答3:


Here is an example of how you can add a servlet to a list of handlers:

    private void addWebApp(String contextPath, String resourceBase, Server server) {

        WebAppContext webAppContext = new WebAppContext();
        // webAppContext.setDescriptor(webapp + "/WEB-INF/web.xml");
        webAppContext.setResourceBase(resourceBase);
        webAppContext.setContextPath(contextPath);
        webAppContext.setParentLoaderPriority(true);
        webAppContext.setWelcomeFiles(new String[] {"index.html"});
        webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");

        final ServletHolder servletHolder =new ServletHolder();
        servletHolder.setAsyncSupported(ContentBasedProxyServlet.class);
        servletHolder.setAsyncSupported(true);

        webAppContext.addServlet(servletHolder, "/*");

        HandlerList handlers = (HandlerList) server.getHandler();
        handlers.addHandler(webAppContext);
}



回答4:


In addition you can put maxThreads to web.xml as well:

<servlet>
    <servlet-name>proxy</servlet-name>
    <servlet-class>example.MyProxyServlet</servlet-class>
    <init-param>
        <param-name>maxThreads</param-name>
        <param-value>5</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>


来源:https://stackoverflow.com/questions/27624873/proxyservlet-stop-working-after-migration-from-jetty-8-to-jetty-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!