We help IT Professionals succeed at work.

How do I resolve this error "javax.xml.ws.WebServiceException .... Place the resource correctly in the classpath.?

Hi,

My experience is that I'm a seasoned programmer in other languages, however  in Java I've only done basic batch file processing and have never used it in anger for Web Developing.

I'm developing a Java Desktop App which contains Web Services clients that consumes/interacts with an API provided by www.betfair.com.  I'm following a tutorial that is mentioned on that website, the tutorial links are in the order that I have followed:

1) https://web.archive.org/web/20091226122643/http://forum.bdp.betfair.com/blog.php?b=4 ( Getting started )
2) https://web.archive.org/web/20091226122414/http://forum.bdp.betfair.com/blog.php?b=6 ( Logging into Betfair using NetBeans part A)
3) https://web.archive.org/web/20091226122538/http://forum.bdp.betfair.com/blog.php?b=7 ( Logging into Betfair using NetBeans part B)
4) https://web.archive.org/web/20120319162850/http://forum.bdp.betfair.com:80/blog.php?b=8 ( Logging into Betfair using NetBeans part C)

I downloaded the latest NetBeans 6.8 ( The full and complete NetBeans package) and followed the instructions provided in the tutorals:

1) to create the Web Service clients using the WDSL urls

When creating the Web clients as part of the Getting Started tutorial, I got an error in the automated generation part, which required me to use the "xendorsed="true" to get that part to compile. As far as I know, this part is okay, but maybe related to the error which is tthe basis for me writing this question.

and 2)create a basic Login GUI.

When I try to run the basic GUI login screen I've created using the tutorials, I get the following error message:

javax.xml.ws.WebServiceException: Cannot find 'https://api.betfair.com/global/v3/BFGlobalService.wsdl' wsdl. Place the resource correctly in the classpath.
at com.betfair.publicapi.v3.bfglobalservice.BFGlobalS ervice_Service.<clinit>(BFGlobalService_Service.ja va:32)
at me.wsop.betfair.exchange.bfLogin.doLogin(bfLogin.j ava:35)
at me.wsop.betfair.exchange.bfLogin.<init>(bfLogin.ja va:24)
at betfair.BetfairView.btnLoginActionPerformed(Betfai rView.java:272)

Open in new window



and the automated Java code that provides this error is:

/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2-hudson-752-
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "BFGlobalService", targetNamespace = "http://www.betfair.com/publicapi/v3/BFGlobalService/", wsdlLocation = "https://api.betfair.com/global/v3/BFGlobalService.wsdl")
public class BFGlobalService_Service
extends Service
{

private final static URL BFGLOBALSERVICE_WSDL_LOCATION;
private final static WebServiceException BFGLOBALSERVICE_EXCEPTION;
private final static QName BFGLOBALSERVICE_QNAME = new QName("http://www.betfair.com/publicapi/v3/BFGlobalService/", "BFGlobalService");

static {
BFGLOBALSERVICE_WSDL_LOCATION = com.betfair.publicapi.v3.bfglobalservice.BFGlobalS ervice_Service.class.getResource("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
WebServiceException e = null;
if (BFGLOBALSERVICE_WSDL_LOCATION == null) {
e = new WebServiceException("Cannot find 'https://api.betfair.com/global/v3/BFGlobalService.wsdl' wsdl. Place the resource correctly in the classpath.");
}
BFGLOBALSERVICE_EXCEPTION = e;
}

Open in new window


I've read other forums for an answer for my situation and now I'm confused as to what the actual solution is, whether I need to amend Java code, roll back to an early version of Jar files, add Environmental Variables to the OS system paths or whether to install missing Jar files in certain locations.

It seems to be a common problem, but I'm at a loss on how to resolve it.  So I'm in your capable hands for the solution to my problem.

So for those who reply, let me know what extra information you may require and I'll provide it the best I can.

Thank you in advance.
Comment
Watch Question

Siva Prasanna KumarPrincipal Solutions Architect
Top Expert 2006

Commented:
Here is what is wrong according to me

BFGLOBALSERVICE_WSDL_LOCATION = com.betfair.publicapi.v3.bfglobalservice.BFGlobalS ervice_Service.class.getResource("https://api.betfair.com/global/v3/BFGlobalService.wsdl");

Class.getResource is meant to local resources with URL's not an WSDL file from URL.

general usage URL myurl = this.getClass().getResource("/myimage.gif");

So two possible solutions

1) download the WSDL file name it some "api.wsdl" and make it available in class path and change the code to

BFGLOBALSERVICE_WSDL_LOCATION = com.betfair.publicapi.v3.bfglobalservice.BFGlobalS ervice_Service.class.getResource("api.wsdl");

2) you really don't need this as you have already provided the wsdlLocation top and what exactly are u doing next in the code you snippet is very partial for me to analyze.



Author

Commented:
Thank you for your response, shivaspk.

Like you I believe that I shouldn't have alter the code as you've suggested in solution one, as this code is generated automatically by NetBean during the Web Service client creation process, from a given wsdl URL.

For the preferred solution 2, you wanted to analyze the code further, so I'm going to provide 2 files:

