-----Original Message-----
From: John McCosker [mailto:[EMAIL PROTECTED]
Sent: 19 January 2005 18:05
To: '[EMAIL PROTECTED]'
Subject: trying to access ServletContext within axis webserviceHi,
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(ExcelPublishingService.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.
Title: trying to access ServletContext within axis webservice
>> File destination =
new File(context.getInitParameter("TREND_JDBC_FAULT"));
If you
are getting parameters from the ServletContext, they need to be defined as
<context-param>s in web.xml, which precede any <servlet>
elements.
To get
a servlet's <init-param> you would need a reference to the Servlet object
itself.
Hope
this helps
Keith
- trying to access ServletContext within axis webservice John McCosker