Skip to main content

ServletContext during initialization in jax-ws

4 replies [Last post]
Joined: 2007-03-17

I am writing a web service using jax-ws and am having problems with initialization. My web service relies on a few auxillary files that I store under WEB-INF/. One of these files is a properties file that I would like to load before any messages are received. Unfortunately, the only way I know to load this file is to use the ServletContext to get the real path for the file before loading. There are some other files that it would be nice to handle in a similar manner before the handling messages.

For a normal servlet, the context is passed into the init method, but from within my web service, I seem to only be able to access a ServletContext from a MessageContext and therefore have to initialize on the first call. I currently have to set a flag that is checked on each call, to see if I have initialized.

What would be perfect would be the a @PostConstruct method that took an argument of a servlet context.

Is there a better way to deal with this today, or something coming in the future?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-10-09

Improvement request:

Joined: 2007-08-10

Ideally, we should be able to access init-params from ServletContext itself. ServletConfig should not be required. But I noticed that the ServletContext obtained from MessageContext does not contain any of the init-params configured in web.xml. Perhaps this is a bug?

Joined: 2003-06-14

I think your request is reasonable. From the spec's point of view, that's the only way. I believe you could use spring to inject ServletContext. Other option is that RI could provide a way to give ServletContext. You could file RFEs on RI and the spec.

Joined: 2003-06-09

Yep. Spring support would do this quite nicely.