"File not found" when testing web service

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;
 public void setUp() {
   forceService = new SforceService();
 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());

However, the test fails every time with the following exception:

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)

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?

‘file:’ URLs aren’t searched for on the class path. To allow for that, you’d have to register and implement a custom protocol (e.g. see this Stack Overflow thread). As such the problem doesn’t seem to be related to Gradle.

Yep … your right. My brain was not fully on yesterday. I fixed it by initializing the service thusly:

forceService = new SforceService(new ClassPathResource("enterprise.wsdl").getURL());