You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Smith, Larry" <xl...@ti.com> on 2002/09/12 23:51:59 UTC

Finding a WEB Service's Directory - Some Results

I've tried the various recommendations (thanks folks).
So far, no luck.

The directory:

	"C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF\classes\esda\"

contains:

	test.txt			<-- a sample text file
	Esda.class			<-- some support utils
	SonarDie.class		<-- the service
	resources\test.txt	<-- a copy of the sample text file

Esda.class and SonarDie.class are members of "package esda"

The pathstring that I'm trying to retrieve (without having to hard code
any container-specific values) is the "home" directory of the service, eg:

	"C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF\classes\esda\"
	
In SonarDie:

	MessageContext mc = MessageContext.getCurrentContext();

this call:

	mc.getProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION);

returns:

	"C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF"

and this call:

	mc.getProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO);

returns:

	"/esda.SonarDie"

The concatenation of these 2 strings does not produce the correct pathname.
Hard-coded container-specific logic would have to be applied.

This block sets 'resURL' to null:

	URL resURL;

	ServletContext sc = ((HttpServlet)
 
mc.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext();

	resURL = sc.getResource("test.txt");

as do ALL of these (set 'resURL' to null):

      resURL = getClass.getClassLoader.getResource("test.txt");
and
      resURL = getClass.getClassLoader.getSystemResource("test.txt");
and
      resURL =
MessageContext.getCurrentContext.getClassLoader.getResource("test.txt");

Thanks & Regards,
Larry

Re: Finding a WEB Service's Directory - Some Results

Posted by doug <um...@yahoo.com>.
Smith, Larry wrote:
> I've tried the various recommendations (thanks folks).
> So far, no luck.
> 
> The directory:
> 
>         "C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF\classes\esda\"
> 
> contains:
> 
>         test.txt                        <-- a sample text file
>         Esda.class                      <-- some support utils
>         SonarDie.class          <-- the service
>         resources\test.txt      <-- a copy of the sample text file
> 
> Esda.class and SonarDie.class are members of "package esda"
> 
> The pathstring that I'm trying to retrieve (without having to hard code
> any container-specific values) is the "home" directory of the service, eg:
> 
>         "C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF\classes\esda\"
>        
> In SonarDie:
> 
>         MessageContext mc = MessageContext.getCurrentContext();
> 
> this call:
> 
>         mc.getProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION);
> 
> returns:
> 
>         "C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF"
> 
> and this call:
> 
>         mc.getProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO);
> 
> returns:
> 
>         "/esda.SonarDie"
> 
> The concatenation of these 2 strings does not produce the correct pathname.
> Hard-coded container-specific logic would have to be applied.
> 
> This block sets 'resURL' to null:
> 
>         URL resURL;
> 
>         ServletContext sc = ((HttpServlet)
>             
> mc.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext();
> 
>         resURL = sc.getResource("test.txt");
> 
> as do ALL of these (set 'resURL' to null):
> 
>       resURL = getClass.getClassLoader.getResource("test.txt");
> and
>       resURL = getClass.getClassLoader.getSystemResource("test.txt");
> and
>       resURL = 
> MessageContext.getCurrentContext.getClassLoader.getResource("test.txt");
> 
> Thanks & Regards,
> Larry
> 

regarding Class.getResource() (or ClassLoader.getResource()) - if you 
don't prefix the resource name with a slash ("/"), getResource will look 
for it in the package subdirectory where the class is defined.  e.g. 
com/mycompany/webservice/text.txt.  if you want it to be found in the 
base of the classpath, use "/test.txt".  this is documented in the API 
docs, but it's easy to overlook.