了解JAX-WS中的@Oneway批注

问题描述:

每个javadoc:

指示给定的@WebMethod仅具有输入消息,而没有输出.通常,单向方法在执行实际业务方法之前将控制线程返回到调用应用程序.如果标记为@Oneway的操作具有返回值或Holder参数,或者声明任何已检查的异常,则181处理器应报告错误.

Indicates that the given @WebMethod has only an input message and no output. Typically, a oneway method returns the thread of control to the calling application prior to executing the actual business method. A 181 processor should report an error if an operation marked @Oneway has a return value or Holder parameters, or declares any checked exceptions.

那么我是否可以假设,如果我需要异常处理(选中或未选中),则不建议使用此批注?我没有从业务逻辑中返回任何信息,但是我仍然对了解超时和其他各种特定于调用SOAP方法的错误感兴趣.此注释是否表示我无权访问HTTP返回码或引发异常?

Can I assume then, that if I need exception handling (checked or unchecked) that this annotation is not recommended ? I don't return anything from the business logic, however I still have an interest in being aware of timeouts and other various errors specific to act of calling a SOAP method. Does this annotation mean I don't have access to HTTP return codes or thrown exceptions ?

问题:我最好还是自己单独处理这个线程,以获得真正的异步调用,并删除@Oneway批注?

Question: Am I better off threading this out on my own to get a truly asynchronous call, and removing the @Oneway annotation ?

@Oneway意味着什么都不会转义您的方法,无论是响应还是异常.这有两个原因:

@Oneway means nothing will ever escape your method, neither response nor exception. This is for two reasons:

  • 技术上的异常只是响应的另一种类型(SOAP错误),因此无法从单向方法(无法返回任何内容)返回它

  • technically exception is just another type of response (SOAP fault), thus it cannot be returned from a one-way method (which can't return anything)

通常由Web服务框架异步执行单向方法(我知道表示).该框架会立即返回,因此即使在开始处理单向方法之前,您的客户也可能收到空响应.引发异常时,原来的HTTP连接已久.

often one-way methods are executed asynchronously by the web service framework (I know apache-cxf odes that). The framework returns immediately, so your customer might have received an empty response even before the handling of one-way method even started. When the exception is thrown, the original HTTP connection is long gone.

因此,如果要传播异常或超时,请使用标准的SOAP方法,该方法的响应为空 * ,并且很少明确声明错误.如果要在一段时间后使呼叫超时,则需要单独的线程池并阻止在给定时间段内等待响应.

So if you want to propagate exceptions or timeouts, use standard SOAP method with empty response* and few faults declared explicitly. If you want to timeout your call after some time, you'll need separate thread pool and blocking waiting for response gor a given period of time.

* 请不要将空的SOAP响应(没有内容的XML文档,只有根标签,包裹在SOAP信封中)与空的HTTP响应(什么都没有混淆了)送回).请记住,SOAP不仅限于HTTP.例如,如果您使用JMS或电子邮件传输,则普通双向功能的空响应(或故障)是从服务器发送到客户端的另一条消息.单向方法只是一条最温和的消息,而什么也没发.

* please do not confuse empty SOAP response (an XML document with no content, just root tag, wrapped in a SOAP envelope) with empty HTTP response (nothing was sent back). Remember that SOAP is not limited to HTTP. For example if you use JMS or e-mail transport, empty response (or fault) of ordinary two-way function is yet another message being sent from server to client. one-way method is just one reauest message and nothing sent back.