I have been migrating an application from a websphere server to tomcat. But now I discovered a problem with accessing the wsdl file. The file is in the correct folder but I cant access it within the code even though it works in websphere. What do I need to change after migrating to tomcat?
Java-class:
//
// Generated By:JAX-WS RI IBM 2.1.1 in JDK 6 (JAXB RI IBM JAXB 2.1.3 in JDK 1.6)
//
package iseries.wsbeans.bit05;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
@WebServiceClient(name = "BIT05", targetNamespace = "http://bit05.wsbeans.iseries", wsdlLocation = "WEB-INF/wsdl/BIT05.wsdl")
public class BIT05
extends Service
{
private final static URL BIT05_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("file:./WEB-INF/wsdl/BIT05.wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
BIT05_WSDL_LOCATION = url;
}
public BIT05(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public BIT05() {
super(BIT05_WSDL_LOCATION, new QName("http://bit05.wsbeans.iseries", "BIT05"));
}
Log:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: file:./WEB-INF/wsdl/BIT05.wsdl. It failed with:
Got .\WEB-INF\wsdl\BIT05.wsdl (The system cannot find the path specified) while opening stream from file:./WEB-INF/wsdl/BIT05.wsdl.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
Any ideas?
Thank you
Instead of:
url = new URL("file:./WEB-INF/wsdl/BIT05.wsdl");
Try with:
url = BIT05.class.getClassLoader().getResource("wsdl/BIT05.wsdl");
It's always better to use classloader or ServletContext
if any rather than directly filesystem when the file is in your classpath.