I’m trying to test a web service client generated by CXF. The (generated) code looks like:
@WebServiceClient(name = "SforceService",
wsdlLocation = "file:enterprise.wsdl",
targetNamespace = "urn:enterprise.soap.sforce.com")
public class SforceService extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("urn:enterprise.soap.sforce.com", "SforceService");
public final static QName Soap = new QName("urn:enterprise.soap.sforce.com", "Soap");
static {
URL url = null;
try {
url = new URL("file:enterprise.wsdl");
} catch (MalformedURLException e) {
System.err.println("Can not initialize the default wsdl from file:enterprise.wsdl");
// e.printStackTrace();
}
WSDL_LOCATION = url;
}
public SforceService(URL wsdlLocation) {
super(wsdlLocation, SERVICE);
}
public SforceService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public SforceService() {
super(WSDL_LOCATION, SERVICE);
}
/**
*
* @return
*
returns Soap
*/
@WebEndpoint(name = "Soap")
public Soap getSoap() {
return super.getPort(Soap, Soap.class);
}
/**
*
* @param features
*
A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.
Supported features not in the <code>features
parameter will have their default values.
-
@return
returns Soap
*/
@WebEndpoint(name = “Soap”)
public Soap getSoap(WebServiceFeature… features) {
return super.getPort(Soap, Soap.class, features);
}
}
I have a simple test case to connect to the service:
public class SalesforceEnterpriseTest {
private static final String USERNAME = "xxxxxx";
private static final String PASSWORD = "xxxxxx";
private SforceService forceService;
@Before
public void setUp() {
forceService = new SforceService();
}
@Test
public void test() throws InvalidIdFault, LoginFault, UnexpectedErrorFault {
Soap soap = forceService.getSoap();
LoginResult res = soap.login(USERNAME, PASSWORD);
System.out.println("Metadata server URL: " + res.getMetadataServerUrl());
System.out.println("Session id: " + res.getSessionId());
soap.logout();
}
}
However, the test fails every time with the following exception:
[snip]
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'file:enterprise.wsdl'.: java.io.FileNotFoundException: enterprise.wsdl (The system cannot find the file specified)
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:210)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:175)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:82)
... 48 more
Caused by: java.io.FileNotFoundException: enterprise.wsdl (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
[snip]
I’ve put the .wsdl file where Gradle should be able to find it: in the src/main/resources directory and the src/test/resources, but it apparently cannot. Any ideas on how to get this going?