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 John McCosker <J....@andronics.com> on 2005/01/19 19:04:52 UTC

trying to access ServletContext within axis webservice

Hi,

I am trying to access <init-param> values from within my axis webservice
like so .. 

...

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

import org.apache.axis.transport.http.HTTPConstants;
import org.apache.axis.MessageContext;

...

public class MyWebService(){

...

	HttpServlet srv =
(HttpServlet)MessageContext.getCurrentContext().getProperty(HTTPConstants.MC
_HTTP_SERVLET);
	ServletContext context = srv.getServletContext();
	File moveFile = new File(fileLocation);
	File destination = new
File(context.getInitParameter("TREND_JDBC_FAULT"));
	boolean fileMoved = moveFile.renameTo(new
File(destination,moveFile.getName()));

...

}

however I am catching and logging the error as this does not seem to work
for me,

java.lang.NullPointerException
	at java.io.File.<init>(File.java:180)
	at
com.leocate.spreadSheets.ExcelPublishingService.createSpreadSheet(ExcelPubli
shingService.java:49)

I put my <init-param> in axis/web-inf/web.xml

<servlet>
		<servlet-name>AxisServlet</servlet-name>
		<display-name>Apache-Axis Servlet</display-name>
		<servlet-class>
		   org.apache.axis.transport.http.AxisServlet
		</servlet-class>
		<init-param>
			<param-name>TREND_JDBC_FAULT</param-name>
			<param-value>\System_Path\</param-value>
		</init-param>
	</servlet>

I am just wondering if I am doing everything correctly,
I am using apache tomcat 4.01, axis beta 1,

I had a look on how to do this on the apache site and this is the Axis
specific approach to getting the
ServletContext,

any advice would be appreciated,

thanks jp.