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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] > Sent: Wednesday, August 01, 2007 9:11 AM > To: [email protected] > 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
