This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes File Not found Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "File Not found Exception" Watch "File Not found Exception" New topic
Author

File Not found Exception

B pandoo
Ranch Hand

Joined: Nov 14, 2006
Posts: 37
Hi,
I am new to Webservice concepts.I had a client and server side application.There is a property file in Serverside.I am trying to read the data from property file using the following code
Properties props = new Properties();
try {
props.load(new FileInputStream("StatementType.properties"));
statementType = props.getProperty("statementdefintionName");
}
catch(IOException e){e.printStackTrace();}
I have placed the property file under WebContent folder.

While making a call from Client side and invoke the webservice,it is throwing a FileNotfound exception as it is unable to locate the file.Please let me know why during a webservice call,it is unable to locate a file in server side.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5


That code depends on the "current" directory - something you have no control over in typical servers. You will need to find a way to get the absolute path to the properties file. What server are you using?

Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
These might help you out.
javax.servlet.ServletContext.getRealPath
javax.servlet.ServletContext.getResource
javax.servlet.ServletContext.getResourceAsStream

You can get the ServletContext from
javax.xml.rpc.server.ServletEndpointContext.getServletContext
if the web service is a JAX-RPC servlet.

You obtain the ServletEndpointContext in an JAX-RPC servlet by implementing the
javax.xml.rpc.server.ServiceLifecycle - the ServletEndpointContext is passed through the init method.

So basically you have to find a way of obtaining the your ServletContext.
B pandoo
Ranch Hand

Joined: Nov 14, 2006
Posts: 37
Hi,
I am using Tomcat Server.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by B pandoo:
Hi,
I am using Tomcat Server.


With what SOAP stack? Axis 1.x, Axis 2, JWSDP 1.x ....
B pandoo
Ranch Hand

Joined: Nov 14, 2006
Posts: 37
Hi,
i am using Axis1.x.Is there any possibility that the property file can be read without getting the ServletContext.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Not found Exception