Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jetty-users Digest, Vol 100, Issue 9

Hi Jan,

Thanks for taking time to looking into this issue.  My Initial post did not address the problem correctly.  After further investigation I have found out the exact issue but the solution still eludes me.   Hope you will be able to help me with that.

The reason I was receiving null servletContext was because I was sharing a single SessionHandler object among many WebAppContexts.  

 In < Jetty 9.4  I used to share a HashSessionManager object between WebAppContexts  as a way of sharing session objects among them so that users don't have to re-authenticate.   The strategy seemed to work fine without any issues.  

In Jetty 9.4 due to changes to Session Management, I am not able to implement similar strategy.  SessionCache are specific to contexts and I am not able to share sessions between contexts.  Is there a way to implement global sessions  (server level rather than context level) in Jetty 9.4  ?


Thanks & Regards,
Aravind.


-----Original Message-----
From: jetty-users-bounces@xxxxxxxxxxx [mailto:jetty-users-bounces@xxxxxxxxxxx] On Behalf Of jetty-users-request@xxxxxxxxxxx
Sent: Friday, September 08, 2017 1:08 PM
To: jetty-users@xxxxxxxxxxx
Subject: jetty-users Digest, Vol 100, Issue 9

Send jetty-users mailing list submissions to
	jetty-users@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
	https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_listinfo_jetty-2Dusers&d=DwICAg&c=3v6EBbtpnn9A7jIZYjOw6KN7Pe17WoimzcinOq2Xztg&r=YbS3Xf40CmAQ12d73dX0bv-TPzDJnSuxn9AFms1fOWg&m=3EtJu1ppbjOzJ_v-OwhfrxLvSX0DZks9P4rZrXYXMgE&s=RvIeN8HbsO4LJBVcUHpSc5W1dLA4pLTzZV6ZsOpK35o&e=
or, via email, send a message with subject or body 'help' to
	jetty-users-request@xxxxxxxxxxx

You can reach the person managing the list at
	jetty-users-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific than "Re: Contents of jetty-users digest..."


Today's Topics:

   1. jetty 9.4.6 - getting null servletcontext in servlets
      (Raghavan, Aravind)
   2. Re: jetty 9.4.6 - getting null servletcontext in	servlets
      (Jan Bartel)


----------------------------------------------------------------------

Message: 1
Date: Fri, 8 Sep 2017 03:05:10 +0000
From: "Raghavan, Aravind" <Aravind.Raghavan@xxxxxxxxxx>
To: "'jetty-users@xxxxxxxxxxx'" <jetty-users@xxxxxxxxxxx>
Subject: [jetty-users] jetty 9.4.6 - getting null servletcontext in
	servlets
Message-ID:
	<507B873CF700714381A8EBAC9E77085499E76585@xxxxxxxxxxxxxxx.local>
Content-Type: text/plain; charset="us-ascii"

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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_private_jetty-2Dusers_attachments_20170908_dc9bb395_attachment.html&d=DwICAg&c=3v6EBbtpnn9A7jIZYjOw6KN7Pe17WoimzcinOq2Xztg&r=YbS3Xf40CmAQ12d73dX0bv-TPzDJnSuxn9AFms1fOWg&m=3EtJu1ppbjOzJ_v-OwhfrxLvSX0DZks9P4rZrXYXMgE&s=uXSeFQ--5DZ_eEs5QQQ2vRjxbnpdypym5CKG62YtgHM&e= >

------------------------------

Message: 2
Date: Fri, 8 Sep 2017 15:08:20 +1000
From: Jan Bartel <janb@xxxxxxxxxxx>
To: JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Subject: Re: [jetty-users] jetty 9.4.6 - getting null servletcontext
	in	servlets
Message-ID:
	<CAEHc-316ZN2MCtR2mQ0jv=RwOhOFkL85dmL51p7KKpmUr2g5ww@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset="utf-8"

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://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_m
> ailman_listinfo_jetty-2Dusers&d=DwICAg&c=3v6EBbtpnn9A7jIZYjOw6KN7Pe17W
> oimzcinOq2Xztg&r=YbS3Xf40CmAQ12d73dX0bv-TPzDJnSuxn9AFms1fOWg&m=3EtJu1p
> pbjOzJ_v-OwhfrxLvSX0DZks9P4rZrXYXMgE&s=RvIeN8HbsO4LJBVcUHpSc5W1dLA4pLT
> zZV6ZsOpK35o&e=
>



--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
*Expert assistance from the creators of Jetty and CometD*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_private_jetty-2Dusers_attachments_20170908_85398a13_attachment.html&d=DwICAg&c=3v6EBbtpnn9A7jIZYjOw6KN7Pe17WoimzcinOq2Xztg&r=YbS3Xf40CmAQ12d73dX0bv-TPzDJnSuxn9AFms1fOWg&m=3EtJu1ppbjOzJ_v-OwhfrxLvSX0DZks9P4rZrXYXMgE&s=itXXamuZkZTco7DCOqWPAcHLxz54wS64UirsH4ZcZJ0&e= >

------------------------------

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_listinfo_jetty-2Dusers&d=DwICAg&c=3v6EBbtpnn9A7jIZYjOw6KN7Pe17WoimzcinOq2Xztg&r=YbS3Xf40CmAQ12d73dX0bv-TPzDJnSuxn9AFms1fOWg&m=3EtJu1ppbjOzJ_v-OwhfrxLvSX0DZks9P4rZrXYXMgE&s=RvIeN8HbsO4LJBVcUHpSc5W1dLA4pLTzZV6ZsOpK35o&e= 

End of jetty-users Digest, Vol 100, Issue 9
*******************************************


Back to the top