How to capture a SOAP exception from a webservice?

Discussion in 'Ruby' started by Nate Imaqaguy, Aug 2, 2006.

  1. I’m trying to catch a soap exception from a web service, but I’m a n00b
    and am having a hard time figuring it out.

    I’m using ruby 1.8.4 (win32)--if it matters.

    I’ve got the start of my program created and can receive successful soap
    objects back from the webservice. So that’s all working good.

    Next, I want to capture SOAP exception errors. For example, I’ll get a
    message saying something does not exist or is not found. This is the
    same message that is in the return XML “faultstring†tag.

    Do I have to find a way to parse the returned XML, or is there an easy
    way to grab the soap exception I'm looking for?

    Thanks for the help. BTW, I tried to use the forum search (I always try
    that first), but it's down for maintenance or something like that.

    Thanks all,

    -nate

    --
    Posted via http://www.ruby-forum.com/.
     
    Nate Imaqaguy, Aug 2, 2006
    #1
    1. Advertising

  2. begin
    @query = @soap.apiFunction(
    {'Key'=>'Value','Key2'=>Value2'}
    )
    #rescue ::SOAP::FaultError => e
    rescue ::XSD::ValueSpaceError => e
    assert_equal("{http://www.foo.com/api}FooBarEnum: cannot accept
    'foo'",e.to_s)
    end

    Hope that helps...
    -Chris

    Nate Imaqaguy wrote:
    > I'm trying to catch a soap exception from a web service, but I'm a n00b
    > and am having a hard time figuring it out.
    >
    > I'm using ruby 1.8.4 (win32)--if it matters.
    >
    > I've got the start of my program created and can receive successful soap
    > objects back from the webservice. So that's all working good.
    >
    > Next, I want to capture SOAP exception errors. For example, I'll get a
    > message saying something does not exist or is not found. This is the
    > same message that is in the return XML "faultstring" tag.
    >
    > Do I have to find a way to parse the returned XML, or is there an easy
    > way to grab the soap exception I'm looking for?
    >
    > Thanks for the help. BTW, I tried to use the forum search (I always try
    > that first), but it's down for maintenance or something like that.
    >
    > Thanks all,
    >
    > -nate
    >
    > --
    > Posted via http://www.ruby-forum.com/.
     
    Chris McMahon, Aug 3, 2006
    #2
    1. Advertising

  3. Hmmm…

    **If** I understand what you were trying to tell me, I **think** I
    adapted your example to my code and came up with this. BTW, “param†is
    an int I’m passing to the method.

    ----------------------------
    if results = soap.FindPatientById( param )
    then puts results.first_name
    puts results.last_name
    else
    begin
    rescue ::SOAP::FaultError => e
    # rescue ::XSD::ValueSpaceError => e
    puts e.to_s
    end
    end
    -----------------------------

    I had something pretty similar to this already. …but it’s not
    working.

    The way I’m doing it, I don’t think I needed the “assert equalâ€
    statement—right? The most confusing parts to me are the “rescue†lines.
    Specifically, which one to use (I went with SOAP, but tried both) and
    how you knew to put “FaultError†there.

    Like I said, I’m a total n00b to ruby. I haven’t even tried programming
    anything since my last C class about 6 years ago, so please be patient
    if I’m missing something obvious.

    = )

    Thanks again,

    -nate





    Chris McMahon wrote:
    > begin
    > @query = @soap.apiFunction(
    > {'Key'=>'Value','Key2'=>Value2'}
    > )
    > #rescue ::SOAP::FaultError => e
    > rescue ::XSD::ValueSpaceError => e
    > assert_equal("{http://www.foo.com/api}FooBarEnum: cannot accept
    > 'foo'",e.to_s)
    > end
    >
    > Hope that helps...
    > -Chris



    --
    Posted via http://www.ruby-forum.com/.
     
    Nate Imaqaguy, Aug 3, 2006
    #3
  4. Re: How to capture a SOAP exception w/ ruby?

    Hello.

    = )

    I know I'm close on this one--I can feel it. Can anyone help? I'd
    appreciate it a lot.

    Thanks,

    -nate




    Nate Imaqaguy wrote:
    > Hmmm…
    >
    > **If** I understand what you were trying to tell me, I **think** I
    > adapted your example to my code and came up with this. BTW, “param†is
    > an int I’m passing to the method.
    >
    > ----------------------------
    > if results = soap.FindPatientById( param )
    > then puts results.first_name
    > puts results.last_name
    > else
    > begin
    > rescue ::SOAP::FaultError => e
    > # rescue ::XSD::ValueSpaceError => e
    > puts e.to_s
    > end
    > end
    > -----------------------------
    >
    > I had something pretty similar to this already. …but it’s not
    > working.
    >
    > The way I’m doing it, I don’t think I needed the “assert equalâ€
    > statement—right? The most confusing parts to me are the “rescue†lines.
    > Specifically, which one to use (I went with SOAP, but tried both) and
    > how you knew to put “FaultError†there.
    >
    > Like I said, I’m a total n00b to ruby. I haven’t even tried programming
    > anything since my last C class about 6 years ago, so please be patient
    > if I’m missing something obvious.
    >
    > = )
    >
    > Thanks again,
    >
    > -nate
    >
    >
    >
    >
    >
    > Chris McMahon wrote:
    >> begin
    >> @query = @soap.apiFunction(
    >> {'Key'=>'Value','Key2'=>Value2'}
    >> )
    >> #rescue ::SOAP::FaultError => e
    >> rescue ::XSD::ValueSpaceError => e
    >> assert_equal("{http://www.foo.com/api}FooBarEnum: cannot accept
    >> 'foo'",e.to_s)
    >> end
    >>
    >> Hope that helps...
    >> -Chris



    --
    Posted via http://www.ruby-forum.com/.
     
    Nate Imaqaguy, Aug 4, 2006
    #4
  5. Nate Imaqaguy

    Bira Guest

    On 8/3/06, Nate Imaqaguy <> wrote:
    > Hmmm=85
    >
    > ----------------------------
    > if results =3D soap.FindPatientById( param )
    > then puts results.first_name
    > puts results.last_name
    > else
    > begin
    > rescue ::SOAP::FaultError =3D> e
    > # rescue ::XSD::ValueSpaceError =3D> e
    > puts e.to_s
    > end
    > end
    > -----------------------------
    >
    > I had something pretty similar to this already. =85but it's not
    > working.


    From what I understand, I believe your method call has to be inside
    the "begin...rescue" block, or "rescue" won't be able to see the error
    when it happens.

    In other words, something like this:

    begin
    if ( results =3D soap.FindPatientById( param ) )
    puts results.last_name
    end
    rescue ::SOAP::FaultError =3D> e
    puts e.to_s
    end


    --=20
    Bira
    http://compexplicita.blogspot.com
    http://sinfoniaferida.blogspot.com
     
    Bira, Aug 4, 2006
    #5
  6. Excellent; thanks!



    Bira wrote:
    > On 8/3/06, Nate Imaqaguy <> wrote:
    >> puts e.to_s
    >> end
    >> end
    >> -----------------------------
    >>
    >> I had something pretty similar to this already. �but it's not
    >> working.

    >
    > From what I understand, I believe your method call has to be inside
    > the "begin...rescue" block, or "rescue" won't be able to see the error
    > when it happens.
    >
    > In other words, something like this:
    >
    > begin
    > if ( results = soap.FindPatientById( param ) )
    > puts results.last_name
    > end
    > rescue ::SOAP::FaultError => e
    > puts e.to_s
    > end



    --
    Posted via http://www.ruby-forum.com/.
     
    Nate Imaqaguy, Aug 5, 2006
    #6
    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. Max
    Replies:
    7
    Views:
    9,184
  2. smartobject

    Track and Capture SOAP messages

    smartobject, May 26, 2005, in forum: Java
    Replies:
    1
    Views:
    6,032
    shakah
    May 26, 2005
  3. Joe Wong
    Replies:
    1
    Views:
    475
    Ype Kingma
    May 14, 2004
  4. PokerJoker

    Capture SOAP envelope

    PokerJoker, Dec 29, 2004, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    414
    PokerJoker
    Dec 29, 2004
  5. Jeremy Schneider

    only able to capture last exception

    Jeremy Schneider, May 13, 2009, in forum: Ruby
    Replies:
    0
    Views:
    96
    Jeremy Schneider
    May 13, 2009
Loading...

Share This Page