Search code examples
pythoneclipseweb-servicesjakarta-eewsdl

How to call a web-service using JavaEE?


I've been using rpclib to auto-generate a WSDL and implement it in Python.

Then I wanted to call a web-service* that has this WSDL using JavaEE, so I simply used the Web Service from WSDL option in the creation wizard in Eclipse (Indigo 3.7.1 with OEPE), but then the Ant build failed with the exception (in short):

weblogic.wsee.tools.WsBuildException Error running JAX-WS wsdlc
Caused by java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()

What should I do? How can I call the web-service using JavaEE?

* The web service is configured with: Apache HTTP Server 2.2.2 + mod_wsgi 3.3 + Python 2.6.5 + rpclib 2.6.1.


Solution

  • Ok, stumbled upon your post the second time, so I'll elaborate my comment given before :).

    First I recapitulate your set-up:

    • You have a working webservice and an URL pointing to the corresponding WSDL
    • You'll try to invoke the WS methods from a different Java EE project on a different machine

    General options for invoking a WS:

    1. Use Dependency Injection to inject the WS reference
    2. Create your own WS stubs

    The first option won't work in your set-up because DI will only work in an container-managed-environment (see my comment). That means that the WS class and the executing class have to be in the same container (e.g. the same server).

    So what is left is to generate your WS stubs manually. Therefore you can use the wsimport tool mentioned in your own answer. There are several different ways to use this tool. Lets have a look in the CLI use:

    1. navigate in your projekt folder of the WS client used by your IDE : %IDE_WORKSPACE%/your project/src
    2. crate a new folder, e.g. stub
    3. open a command window in this directory
    4. execute the follwing command : wsimport -keep <http://yourwsdl?wsdl>
    5. After a refresh you should see several created files

    Back in your IDE:

    Now you're able to use your generated stub-files to connect to the WS by getting a port from the generated service-file

    public class WsClient {
    
      public static void main(String[] args) {
        //Create Service
        'GeneratedFile'Service service = new 'GeneratedFile'Service();
    
        //create proxy
        'GeneratedFile' proxy = service.get'GeneratedFile'Port();
    
        //invoke
        System.out.println(proxy.yourMethod(yourParam));
      }
    }
    

    Last hints:

    • For portabilty purpose check the generated files. In their annotations sometimes the WSDL file is linked to a local copy. Just change this back to your WSDL-URL.
      AFAIK there is an option in the wsimport tool to set this directly in the import routine.
    • There is a plugin for Eclipse called soapUI which allows you to use the wsimport tool in a GUI out of Eclipse. Once set up it should accelerate your work.
    • I've also found a quick start guide in developing WS clients with eclipse.

    Hope this helped, have Fun!

    EDIT: Just to clarify:

    needed files after wsimport generation

    After you used the wsimport tool you should have a directory containing files like shown in the image. To make this example clear you'll need to get a Service from the RequestFileService (this is my WS operation) like RequestFileService service = new RequestFileService(); and after this you'll need a Port on this service like RequestFile proxy = service.getRequestFilePort();.
    After this you can invoke your method calls by using the port proxy.yourMethod(yourParam);