Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jetty 9.4.6 - getting null servletcontext in servlets

Aravind,

There's not enough info in your post to pinpoint the problem. I've whipped up a small example based on your code, and it runs with no problems:

        Server server = new Server(8080);
        HandlerCollection handlers_ = new HandlerCollection(true);
        ContextHandlerCollection chc_ = new ContextHandlerCollection();
        String path = "/blah";

        WebAppContext context =
                new WebAppContext(chc_, "/path/to/distro/demo-base/webapps/test.war", path);

        //needed for the test webapp
        HashLoginService loginService = new HashLoginService();
        loginService.setName( "Test Realm" );
        loginService.setConfig( "/path/to/distro/demo-base/etc/realm.properties" );
        server.addBean( loginService );
        chc_.addHandler(context);
        context.setContextPath(path);


        String servletPath = "/blah/*";
        Servlet servlet = new HelloServlet("blah-hello");
        ServletHolder servletHolder = new ServletHolder(servlet);
        context.addServlet(servletHolder, servletPath);

        handlers_.setHandlers(new Handler[] { chc_, new DefaultHandler()});
        server.setHandler(handlers_);
        server.start();
        server.join();


Perhaps you have old jetty-9.3 jars on the classpath?

In the absence of more info, I can only suggest that you turn on full debug to give a clue. Maybe also try a  server.setDumpAfterStart(true) as well to see more.

Jan

On 8 September 2017 at 13:05, Raghavan, Aravind <Aravind.Raghavan@xxxxxxxxxx> wrote:

Hi All,

 

I recently upgraded from jetty 9.3.11 to 9.4.6 .  And after upgrade  none of my servlets are able to get servlet context.  getServletContext() always returns null.  Can you please help me figure out what I am doing wrong? 

 

Relevant section of code:

 

handlers_ = new HandlerCollection(true);

chc_ = new ContextHandlerCollection();

for(WebAppConfig wap: webAppConfigs)   //webappconfig a POJO from where I am getting webapp configs

{

  String path = wap.getPath();

  String warFile = wap.getWarFile();

  WebAppContext context =

    new WebAppContext(chc_, warFile, path);

  chc_.addHandler(context);

  context.setContextPath(path);

  for (ServletConfig servletConfig: wap.getServletConfigs())  //ServletConfig is another POJO to get servlet configs

  {

    String servletName = servletConfig.getName();

    String servletPath = servletConfig.getPath();

    Servlet servlet = servletConfig.getServlet();  

    ServletHolder servletHolder = new ServletHolder(servlet);

    context.addServlet(servletHolder, servletPath);

  }

}

handlers_.setHandlers(new Handler[] { chc_, new DefaultHandler()});

server_.setHandler(handlers_);

 

 

Note the same code worked fined with 9.3.11.  Getting null context only after upgrading to 9.4.6.  I am not sure what has changed in 9.4.x to cause this issue.  I can’t find any changes (other than Session Management) in documentation.

 

 

Thanks,

Aravind.

 

 


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


Back to the top