Using wsdl2java to generate stub with PROPER async support

可紊 提交于 2020-01-04 01:51:51

问题


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?


回答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.




回答2:


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>


来源:https://stackoverflow.com/questions/5910660/using-wsdl2java-to-generate-stub-with-proper-async-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!