Results 1 to 5 of 5

Thread: Exception handling

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Location
    Germany, Karlsruhe
    Posts
    157

    Question Exception handling

    Hi,

    i want to talk about exception handling.
    I'm using a SoapFaultMappingExceptionResolver with this configuration
    Code:
    <property name="defaultFault">
      <value>RECEIVER,Server error</value>
    </property>
    <property name="exceptionMappings">
      <props>
        <prop key="org.springframework.oxm.UnmarshallingException">SENDER,Invalid request</prop>
        <prop key="org.springframework.oxm.ValidationFailureException">SENDER,Invalid request</prop>
      </props>
    </property>
    Ok, that's fine. But please think about this.

    I have this web service: XYZObject getXYZObject(id)

    If an object with a given id doesn't exist, what should i do?
    Should i create something like a SOAPFault object in my Endpoint code and return it in the invokeInternal method?

    Or should my endpoint code throw an XYZObjectNotFoundException and use the SoapFaultMappingExceptionResolver to return this exception to the client?

    What's the better way?
    Are there other ways?

    It would be also nice to map SOAPFault codes of my XYZObjectNotFoundException to message constants defined in my XSD.
    How can i do this?
    I know i can define an xml schema enumeration for my error message constants, but how can i link an XYZObjectNotFoundException to a schema enumeration?

    Cheers,

    Ingo

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    Quote Originally Posted by res1st
    i want to talk about exception handling.
    I'm using a SoapFaultMappingExceptionResolver with this configuration
    Code:
    <property name="defaultFault">
      <value>RECEIVER,Server error</value>
    </property>
    <property name="exceptionMappings">
      <props>
        <prop key="org.springframework.oxm.UnmarshallingException">SENDER,Invalid request</prop>
        <prop key="org.springframework.oxm.ValidationFailureException">SENDER,Invalid request</prop>
      </props>
    </property>
    Ok, that's fine. But please think about this.

    I have this web service: XYZObject getXYZObject(id)

    If an object with a given id doesn't exist, what should i do?
    Should i create something like a SOAPFault object in my Endpoint code and return it in the invokeInternal method?

    Or should my endpoint code throw an XYZObjectNotFoundException and use the SoapFaultMappingExceptionResolver to return this exception to the client?

    What's the better way?
    Obviously it's a matter of taste, but I think the better way is to throw an (checked) exception in your business logic, and map that to a soap fault. The exception has absolutely no SOAP-related stuff in it. This way, if you also have a WEB UI, you can map that same exception to a specific error page. A clean separation of concerns is your goal here.

    Quote Originally Posted by res1st
    It would be also nice to map SOAPFault codes of my XYZObjectNotFoundException to message constants defined in my XSD.
    How can i do this?
    I know i can define an xml schema enumeration for my error message constants, but how can i link an XYZObjectNotFoundException to a schema enumeration?
    I am not sure I understand what you want to do. Could you elaborate a bit more?
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Mar 2006
    Location
    Germany, Karlsruhe
    Posts
    157

    Default

    Obviously it's a matter of taste, but I think the better way is to throw an (checked) exception in your business logic, and map that to a soap fault.
    I think you are right, i'm doing this right now. I'm using the SoapFaultMappingExceptionResolver, but i have to extend it because it want deliver custom message texts of my exceptions. My Exception texts are build at runtime. Actually, it's only static text from my spring application context, but it's ok at the moment.
    But it's a little bit more complicated.

    I will explain it with the following scenario:
    I have an WS-API with CRUD operations. All operations can throw a DataAccessException.
    But this is too generic. That's why i extend my DataAccessException by an ObjectNotFound exception (if an invalid ID is given).

    I added soap-faults to my WSDL document and described them in a xml schema file. If i generate client code with axis, all is looking fine. I get exception classes (AxisFault classes) for my DataAccessException and my ObjectNotFoundException.

    What's missing is my server exception handling. JAXB has generated "fault" classes, but this classes aren't exception classes - it's just the name. JAXB can't know that this classes should be exception, because it only parses the xml schema file and not my wsdl file.
    But how do i get exception classes from JAXB?

    If this problem is solved, i can write an exception mapper which generates my soap faults.

    Cheers,

    Ingo

  4. #4
    Join Date
    Feb 2008
    Posts
    6

    Default Is there a solution to this problem?

    Or Exception classes as Faults in autogenerated wsdl?

  5. #5
    Join Date
    Aug 2005
    Posts
    39

    Default

    I'm confused by this also.

    My schema defines XyzRequest, XyzResponse, and XyzFault. JAXB is used to generate POJO classes for each of these. The schema types are also picked up by DefaultWsdl11Definition, which exposes XyzFault as a wsdl:fault for the Xyz operation. So far so good.

    But now there seems to be a disconnect between the faults as declared by the WSDL, and the exception handling. The XyzFault class, as generated by JAXB, is not an Exception, and so I have define an internal exception class and theow that from my endpoint.

    But how do I then map that exception on to the XyzFault? If the supplied exception resolvers only allow you to resolve to a generic fault type, with fault code and message, how can we resolve on to the operation-specific faults as defined in the WSDL? If the generated XyzFault class even relevent?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •