After a little more research I think I know where my thinking is wrong.

When my service is finished I think I have to make a war file to distribute
it and there I can put the files where I think is right, like classes of 
course in "WEB-INF/classes/myservice" text files, XML files etc in 
servlet/myservice etc. In other words I get to decide on the file structure 
so it is not necessarily bad programming style to use explicate path names 
based on that file structure relative to the SOAP root directory, like 
"servlet/myservice/settings.ini".

Thanks
Con 

-----Original Message-----
From: Ruane, Conleth 
Sent: 17 June 2003 11:44
To: '[EMAIL PROTECTED]'
Subject: RE: Accessing text files in SOAP service folder


Thanks again Scott. 
I just use getServletPath() to establish the 
"current directory" when the service is running.
The problem is that the "current directory" is not the directory 
containing the service classes nor is it a directory 
soap/servlet/myservice, so that the call

        servlet.getServletContext().getRealPath("myservice.ini")

returns

        C:\PROGRA~1\APACHE~1\TOMCAT~1.1\bin\..\webapps\soap\myservice.ini
instead of what I'd like
        <tomcat>\webapps\soap\WEB-INF\classes\myservice\myservice\myservice.ini
or
        <tomcat>\webapps\soap\servlet\myservice\myservice.ini

I think what I'll probably do is either look in a few places for the properties 
file like 
        getRealPath("WEB-INF/classes/myservice/myservice.ini")
        getRealPath("servlet/myservice/myservice.ini")
        getRealPath("myservice.ini")
        ...
until I find a file, or I'll use an environment variable like 'MYSERVICE_HOME'.

I'm probably just not 'thinking' SOAP services yet. This is my first web service.

Thanks.

Regards 
Con



-----Original Message-----
From: Scott Nichol [mailto:[EMAIL PROTECTED]
Sent: 16 June 2003 19:25
To: [EMAIL PROTECTED]
Subject: RE: Accessing text files in SOAP service folder


You do not want to use getServletPath().  As you have seen, it gives 
you a virtual path, not a physical filesystem path.

Use getRealPath() alone.  If you really want to be slick, use 
ServletContext#getResource or ServletContext#getResourceAsStream to 
read the configuration as a "resource" within the webapp.

On 16 Jun 2003 at 15:15, Ruane, Conleth wrote:

> Thanks Scott.
> That helped a lot. I've modified my service so that I can access
> the SOAPContext object.
> I still can't do quite exactly what I want however and I'm wondering 
> if it's just because I'm trying to do the wrong thing.
> 
> A call to
> 
>         request.getServletPath();
> 
> returns something like /servlet/rpcrouter
> 
> and getRealPath() turns this into the equivalent of 
> 'C:\Program Files\Apache Group\Tomcat 4.1\webapps\soap\servlet\rpcrouter'
> 
> but my classes are in
> 'C:\Program Files\Apache Group\Tomcat 4.1\webapps\soap\WEB-INF'
> 
> and actually there is no folder 'servlet' in 
> 'C:\Program Files\Apache Group\Tomcat 4.1\webapps\soap\'.
> 
> What I was trying to do is have a collection of classes implementing 
> my service and a properties file for various settings in the same 
> directory. Is there anything 'wrong' with this approach or should
> I have a folder like 'mySoapService' under '...webapps\soap\servlet\rpcrouter'
> to hold stuff like settings files. This is what the return value of 
> 'request.getServletPath()' would imply. Classes go under 
> 'webapps\soap\WEB-INF\mySoapService' any other stuff under 
> 'webapps\soap\servlet\rpcrouter\mySoapService'.
> 
> Another approach I've considered is to get the path for the properties
> file from an environment variable.
> 
> Is there a right way to access property files from SOAP services?
> None of the SOAP samples do this and I couldn't find anything on
> the web. (I'm still looking though).
> 
> Any input is appreciated.
> 
> Thanks
> Con
> 
> 
>         String tmpDir = request.getServletPath();
> 
> 
> 
> -----Original Message-----
> From: Scott Nichol [mailto:[EMAIL PROTECTED]
> Sent: 13 June 2003 19:11
> To: [EMAIL PROTECTED]
> Subject: Re: Accessing text files in SOAP service folder
> 
> 
> Doing a getRealPath is fine, but you have to code your services 
> specially to get the servlet context.  Specifically, you must add a 
> parameter to the method(s) of type SOAPContext.  Apache SOAP will 
> then pass the current request context, from which you can get the 
> HttpRequest, etc.
> 
> As long as you have the SOAPContext, you might want to consider 
> having your parameters in either the web.xml for the Apache SOAP 
> webapp, or the deployment descriptor for the service.  These are 
> fairly standard places for initialization information.
> 
> If you are using a nightly build of Apache SOAP, you can also have 
> your service implement the ConfigurableService interface.  This has a 
> method that is called immediately after instantiation of the service. 
> The method receives the webapp and deployment descriptor values as 
> parameters.
> 
> On 13 Jun 2003 at 16:41, Ruane, Conleth wrote:
> 
> > Hi All.
> > 
> > I'm writing my first SOAP service using Apache SOAP.
> > I've run into a problem I can't find a solution for after a lot of searching.
> > 
> > I want my service to pull some settings from a text file which is in the same 
> > folder as the service classes but if I use just the file name I get a 
> > fileNotFoundException.
> > I've established that the file is being looked for in the tomcat bin folder 
> > instead of the
> > folder where the classes are. I want to avoid using a hardcoded absolute path.
> > 
> > A similar problem in my jsp pages I solved using
> >              workingDir =  
> > pageContext.getServletContext().getRealPath(request.getServletPath());
> > 
> > Can I do something similar in a soap service class or is there any good way to do 
> > what I want.
> > 
> > Thanks
> > 
> > Con
> > 
> > 
> 
> 
> Scott Nichol
> 
> Do not reply directly to this e-mail address,
> as it is filtered to only receive e-mail from
> specific mailing lists.
> 
> 
> 


Scott Nichol

Do not reply directly to this e-mail address,
as it is filtered to only receive e-mail from
specific mailing lists.


Reply via email to