Skip to main content

Access ServletContext from JAX-WS web service

8 replies [Last post]
weiresr
Offline
Joined: 2007-09-13
Points: 0

Is there a way to access the ServletContext out of a deployed JAX-WS web service when NOT currently executing a web service request? Injection of the @Resource WebServiceContext works fine, but accessing the ServletContext from there only works in the WebMethods...

I would need to get the context (actually, the directory where my application was deployed) already at initialisation, such as in a @PostConstruct method, e.g. to access configuration files.

Is there any way to do this? I'd appreciate any help :)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cowabunga1984
Offline
Joined: 2009-06-11
Points: 0

Actually I have the same problem. Could you solve it?

markus_franke
Offline
Joined: 2007-10-10
Points: 0

Hi.

Are there any news on this topic? Metro 1.5 seems to support only the mechanism described above.

So how about Metro 2.x?

ramapulavarthi
Offline
Joined: 2004-06-01
Points: 0

Its not supported now. Please file an issue to track this.

markus_franke
Offline
Joined: 2007-10-10
Points: 0
Andreas Loew

Hi Markus, hi Rama, hi all,

Am 29.09.2010 19:37, schrieb metro@javadesktop.org:
> Its not supported now. Please file an issue to track this.

I would tend to look at it differently: As always with programming
issues: "Where there is a will, there is a way." ;-)

Note that I haven't tested the following approach, but I think it should
work:

From plain Java EE, remember that a) you may define custom startup
servlets ( in web.xml) b) the standard Metro web
services servlet is named
com.sun.xml.ws.transport.http.servlet.WSServlet and (AFAIK) not a final
class.

Therefore you can extend this class by your own implementation, and then
use Java EE HTTPServlet standard methods init() and destroy() to
implement whatever functionality you like (but make sure you call
super() first!) and then override Java EE 5 or 6 autogenerated web.xml
with your class name and load-on-startup=1 for your servlet class.

@Rama:
Can you confirm that this is a feasible (and maybe even advisable) way
of implementing this?

HTH & best regards,

Andreas

--
Andreas Loew
Senior Java Architect
Oracle Advanced Customer Services (Germany)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

markus_franke
Offline
Joined: 2007-10-10
Points: 0

Hi Andreas.

I would assume that this is working. But then how to provide this information to the actual business logic of the Web Service? So far as I see the Web Service stuff will be instantiated later on (i.e. after HttpServlet.init()) by the typical JAX-WS magic.

Jitendra Kotamraju

metro@javadesktop.org wrote:
> Is there a way to access the ServletContext out of a deployed JAX-WS web service when NOT currently executing a web service request? Injection of the @Resource WebServiceContext works fine, but accessing the ServletContext from there only works in the WebMethods...
>
> I would need to get the context (actually, the directory where my application was deployed) already at initialisation, such as in a @PostConstruct method, e.g. to access configuration files.
>
> Is there any way to do this? I'd appreciate any help :)
>
There is no standard portable way of doing this. Probably we should
expose a way to do this in metro.

Jitu
> [Message sent by forum member 'weiresr' (weiresr)]
>
> http://forums.java.net/jive/thread.jspa?messageID=254636
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
> For additional commands, e-mail: users-help@metro.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

ernestojpg
Offline
Joined: 2005-10-09
Points: 0

Hi all,

Is there already a way to do this?

The improvement request is still pending.

Thanks in advance.