jQuery in Action, 3rd edition
The moose likes Web Services and the fly likes Web Service Initialization Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Service Initialization Parameters" Watch "Web Service Initialization Parameters" New topic

Web Service Initialization Parameters

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
I have a simple webservice (well the frontend is simple, its guts are a little binary hell) and the service has a configuration file but I cannot find anyway to give the path to that file other than hardcoding it, editing the WSDL file or the web.xml is OK

I'm using a WSDL file, Axis2, Tomcat 6, java 6, Eclipse and I don't know what other detail can serve as information.
Gupta Tarun

Joined: Sep 16, 2010
Posts: 22

1. One option is to package the configuration file and load it from class path as explained here,
http://www.javaworld.com/javaqa/2003-08/01-qa-0808-property.html the only drawback here is that any changes in the configuration file requires re-packaging the application.

2. To avoid that you can have System property which can be specified using -D option, but this becomes an addition installation/deployment step.

If you don't like 1 and 2 then you can still use web.xml init-param and get the handle of the servlet context using following code within your axis2 service -

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
I have found a solution... a dirty solution (as dirty as a pig) but it's good to me

I've developed a servlet with the load-on-startup option set to >0 and that servlet has 2 fields static, the configuration file and its completion status (true it has started)

and then in the webservice...

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Hi Alex,
As a web service is itself a web application, you can use web.xml to provide any initialization parameters (context params). If you don't have any initialization servlets, then you can use ServletContextListener concrete class to retrieve initialization parameters and do whatever you want. Initialization parameter can also be a path to a resource like *.properties and subseqeuntly be loaded.

To answer your question on how to set the path, provide path "/WEB-INF/classes/configuration.properties" either as a hardcoded string within ServletContextListener concrete class or as a context parameter (if you think this is dynamic). Now, you can get real path using

Hope this helps!

(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Konstantin xxx

Joined: Oct 11, 2011
Posts: 1
I agree. Here's the link: http://aspose.com/file-tools
subject: Web Service Initialization Parameters
It's not a secret anymore!