0

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.

wafwaf
  • 651
  • 12
  • 24

1 Answers1

3

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);

BenMorel
  • 34,448
  • 50
  • 182
  • 322
SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • Thanks. Three things: 1. My web-service isn't a JavaEE project (it's not even written in Java). 2. My client does run in a container-managed-env (I'm using JavaEE -> my code is part of an EAR that runs in an application server). I do use DI (@WebServiceRef), but even so, I still have to first generate the stubs with wsimport. 3. This soapUI plugin seems cool, I'l try it out. – wafwaf Mar 14 '12 at 08:24
  • To answer your questions: 1.That doesn't matter, you got your WSDL to generate your stubs for any client. 2.The WS you want to invoke isn't published in the **same** container (and in Java) so you're not able to inject it via DI. You could also omit the annotation! 3. Yeah, I like it, too. But it seems to be a *bit* buggy. Cheers! – SimonSez Mar 14 '12 at 08:38
  • 1. Yup. 2. But still, I do need the DI, or else how can I instantiate the stub? simply with 'new'? 3. Like almost every Eclipse plugin out there :) – wafwaf Mar 14 '12 at 09:24
  • And what does the JavaEE specs say about that? Is it safe? Isn't it like opening a socket without it being managed by the Application Server? – wafwaf Mar 14 '12 at 18:13
  • I'm not talking about that type of secutiry. I'm talking about safety in terms of managing the server's resources correctly. Oh and I did managed to invoke the WS (both with DI and without). – wafwaf Mar 15 '12 at 08:47
  • Glad to hear, hope I could contribute something to your solution. For me and my setup I couldn't note any *"bad overhead"* so I assume that there is no misbehavior in ressource management, but this could vary depending on your setup. – SimonSez Mar 15 '12 at 09:20