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 feh <ra...@berbee.com> on 2007/08/14 23:03:32 UTC

access to ServletConfig from service class

I've embedded Axis2 in an existing application running under Tomcat, such
that the AxisServlet is specified in web.xml, and all requests for
/app/services/* are routed to Axis.

Axis then takes care of calling my service methods for a given request. 

Does anybody know how I can get a reference to the ServletContext or
ServletConfig from within a service method?

Thanks!
-- 
View this message in context: http://www.nabble.com/access-to-ServletConfig-from-service-class-tf4269706.html#a12152200
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: access to ServletConfig from service class

Posted by Upul Godage <up...@gmail.com>.
Hi Amila,

I could not find anywhere in the code that sets the property of
MC_HTTP_SERVLET.

But there is this MC_HTTP_SERVLETCONTEXT, which is set in
org.apache.axis2.deployment.WarBasedAxisConfigurator.setConfigContext(ConfigurationContext
configContext)

    public void setConfigContext(ConfigurationContext configContext) {
        super.setConfigContext(configContext);

        // setting ServletContext into configctx
        configContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT,
                                  config.getServletContext());
        // setting ServletContext into configctx
        configContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT,
                                  config.getServletContext());
        Parameter servletConfigParam = new Parameter();
        servletConfigParam.setName(HTTPConstants.HTTP_SERVLETCONFIG);
        servletConfigParam.setValue(config);
        try {
            configContext.getAxisConfiguration
().addParameter(servletConfigParam);
        } catch (AxisFault axisFault) {
            log.error(axisFault.getMessage(), axisFault);
        }
    }

(Though it is set twice there by mistake. May be it was meant for something
else.)

Upul


On 8/17/07, Amila Suriarachchi <am...@gmail.com> wrote:
>
> Are you running on Tomcat?
> To use this attribute you should deploy the Axis2 war distribution.
>
> Amila.
>
> On 8/15/07, feh < ramin@berbee.com> wrote:
> >
> >
> >
> >
> > Raghu Upadhyayula wrote:
> > >
> > > Hi Feh,
> > >
> > >       You can get the ServletContext as follows (In Axis 1.3).  Which
> > > Axis version are you using?
> > >       For Axis 1.3
> > >       MessageContext context = MessageContext.getCurrentContext ();
> > >       HttpServlet servlet =
> > > (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> > >       ServletContext servletContext = servlet.getServletContext();
> > >
> > >       For Axis2 1.2
> > >       MessageContext context =
> > > MessageContext.getCurrentMessageContext();
> > >       HttpServlet servlet =
> > > (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> > >       ServletContext servletContext = servlet.getServletContext();
> > >
> > > Thanks
> > > Raghu
> > >
> > >
> >
> > Thanks Raghu.
> >
> > I'm using Axis2...I gave the code above a try, and while I am able to
> > get
> > the MessageContext, when I try to get the MC_HTTP_SERVLET property, the
> > return value is null.
> >
> > Any guesses as to why?
> >
> > --
> > View this message in context: http://www.nabble.com/access-to-ServletConfig-from-service-class-tf4269706.html#a12163073
> >
> > Sent from the Axis - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> --
> Amila Suriarachchi,
> WSO2 Inc.

Re: access to ServletConfig from service class

Posted by Amila Suriarachchi <am...@gmail.com>.
Are you running on Tomcat?
To use this attribute you should deploy the Axis2 war distribution.

Amila.

On 8/15/07, feh <ra...@berbee.com> wrote:
>
>
>
>
> Raghu Upadhyayula wrote:
> >
> > Hi Feh,
> >
> >       You can get the ServletContext as follows (In Axis 1.3).  Which
> > Axis version are you using?
> >       For Axis 1.3
> >       MessageContext context = MessageContext.getCurrentContext();
> >       HttpServlet servlet =
> > (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> >       ServletContext servletContext = servlet.getServletContext();
> >
> >       For Axis2 1.2
> >       MessageContext context =
> > MessageContext.getCurrentMessageContext();
> >       HttpServlet servlet =
> > (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
> >       ServletContext servletContext = servlet.getServletContext();
> >
> > Thanks
> > Raghu
> >
> >
>
> Thanks Raghu.
>
> I'm using Axis2...I gave the code above a try, and while I am able to get
> the MessageContext, when I try to get the MC_HTTP_SERVLET property, the
> return value is null.
>
> Any guesses as to why?
>
> --
> View this message in context:
> http://www.nabble.com/access-to-ServletConfig-from-service-class-tf4269706.html#a12163073
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Amila Suriarachchi,
WSO2 Inc.

Broken 2.1.1 Build?

Posted by Martin Gainty <mg...@hotmail.com>.
cd $AXIS
ant
Buildfile: build.xml

init:

pre.compile.test:
     [echo] Stax Availability= true
     [echo] Axis2 Availability= true

compile.src:
    [javac] Compiling 863 source files to C:\AXIS\axis2-1.1\build\classes
    [javac] 
C:\AXIS\axis2-1.1\src\modules\adb-codegen\test\org\apache\axis2\sche
ma\testsuite\AbstractTest.java:24: package services.echo.types does not 
exist
    [javac] import services.echo.types.BookInformation;

Anyone know where I can get services.echo.types.BookInformation?

Thanks/
Martin

This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: solution found

Posted by Deepal jayasinghe <de...@gmail.com>.
Have a look at
http://wso2.org/library/480

Thanks
Deepal
> I did some digging, and I was able to get the ServletContext via:
>
>         MessageContext context = MessageContext.getCurrentMessageContext();
>         ServletContext servletContext =
> (ServletContext)context.getProperty("transport.http.servletContext");
>
>
>
> feh wrote:
>   
>>
>> Raghu Upadhyayula wrote:
>>     
>>> Hi Feh,
>>>
>>> 	You can get the ServletContext as follows (In Axis 1.3).  Which
>>> Axis version are you using?
>>> 	For Axis 1.3
>>>       MessageContext context = MessageContext.getCurrentContext(); 
>>>       HttpServlet servlet =
>>> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>>>       ServletContext servletContext = servlet.getServletContext();
>>>
>>> 	For Axis2 1.2
>>>       MessageContext context =
>>> MessageContext.getCurrentMessageContext(); 
>>>       HttpServlet servlet =
>>> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>>>       ServletContext servletContext = servlet.getServletContext();
>>>
>>> Thanks
>>> Raghu
>>>
>>>
>>>       
>> Than


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


solution found

Posted by feh <ra...@berbee.com>.
I did some digging, and I was able to get the ServletContext via:

        MessageContext context = MessageContext.getCurrentMessageContext();
        ServletContext servletContext =
(ServletContext)context.getProperty("transport.http.servletContext");



feh wrote:
> 
> 
> 
> Raghu Upadhyayula wrote:
>> 
>> Hi Feh,
>> 
>> 	You can get the ServletContext as follows (In Axis 1.3).  Which
>> Axis version are you using?
>> 	For Axis 1.3
>>       MessageContext context = MessageContext.getCurrentContext(); 
>>       HttpServlet servlet =
>> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>>       ServletContext servletContext = servlet.getServletContext();
>> 
>> 	For Axis2 1.2
>>       MessageContext context =
>> MessageContext.getCurrentMessageContext(); 
>>       HttpServlet servlet =
>> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>>       ServletContext servletContext = servlet.getServletContext();
>> 
>> Thanks
>> Raghu
>> 
>> 
> 
> Thanks Raghu.
> 
> I'm using Axis2...I gave the code above a try, and while I am able to get
> the MessageContext, when I try to get the MC_HTTP_SERVLET property, the
> return value is null.
> 
> Any guesses as to why?
> 
> 

-- 
View this message in context: http://www.nabble.com/access-to-ServletConfig-from-service-class-tf4269706.html#a12163891
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: access to ServletConfig from service class

Posted by feh <ra...@berbee.com>.


Raghu Upadhyayula wrote:
> 
> Hi Feh,
> 
> 	You can get the ServletContext as follows (In Axis 1.3).  Which
> Axis version are you using?
> 	For Axis 1.3
>       MessageContext context = MessageContext.getCurrentContext(); 
>       HttpServlet servlet =
> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>       ServletContext servletContext = servlet.getServletContext();
> 
> 	For Axis2 1.2
>       MessageContext context =
> MessageContext.getCurrentMessageContext(); 
>       HttpServlet servlet =
> (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>       ServletContext servletContext = servlet.getServletContext();
> 
> Thanks
> Raghu
> 
> 

Thanks Raghu.

I'm using Axis2...I gave the code above a try, and while I am able to get
the MessageContext, when I try to get the MC_HTTP_SERVLET property, the
return value is null.

Any guesses as to why?

-- 
View this message in context: http://www.nabble.com/access-to-ServletConfig-from-service-class-tf4269706.html#a12163073
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: access to ServletConfig from service class

Posted by Raghu Upadhyayula <ru...@responsys.com>.
Hi Feh,

	You can get the ServletContext as follows (In Axis 1.3).  Which
Axis version are you using?
	For Axis 1.3
      MessageContext context = MessageContext.getCurrentContext(); 
      HttpServlet servlet =
(HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
      ServletContext servletContext = servlet.getServletContext();

	For Axis2 1.2
      MessageContext context =
MessageContext.getCurrentMessageContext(); 
      HttpServlet servlet =
(HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
      ServletContext servletContext = servlet.getServletContext();

Thanks
Raghu

-----Original Message-----
From: feh [mailto:ramin@berbee.com] 
Sent: Tuesday, August 14, 2007 2:04 PM
To: axis-user@ws.apache.org
Subject: access to ServletConfig from service class


I've embedded Axis2 in an existing application running under Tomcat,
such
that the AxisServlet is specified in web.xml, and all requests for
/app/services/* are routed to Axis.

Axis then takes care of calling my service methods for a given request. 

Does anybody know how I can get a reference to the ServletContext or
ServletConfig from within a service method?

Thanks!
-- 
View this message in context:
http://www.nabble.com/access-to-ServletConfig-from-service-class-tf42697
06.html#a12152200
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org