You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Moore, Greg" <Gr...@adp.com> on 2007/07/25 01:22:50 UTC

can I handle soap faults when using httpClient?

Hi, 

Done some searching of httpclient, axis, jython and other lists as well
as google searches and I haven't come up with anything that explained
what I am wondering about. Maybe some kind person will take pity on the
confused. :) 

I'm posting an xml file containing a soap envelope to a service and I
get back a xml response that should contain a CDATA element. I'm using
HttpClient to do this. Below is the essential Jython code that I'm using
as an example similar to what I'm doing.  I originally was trying to do
this using Axis but after several days of trying was never successful.

My question is it possible to handle soap errors and/or faults somehow
using the method below or do I have to parse xml or is there some way I
could use axis? 

        from org.apache.commons.httpclient import *
        from org.apache.commons.httpclient.methods import *
        from java.io import File

        xmlData = File(xmlFilename)
        length = xmlData.length()
        url = "http://myserver.somewhere.com/services/Check.asmx"
        soapAction = "http://GateWay/Services/CreditCheck/GetReportXml"
        post = PostMethod(url)
        entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
        post.addRequestHeader("Content-Length", str(length))
        post.setRequestEntity(entity)
        post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
        post.addRequestHeader("User-Agent", "SQA_TestClient0")
        post.setRequestHeader("SOAPAction", soapAction)
        httpClient = HttpClient()
        statusCode = httpClient.executeMethod(post)
       if statusCode == HttpStatus.SC_OK:
                resultText = post.getResponseBodyAsString()
       else:
	  # I'd like to check for soap fault here instead of a generic
              # failure.
              print " failure: " + post.getStatusLine().toString()

Thanks in advance,
Greg Moore
Software QA
ADP, Inc.



This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


RE: can I handle soap faults when using httpClient?

Posted by "Moore, Greg" <Gr...@adp.com>.
Thanks for the reply Oleg. I tried the Axis list as well and the silence
was deafening. I've tried some stuff with Axis 1.4 but wasn't
successful.
I thought I'd try the httpClient list just in case. :)

Regards,
Greg.

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Thursday, July 26, 2007 6:15 AM
To: HttpClient User Discussion
Subject: Re: can I handle soap faults when using httpClient?

On Tue, 2007-07-24 at 18:22 -0500, Moore, Greg wrote:
[snip]
> My question is it possible to handle soap errors and/or faults somehow
> using the method below or do I have to parse xml or is there some way
I
> could use axis? 

Greg

I _assume_ one could use Axis2 engine for that end. You'll have a better
luck getting a more detailed answer at the axis-user list, though.

Oleg



This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: can I handle soap faults when using httpClient?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2007-07-24 at 18:22 -0500, Moore, Greg wrote:
> Hi, 
> 
> Done some searching of httpclient, axis, jython and other lists as well
> as google searches and I haven't come up with anything that explained
> what I am wondering about. Maybe some kind person will take pity on the
> confused. :) 
> 
> I'm posting an xml file containing a soap envelope to a service and I
> get back a xml response that should contain a CDATA element. I'm using
> HttpClient to do this. Below is the essential Jython code that I'm using
> as an example similar to what I'm doing.  I originally was trying to do
> this using Axis but after several days of trying was never successful.
> 
> My question is it possible to handle soap errors and/or faults somehow
> using the method below or do I have to parse xml or is there some way I
> could use axis? 

Greg

I _assume_ one could use Axis2 engine for that end. You'll have a better
luck getting a more detailed answer at the axis-user list, though.

Oleg


> 
>         from org.apache.commons.httpclient import *
>         from org.apache.commons.httpclient.methods import *
>         from java.io import File
> 
>         xmlData = File(xmlFilename)
>         length = xmlData.length()
>         url = "http://myserver.somewhere.com/services/Check.asmx"
>         soapAction = "http://GateWay/Services/CreditCheck/GetReportXml"
>         post = PostMethod(url)
>         entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
>         post.addRequestHeader("Content-Length", str(length))
>         post.setRequestEntity(entity)
>         post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
>         post.addRequestHeader("User-Agent", "SQA_TestClient0")
>         post.setRequestHeader("SOAPAction", soapAction)
>         httpClient = HttpClient()
>         statusCode = httpClient.executeMethod(post)
>        if statusCode == HttpStatus.SC_OK:
>                 resultText = post.getResponseBodyAsString()
>        else:
> 	  # I'd like to check for soap fault here instead of a generic
>               # failure.
>               print " failure: " + post.getStatusLine().toString()
> 
> Thanks in advance,
> Greg Moore
> Software QA
> ADP, Inc.
> 
> 
> 
> This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org