You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Moore, Greg" <Gr...@adp.com> on 2007/08/01 18:05:42 UTC

How to handle soap faults?

Hi, 

Done some searching of axis and other lists as well as google searches
and I haven't come up with anything that explained what I am wondering
about. 

I'm posting an xml file containing a soap envelope to a service and I
get back a xml response that will either contain a soap fault or a CDATA
element. I'm using apache commons HttpClient to do this. 

My question is it possible to use Axis to handle soap errors and/or
faults using this method. If it is a pointer on how to do it brief
example would be greatly appreciated. 

Thanks in Advance,

Greg Moore
QA Specialist IV
Dealer Services
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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: How to handle soap faults?

Posted by "Moore, Greg" <Gr...@adp.com>.
Dims,

Wow. thanks!! I didn't expect such a quick response with an example in
jyhton... 

Thank you very much. You've made my week. I've been struggling with this
for a while now. I was expecting it to be harder.

Regards,
Greg. 

-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com] 
Sent: Wednesday, August 01, 2007 2:06 PM
To: Moore, Greg
Cc: axis-user@ws.apache.org
Subject: Re: How to handle soap faults?

Here you go:

#This handles the imports of the java stuff
from org.apache.commons.httpclient import *
from org.apache.commons.httpclient.methods import *
from org.apache.axis2.builder import *
from java.lang import *
from java.io import File

# xmlfilename contains a complete SOAP Envelope and all the headers
xmlFilename = 'aSoapEnvelope.xml'
xmlData = File(xmlFilename)
length = xmlData.length()
url = "http://localhost:5050/axis2/services/Version"
soapAction = "urn:getVersion"

# setup the http client -- post method and http headers
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)

# every thing is set now fire it off.
# responseText is whatever the server sends back either
# a response containing soap fault or a one containing cdata
httpClient = HttpClient()
statusCode = httpClient.executeMethod(post)
print "HTTP status code: " + Integer.toString(statusCode)
if statusCode == HttpStatus.SC_OK:
    builder =
BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print envelope.toString();
else:
# I'd like to check for soap fault here instead of a generic
# failure.
    builder =
BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print "Has Fault? : " +
Boolean.toString(envelope.getBody().hasFault());

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi dims,
>
> Sure, but I'll warn you its in Jython so its not straight Java but
> pretty readable as is. # are single line comments just like the java
//
>
>         #This handles the imports of the java stuff
>         from org.apache.commons.httpclient import *
>         from org.apache.commons.httpclient.methods import *
>         from java.io import File
>
>         # xmlfilename contains a complete SOAP Envelope and all the
> headers
>         xmlFilename = 'aSoapEnvelope.xml'
>         xmlData = File(xmlFilename)
>         length = xmlData.length()
>         url = "http://myserver.somewhere.com/services/Check.asmx"
>         soapAction = "http://GateWay/Services/Check/GetReportXml"
>
>         # setup the http client -- post method and http headers
>         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)
>
>         # every thing is set now fire it off.
>         # responseText is whatever the server sends back either
>         # a response containing soap fault or a one containing cdata
>         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()
>
> Hope this helps
>
> Regards,
> Greg,
>
>
> On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
[truncated]
> My question is it possible to use Axis to handle soap errors and/or 
> faults using HttpClient. 
-- 
Davanum Srinivas :: http://davanum.wordpress.com


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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to handle soap faults?

Posted by Davanum Srinivas <da...@gmail.com>.
Here you go:

#This handles the imports of the java stuff
from org.apache.commons.httpclient import *
from org.apache.commons.httpclient.methods import *
from org.apache.axis2.builder import *
from java.lang import *
from java.io import File

# xmlfilename contains a complete SOAP Envelope and all the headers
xmlFilename = 'aSoapEnvelope.xml'
xmlData = File(xmlFilename)
length = xmlData.length()
url = "http://localhost:5050/axis2/services/Version"
soapAction = "urn:getVersion"

# setup the http client -- post method and http headers
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)

# every thing is set now fire it off.
# responseText is whatever the server sends back either
# a response containing soap fault or a one containing cdata
httpClient = HttpClient()
statusCode = httpClient.executeMethod(post)
print "HTTP status code: " + Integer.toString(statusCode)
if statusCode == HttpStatus.SC_OK:
    builder = BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print envelope.toString();
else:
# I'd like to check for soap fault here instead of a generic
# failure.
    builder = BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print "Has Fault? : " + Boolean.toString(envelope.getBody().hasFault());

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi dims,
>
> Sure, but I'll warn you its in Jython so its not straight Java but
> pretty readable as is. # are single line comments just like the java //
>
>         #This handles the imports of the java stuff
>         from org.apache.commons.httpclient import *
>         from org.apache.commons.httpclient.methods import *
>         from java.io import File
>
>         # xmlfilename contains a complete SOAP Envelope and all the
> headers
>         xmlFilename = 'aSoapEnvelope.xml'
>         xmlData = File(xmlFilename)
>         length = xmlData.length()
>         url = "http://myserver.somewhere.com/services/Check.asmx"
>         soapAction = "http://GateWay/Services/Check/GetReportXml"
>
>         # setup the http client -- post method and http headers
>         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)
>
>         # every thing is set now fire it off.
>         # responseText is whatever the server sends back either
>         # a response containing soap fault or a one containing cdata
>         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()
>
> Hope this helps
>
> Regards,
> Greg,
>
>
> -----Original Message-----
> From: Davanum Srinivas [mailto:davanum@gmail.com]
> Sent: Wednesday, August 01, 2007 9:11 AM
> To: axis-user@ws.apache.org
> Subject: Re: How to handle soap faults?
>
> Greg,
>
> Can you please post what you have so far?
>
> thanks,
> dims
>
>
>
> 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.
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

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


RE: How to handle soap faults?

Posted by "Moore, Greg" <Gr...@adp.com>.
Hi dims,

Sure, but I'll warn you its in Jython so its not straight Java but
pretty readable as is. # are single line comments just like the java // 

        #This handles the imports of the java stuff
        from org.apache.commons.httpclient import *
        from org.apache.commons.httpclient.methods import *
        from java.io import File

        # xmlfilename contains a complete SOAP Envelope and all the
headers
        xmlFilename = 'aSoapEnvelope.xml'
        xmlData = File(xmlFilename)
        length = xmlData.length()
        url = "http://myserver.somewhere.com/services/Check.asmx"
        soapAction = "http://GateWay/Services/Check/GetReportXml"
        
        # setup the http client -- post method and http headers
        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)
        
        # every thing is set now fire it off.
        # responseText is whatever the server sends back either 
        # a response containing soap fault or a one containing cdata 
        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()

Hope this helps 

Regards,
Greg,


-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com] 
Sent: Wednesday, August 01, 2007 9:11 AM
To: axis-user@ws.apache.org
Subject: Re: How to handle soap faults?

Greg,

Can you please post what you have so far?

thanks,
dims



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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to handle soap faults?

Posted by Davanum Srinivas <da...@gmail.com>.
Greg,

Can you please post what you have so far?

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi,
>
> Done some searching of axis and other lists as well as google searches
> and I haven't come up with anything that explained what I am wondering
> about.
>
> I'm posting an xml file containing a soap envelope to a service and I
> get back a xml response that will either contain a soap fault or a CDATA
> element. I'm using apache commons HttpClient to do this.
>
> My question is it possible to use Axis to handle soap errors and/or
> faults using this method. If it is a pointer on how to do it brief
> example would be greatly appreciated.
>
> Thanks in Advance,
>
> Greg Moore
> QA Specialist IV
> Dealer Services
> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

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