Announcement Announcement Module
Collapse
No announcement yet.
Exception handling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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?

    Comment


    • #3
      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

      Comment


      • #4
        Is there a solution to this problem?

        Or Exception classes as Faults in autogenerated wsdl?

        Comment


        • #5
          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?

          Comment

          Working...
          X