bfLogin.java class file, line 35, make this call "com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service service = new com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service();"

The above line of code requires, the BFGlobalService_Service.java class file (Java class generated by NetBeans during Web Service class phase).  It is in this file that I provided a small code snippet originally, where the occurs at line 32:

e = new WebServiceException("Cannot find 'https://api.betfair.com/global/v3/BFGlobalService.wsdl' wsdl. Place the resource correctly in the classpath.");

 

BFGlobalService-Service.java

Author

Commented:
Hmmmmm, I didn't realise you could only attach 1 file, so here is the second file bfLogin.java I mentioned in my first reply.
bfLogin.java
Principal Solutions Architect
Top Expert 2006
Commented:
I am still not sure why u have this static block

    static {
        BFGLOBALSERVICE_WSDL_LOCATION = com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service.class.getResource("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
        WebServiceException e = null;
        if (BFGLOBALSERVICE_WSDL_LOCATION == null) {
            e = new WebServiceException("Cannot find 'https://api.betfair.com/global/v3/BFGlobalService.wsdl' wsdl. Place the resource correctly in the classpath.");
        }
        BFGLOBALSERVICE_EXCEPTION = e;
    }

The simplest thinking I can suggest you is to remove this static block in BFGlobalService-Service.java

and try if it still doesn't work! then do this below change in bfLogin.java

change this code from

com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service service = new com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service();

to the code below
com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service service = new com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service("https://api.betfair.com/global/v3/BFGlobalService.wsdl");

Open in new window

Author

Commented:
shivaspk,

I finally got this working, it didn't require any direct manual source changes at all.  I'm happy to give you get the points for your help.

The solution was due partly to the idea you gave as solution one, but no manual code change from me.

I didn't realise that when creating a Web Service client it save's a copy of the wsdl file to the local filesystem.  I found mine here:

C:\Documents and Settings\robin\My Documents\NetBeansProjects\Betfair\src\META-INF\wsdl\

I recreated the Web Service clients by pointing to the local copy,and let NetBeans to compile/parse/generate the needed source code.  After that I rebuilt the project, to ensure all references were relinked.

So the new BFGlobalService_Service.java source code looks like this:


package com.betfair.publicapi.v3.bfglobalservice;

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.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2-hudson-752-
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "BFGlobalService", targetNamespace = "http://www.betfair.com/publicapi/v3/BFGlobalService/", wsdlLocation = "file:/C:/Documents%20and%20Settings/robin/My%20Documents/NetBeansProjects/Betfair/src/META-INF/wsdl/api.betfair.com/global/v3/BFGlobalService.wsdl")
public class BFGlobalService_Service
    extends Service
{

    private final static URL BFGLOBALSERVICE_WSDL_LOCATION;
    private final static WebServiceException BFGLOBALSERVICE_EXCEPTION;
    private final static QName BFGLOBALSERVICE_QNAME = new QName("http://www.betfair.com/publicapi/v3/BFGlobalService/", "BFGlobalService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/C:/Documents%20and%20Settings/robin/My%20Documents/NetBeansProjects/Betfair/src/META-INF/wsdl/api.betfair.com/global/v3/BFGlobalService.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        BFGLOBALSERVICE_WSDL_LOCATION = url;
        BFGLOBALSERVICE_EXCEPTION = e;
    }

    public BFGlobalService_Service() {
        super(__getWsdlLocation(), BFGLOBALSERVICE_QNAME);
    }

    public BFGlobalService_Service(WebServiceFeature... features) {
        super(__getWsdlLocation(), BFGLOBALSERVICE_QNAME, features);
    }

    public BFGlobalService_Service(URL wsdlLocation) {
        super(wsdlLocation, BFGLOBALSERVICE_QNAME);
    }

    public BFGlobalService_Service(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, BFGLOBALSERVICE_QNAME, features);
    }

    public BFGlobalService_Service(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public BFGlobalService_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns BFGlobalService
     */
    @WebEndpoint(name = "BFGlobalService")
    public BFGlobalService getBFGlobalService() {
        return super.getPort(new QName("http://www.betfair.com/publicapi/v3/BFGlobalService/", "BFGlobalService"), BFGlobalService.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns BFGlobalService
     */
    @WebEndpoint(name = "BFGlobalService")
    public BFGlobalService getBFGlobalService(WebServiceFeature... features) {
        return super.getPort(new QName("http://www.betfair.com/publicapi/v3/BFGlobalService/", "BFGlobalService"), BFGlobalService.class, features);
    }

    private static URL __getWsdlLocation() {
        if (BFGLOBALSERVICE_EXCEPTION!= null) {
            throw BFGLOBALSERVICE_EXCEPTION;
        }
        return BFGLOBALSERVICE_WSDL_LOCATION;
    }

}

Open in new window

Siva Prasanna KumarPrincipal Solutions Architect
Top Expert 2006

Commented:
smilerude, in order to assign me the point you need to select one of my suggestions as answer with appropriate grade unlike deleting the question it self :)

Author

Commented:
The solutions provided were clear to understand where I needed to make them and pointed me in the direction of the complete solution.