JAX-WS and RuntimeException in service implementation

Discussion in 'Java' started by Sebastian Millies, Aug 19, 2010.

  1. Hello,

    I am confused with regard to the treatment of runtime
    exceptions in a webservice call. Can anyone give an explanation
    (or point me to one) that is clearer and more complete than the
    JAX-WS spec itself?

    The scenario:
    Supppose I call a webservice in Java over a JAX-WS 2.1
    compliant SOAP implementation and the service implementation
    throws a java.lang.RuntimeException. What happens on the
    service and the client side?

    What the spec has to say:
    The JAX-WS spec says in section 3.7 :
    java.lang.RuntimeException and java.rmi.RemoteException and their
    subclasses MUST NOT be treated as service specific exceptions and
    MUST NOT be mapped to WSDL.

    Sections 5.1.1.1 and 6.4.1 about protocol specific exceptions seem
    not to apply, because a runtime exception that occurs e. g. because
    of an SQL Error on the server side certainly would not qualify as
    a subclass for the SOAP protocol.

    My questions:
    Thus, on the client side I expect to see nothing in the returned SOAP
    message. I also do not expect a WebServiceException, because these
    occur if there is any error prior to invocation of the operation.
    Am I right?

    Given that a runtime exception may always occur on the server
    (external resource not availabe etc.) am I thus forced to wrap any
    runtime exception in some service exception in my service
    implementation?

    Comment:
    It would be tedious if I were right. Especially if I do not know at
    coding time whether my service will be called using a web service
    or directly in the same JVM (this may vary with the deployment
    configuration, just think of SCA components), I'd be effectively
    barred from using unchecked exceptions.


    -- Sebastian
    Sebastian Millies, Aug 19, 2010
    #1
    1. Advertising

  2. Sebastian Millies

    Daniel Pitts Guest

    On 8/19/2010 12:44 AM, Sebastian Millies wrote:
    > Hello,
    >
    > I am confused with regard to the treatment of runtime
    > exceptions in a webservice call. Can anyone give an explanation
    > (or point me to one) that is clearer and more complete than the
    > JAX-WS spec itself?
    >
    > The scenario:
    > Supppose I call a webservice in Java over a JAX-WS 2.1
    > compliant SOAP implementation and the service implementation
    > throws a java.lang.RuntimeException. What happens on the
    > service and the client side?
    >
    > What the spec has to say:
    > The JAX-WS spec says in section 3.7 :
    > java.lang.RuntimeException and java.rmi.RemoteException and their
    > subclasses MUST NOT be treated as service specific exceptions and
    > MUST NOT be mapped to WSDL.
    >
    > Sections 5.1.1.1 and 6.4.1 about protocol specific exceptions seem
    > not to apply, because a runtime exception that occurs e. g. because
    > of an SQL Error on the server side certainly would not qualify as
    > a subclass for the SOAP protocol.
    >
    > My questions:
    > Thus, on the client side I expect to see nothing in the returned SOAP
    > message. I also do not expect a WebServiceException, because these
    > occur if there is any error prior to invocation of the operation.
    > Am I right?
    >
    > Given that a runtime exception may always occur on the server
    > (external resource not availabe etc.) am I thus forced to wrap any
    > runtime exception in some service exception in my service
    > implementation?

    External resource not available should be a checked exception, not a
    runtime exception.

    >
    > Comment:
    > It would be tedious if I were right. Especially if I do not know at
    > coding time whether my service will be called using a web service
    > or directly in the same JVM (this may vary with the deployment
    > configuration, just think of SCA components), I'd be effectively
    > barred from using unchecked exceptions.

    You're service should throw service specific exceptions. This is good
    design, regardless of whether it is a web-service or not.

    As for the SOAP protocol, I'm not too familiar with it, so I can't
    answer your specific question above.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Aug 19, 2010
    #2
    1. Advertising

  3. Sebastian Millies

    Tom Anderson Guest

    On Thu, 19 Aug 2010, Sebastian Millies wrote:

    > I am confused with regard to the treatment of runtime
    > exceptions in a webservice call. Can anyone give an explanation
    > (or point me to one) that is clearer and more complete than the
    > JAX-WS spec itself?
    >
    > The scenario:
    > Supppose I call a webservice in Java over a JAX-WS 2.1
    > compliant SOAP implementation and the service implementation
    > throws a java.lang.RuntimeException. What happens on the
    > service and the client side?
    >
    > What the spec has to say:
    > The JAX-WS spec says in section 3.7 :
    > java.lang.RuntimeException and java.rmi.RemoteException and their
    > subclasses MUST NOT be treated as service specific exceptions and
    > MUST NOT be mapped to WSDL.
    >
    > Sections 5.1.1.1 and 6.4.1 about protocol specific exceptions seem
    > not to apply, because a runtime exception that occurs e. g. because
    > of an SQL Error on the server side certainly would not qualify as
    > a subclass for the SOAP protocol.
    >
    > My questions:
    > Thus, on the client side I expect to see nothing in the returned SOAP
    > message. I also do not expect a WebServiceException, because these
    > occur if there is any error prior to invocation of the operation.
    > Am I right?
    >
    > Given that a runtime exception may always occur on the server
    > (external resource not availabe etc.) am I thus forced to wrap any
    > runtime exception in some service exception in my service
    > implementation?


    My guess would be that the SOAP implementation will catch a runtime
    exception and return a fault, with a faultcode of Server. Chances are that
    the client SOAP stack will turn this into an exception again - in java, a
    SOAPFaultException.

    I don't have the JAX-WS to hand, so i can't actually cite any evidence for
    this, though.

    tom

    --
    Science runs with us, making us Gods.
    Tom Anderson, Aug 20, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Uppiano

    Migrating JAX-RPC to JAX-WS

    Karl Uppiano, Dec 15, 2006, in forum: Java
    Replies:
    1
    Views:
    530
    Karl Uppiano
    Dec 15, 2006
  2. Karl Uppiano
    Replies:
    3
    Views:
    642
    Karl Uppiano
    Dec 19, 2006
  3. Replies:
    0
    Views:
    721
  4. ankur
    Replies:
    10
    Views:
    538
    Andrew Thompson
    Aug 24, 2008
  5. Sascha Roth
    Replies:
    2
    Views:
    810
    Sascha Roth
    Jul 3, 2009
Loading...

Share This Page