3

Lets say I have a service with ONLY one method: int generateRandomNumbers().

Is is possible to use wsdl2java to generate a stub with proper async support?

For example, the generated class should has the following methods/messages:

int generateRandomNumbers()
int generateRandomNumbers_Async(callback)

I know how to use wsdl2java to generate stubs with the async messages. However, this only works if the service understands the async messages.

What I mean by proper async support is that

  • generateRandomNumbers_Async is not a new message, since the service only understands generateRandomNumbers, not generateRandomNumbers_Async
  • generateRandomNumbers_Async = invokes generateRandomNumbers in a different thread, and invokes the callback when generateRandomNumbers is finished behind the scenes.

Any idea?

How about other web service frameworks?

skaffman
  • 398,947
  • 96
  • 818
  • 769
David
  • 185
  • 4
  • 13

2 Answers2

1

When using CXF, it should work exactly like your "second" bullet, kind of. The "generateRandomNumbers" message is sent on the calling thread so if there is an IO error or similar that would be thrown back immediately. (per jaxws spec) A background thread would then handle the response and call the callback.

When generating the code with wsdl2java, you would need to create a jaxws binding file that contains something like:

<bindings
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  wsdlLocation="hello_world_async.wsdl"
  xmlns="http://java.sun.com/xml/ns/jaxws">
  <bindings node="wsdl:definitions">
    <enableAsyncMapping>true</enableAsyncMapping>
  </bindings>
</bindings>

and pass that with the -B flag. That will generate a bunch of new methods on the interface for the async versions. You should just need to use those.

Daniel Kulp
  • 14,447
  • 4
  • 45
  • 37
  • What options should I use for this? It might be that I weren't using the right options. I have tried. It doesn't work. The async operations were using the async messages which the services could not understand. – David May 06 '11 at 16:46
  • I had tried this, it doesn't work. According to the server log, "generateRandomNumbers_Async" is sent, rather than "generateRandomNumbers". – David May 10 '11 at 09:34
  • I think, there is a need for generating just one method: `Future generateRandomNumbers()` (or maybe `void generateRandomNumbers(callback)`). That is what I would expect from async service. – mirelon Feb 02 '15 at 14:48
  • Or in other words: this service is not usable for standard soap clients like SOAPUI. The documentation you are referring to is showing how to create asynchronous client by calling port.greetMeSometimeAsync() method. But when sending a SOAP request, it returns a fault with message `Message part greetMeSometimeAsync was not recognized. (Does it exist in service WSDL?)` – mirelon Feb 02 '15 at 15:07
  • (I assumed this documentation: http://cxf.apache.org/docs/developing-a-consumer.html) – mirelon Feb 02 '15 at 15:24
0

Just an information to configure your server. The Annotation @UseAsyncMethod will trigger the async method instead the synchronous one. Be sure to use Servlet 3.0 and more. Configure your servlet using true in your web.xml :

<servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <!-- Enable asynchronous requests -->
        <async-supported>true</async-supported>
</servlet>