Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding @Oneway annotation in JAX-WS

Tags:

java

jax-ws

Per the javadoc:

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.

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 ?

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

like image 681
JHarnach Avatar asked Oct 24 '12 21:10

JHarnach


1 Answers

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

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

  • 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.

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.

* 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.

like image 191
Tomasz Nurkiewicz Avatar answered Nov 10 '22 09:11

Tomasz Nurkiewicz