Results 1 to 10 of 14

Thread: howto return exceptions as soap faults

Hybrid View

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

    Default howto return exceptions as soap faults

    Hi,
    i posted my problem before in the remoting forum but it was maybe the wrong place.
    http://forum.springframework.org/showthread.php?t=25001
    It would be nice if someone can help me.
    Cheers,

    Ingo

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

    Default

    Quote Originally Posted by res1st
    Hi,
    i'm using a web service (xfire) to call my business methods. My business methods invoke DAOs to retrieve data.

    I want to put execptions from my business logic and my DAOs into a "SOAP Fault" to give my clients some error feedback.
    How can i do this?
    Are there different ways to do it?
    I'm not sure whether it is possible with XFire. Perhaps someone else can help you with this.

    It is possible with Spring Web Services (the topic of this forum), however. Just as you would map an exception to an error page in your web.xml or -servlet.xml application context, you can do the same with Spring Web Services.

    You do so by using the SoapFaultMappingExceptionResolver. In the download is a sample airline application which shows you how to wire this up. See http://springframework.cvs.sourcefor...e=text%2Fplain, at the bottom of the file.

    Cheers,
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    May 2006
    Posts
    7

    Default

    You can create XFireFault by yourselft and setup on it all information you needed to pass to client.
    Just create handler class with code to convert your custom exception to XFireFault and add it to faultHandlers list of xfire instnace.
    Handler can look like this :
    public class MyFaultHandler extends AbstractHandler {

    public void invoke(MessageContext context) throws Exception {

    Exception ex = (Exception) context.getProperty(DefaultFaultHandler.EXCEPTION) ;
    if( ex instanceof XFireFault){
    XFireFault w = (XFireFault)ex;
    String infoForClient = convertMyException( w.getCause());
    w.setMessage(infoForClient);

    }
    }
    If you are using default config - sevices.xml you need just add following to it:
    <xfire>
    <faultHandlers>
    <handler handlerClass="com.hp.webservices.handlers.MyFaultH andler"/>
    </faultHandlers>
    </xfire>

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

    Default

    Thanks for your answers.

    @poutsma
    I'm still considering spring-ws but it isn't released yet as a stable version and i heard to much bad things. That's why i use xfire and switch maybe later to spring-ws. But good to know how it would work with spring-ws. Thank you.

    @tomeks:
    Do i understand it right?
    The Business logic (and therefore DAO code) is invoked by xfire and that's why all exceptions can be cached by a xfire fault handler?

    Cheers,

    Ingo
    Last edited by res1st; May 18th, 2006 at 06:43 AM.

  5. #5
    Join Date
    May 2006
    Posts
    7

    Default

    Yes, all exceptions thrown by your service are catched and converted to XFireFault by service invoker, which is then serialized to SOAP fault.

  6. #6
    Join Date
    Jun 2005
    Location
    Athens, Greece
    Posts
    57

    Default

    Quote Originally Posted by res1st
    i heard to much bad things.
    Can you share with us the bad things that you heard?

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

    Default

    Hi Routis,

    i looked some weeks ago for web service technologies and found some bad blog entries and comments. Sorry, i didn't saved the links. But then i use goolge, i quickly find things like http://radio.weblogs.com/0112098/2005/11/23.html#a542.

    I also didn't understand what's the advantage using Spring-WS for me. Top-down development sounds interesting, but it's more easy to create java interfaces/classes then wsdl documents, right?
    At top-down the wsdl is constant. That's nice because ws-interfaces should be stable. But if i "freeze" my Java interfaces, the generated wsdl-file should also be constant. So, i stick with programming Java instead of WSDL.

    I also looked in the documentation of Spring-WS and i wasn't very satisfied with that.

    Cheers,

    Ingo

Posting Permissions

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