You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by shantanu chawla <sh...@gmail.com> on 2005/08/17 21:29:50 UTC
How to get hold of current servlet context and session in axis 1.2
my webservice running is axis1.2RC3 needs to access current servlet session
and servletContext. I believe axis is running as a servlet so I can get hold
of the session and servlet context.
I am using this code:
MessageContext messageContext = MessageContext.getCurrentContext();
HttpServlet servlet = (HttpServlet)messageContext.getProperty(
HTTPConstants.MC_HTTP_SERVLET);
ServletContext servletContext = (ServletContext)servlet.getServletContext();
HttpSession session =(HttpSession)messageContext.getProperty(
HTTPConstants.MC_HTTP_SERVLETREQUEST);
I am getting java.lang.ClassCastException on casting to HttpSession. I am
doing the right thing
Thanks
Shantanu Chawla
--
Graduate Student
Department of Computer Science,
San Diego State University
Re: How to get hold of current servlet context and session in axis 1.2
Posted by shantanu chawla <sh...@gmail.com>.
it worked !
Thanks
Shantanu
On 8/17/05, Javier Gonzalez <ja...@gmail.com> wrote:
>
> If I see it right, you are missing a step.
>
> This instruction:
> (HttpSession)messageContext.getProperty(
> HTTPConstants.MC_HTTP_SERVLETREQUEST);
>
> will return a HttpServletRequest object, not a HttpSessionObject.
>
> You need to do:
> HttpSession session =((HttpServletRequest)messageContext.getProperty(
> HTTPConstants.MC_HTTP_SERVLETREQUEST)).getSession();
>
> On 8/17/05, shantanu chawla <sh...@gmail.com> wrote:
> > my webservice running is axis1.2RC3 needs to access current servlet
> session
> > and servletContext. I believe axis is running as a servlet so I can get
> hold
> > of the session and servlet context.
> >
> > I am using this code:
> >
> >
> >
> > MessageContext messageContext =
> > MessageContext.getCurrentContext();
> >
> > HttpServlet servlet =
> > (HttpServlet)messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> > ServletContext servletContext =
> > (ServletContext)servlet.getServletContext();
> >
> > HttpSession session
> > =(HttpSession)messageContext.getProperty(
> > HTTPConstants.MC_HTTP_SERVLETREQUEST);
> >
> > I am getting java.lang.ClassCastException on casting to HttpSession. I
> am
> > doing the right thing
> >
> > Thanks
> >
> > Shantanu Chawla
> >
> >
> > --
> > Graduate Student
> > Department of Computer Science,
> > San Diego State University
>
>
> --
> Javier Gonzalez Nicolini
>
--
Graduate Student
Department of Computer Science,
San Diego State University
Re: How to get hold of current servlet context and session in axis 1.2
Posted by Javier Gonzalez <ja...@gmail.com>.
If I see it right, you are missing a step.
This instruction:
(HttpSession)messageContext.getProperty( HTTPConstants.MC_HTTP_SERVLETREQUEST);
will return a HttpServletRequest object, not a HttpSessionObject.
You need to do:
HttpSession session =((HttpServletRequest)messageContext.getProperty(
HTTPConstants.MC_HTTP_SERVLETREQUEST)).getSession();
On 8/17/05, shantanu chawla <sh...@gmail.com> wrote:
> my webservice running is axis1.2RC3 needs to access current servlet session
> and servletContext. I believe axis is running as a servlet so I can get hold
> of the session and servlet context.
>
> I am using this code:
>
>
>
> MessageContext messageContext =
> MessageContext.getCurrentContext();
>
> HttpServlet servlet =
> (HttpServlet)messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> ServletContext servletContext =
> (ServletContext)servlet.getServletContext();
>
> HttpSession session
> =(HttpSession)messageContext.getProperty(
> HTTPConstants.MC_HTTP_SERVLETREQUEST);
>
> I am getting java.lang.ClassCastException on casting to HttpSession. I am
> doing the right thing
>
> Thanks
>
> Shantanu Chawla
>
>
> --
> Graduate Student
> Department of Computer Science,
> San Diego State University
--
Javier Gonzalez Nicolini