I've looked in the FAQ, the Wiki, and through the mailing list and unless I've missed 
something 
obvious there doesn't appear to be a generally accepted way to do this.

My code can run as a stand-alone client or a SOAP service or an Axis service. I load a 
class 
name when it starts to determine which of those it should run as.

I'm currently using System.getProperty(). That works if I provide the class name on 
the 
command line to start the client or on Tomcat's command line.

What I'm going to more toward is trying to use System.getProperty() and if that 
doesn't work 
try to read a properties file, something like:
new Properties( getClass().getResourceAsStream( "myfile" ) ) I haven't tried that yet, 
but I'd 
imagine it would work and be fairly non-Axis-specific.

I've included below snippets I took from past email messages. Search for these to put 
them in 
context:


----------------------
 org.apache.axis.MessageContext axisContext = 
org.apache.axis.MessageContext.getCurrentContext();
                javax.servlet.ServletContext sc = 
((javax.servlet.http.HttpServlet)axisContext.getProperty
(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLET)).getServletContex
t();

                String path = sc.getRealPath("/WEB-INF/service.properties");
                // now get the properties for the server and EJB location 
information
                java.util.Properties props = new java.util.Properties();
                
                try {
                        props.load(new java.io.FileInputStream(path));
                }
                catch(java.io.FileNotFoundException fnfe) {
                        sc.log("service.properties file not found. Will use 
defaults." + fnfe.getMessage());
                        System.out.println("service.properties file not found. 
Will use defaults");
                }

                catch(java.io.IOException ioe) {
                        sc.log("service.properties file not loaded. Will use 
defaults." + ioe.getMessage());
                        System.out.println("service.properties file not loaded. 
Will use defaults");
                }

                String server = props.getProperty("EJBServer", "127.0.0.1");
                String port= props.getProperty("EJBServerPort", "7001");
                String ejb= props.getProperty("EJBJNDIName", "SoapBean");


----------------------

// Get path to WEB-INF
org.apache.axis.MessageContext msgContext =
org.apache.axis.MessageContext.getCurrentContext();
String strWebInf =
msgContext.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_
SERVLETLOCATION).toString();

// Use path to WEB-INF to read text file into properties
Properties propsConfig = new Properties();
propsConfig.load(new BufferedInputStream(new FileInputStream(new
File(strWebInf + "/Config.txt"))));

// Use path to WEB-INF to read text file into string
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new
File(strWebInf + "/Stuff.txt")));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int nData = bis.read();
while (nData != -1)
{
    baos.write(nData);
    nData = bis.read();
}
bis.close();
baos.flush();
baos.close();
String strStuff = baos.toString();


----------------------

HttpServlet srv = (HttpServlet) 
MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLET);

To get properties from the web.xml file.  But, I cannot find anywhere that 
speficies what the XML for a property should look like in the web.xml 
file, or where that xml should go in web.xml.  I have tried guessing, and 
I haven't guessed it correct yet.  Can someone provide an example of what 
the web.xml needs to look like to contain a property I can retrieve using 
the MessageContext.getCurrentContext().getProperty() method?

Also, I would prefer storing the properties in the server-config.wsdd in 
the service section for my web service.

----------------------

org.apache.axis.MessageContext msgContext =
    org.apache.axis.MessageContext.getCurrentContext();
String paramValue = (String)
   msgContext.getProperty("Name");
System.err.println("paramValue="+paramValue);

Method #2
org.apache.axis.handlers.soap.SOAPService service =
  msgContext.getService();
paramValue = (String) service.getOption("Name");
System.err.println("paramValue="+paramValue);


On 11 Jun 2004 at 10:06, Guha, Suteertha [IE] wrote:
> 
> Hello again, I am sure this is possible. And should be simple enough. Can someone 
> please help me 
> out once you get a few spare cycles?
> 
> Thanks!!!
> 
> 
>     -----Original Message-----
>     From: Guha, Suteertha [IE] [mailto:[EMAIL PROTECTED] 
>     Sent: Thursday, June 10, 2004 3:15 PM
>     To: '[EMAIL PROTECTED]'
>     Subject: How to read config values from soap service deployed as WAR?
>     
>     Hi!
>     
>     I need to know how one reads configuration values ( like env-entry in deployment 
>     descriptors) from the Impl classes of a webservice deployed as a WAR file using 
> AXIS 
>     providers?
>     
>     Thank you,
>     Guha
> 


Reply via email to