From: Moore, G. <Gre...@ad...> - 2007-06-20 00:59:08
|
Hi, I am a long time fan of Jython and a long time reader of this list. The members of this list have indirectly answered may of my questions. However I have a question that I haven't found an answer to. I hope the members the list can help me with. I Just need to upload an xml file to a service the get and display the result. Check for fault and report on them if they happen.=20 I'm learning SOAP (client side is all I need) and I'm using Axis 1.4 however my python skills are much better then my Java skills. so I'm having a little translating the example client that comes with axis=20 The basic question is how do I translate the following line: String ret =3D (String) call.invoke( new Object[] { "Hello!" } );=20 below is the code I wrote. I hope the formatting isn't too messed up. Thanks for all the past help and thanks in advance for any help with this. It is truly much appreciated.=20 Regards, Greg W. Moore QA IV ADP, Inc. The java looks like:=20 public class TestClient { public static void main(String [] args) { try { String endpoint =3D "http://nagoya.apache.org:5049/axis/services/echo"; Service service =3D new Service(); Call call =3D (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName( =09=09new QName("http://soapinterop.org/", "echoString")); =20 // I got stuck translating the next line. String ret =3D (String) call.invoke( new Object[] { "Hello!" } ); System.out.println("Sent 'Hello!', got '" + ret + "'"); } catch (Exception e) { System.err.println(e.toString()); } } } So this is what I have so far... but I'm not sure where the xml file comes in... I don't really understand the use of ByteArrayInputStream=20 Yes I know there are easier ways to accomplish this but it needs to be SOAP. Please just accept that. If I'm really off base please let me know that as well.=20 from org.apache.axis.client import Call from org.apache.axis.client import Service from org.apache.axis.message import SOAPEnvelope from org.apache.axis.utils import Options #from org.apache.axis import SOAPException?? from java.io import ByteArrayInputStream, InputStream, FileReader from java.net import URL from java.lang import String url =3D "http://[insertHostNameHere]/Ecommerce/services/Check.asmx" serviceName =3D "GetReportXml" TRUE =3D 1 FALSE =3D 0 DEBUGGING =3D TRUE fileSelection =3D 'test.xml' msg =3D FileReader(fileSelection) def doTest(urlArg, serviceArg=3DNone): #opts =3D Options(String(urlArg)) #url =3D opts.getURL() action =3D serviceName if (serviceArg !=3D None): action =3D "GetReport" #args =3D opts.getRemainingArgs() if urlArg !=3D None: action =3D "http://SomeValidHost/services/something.asmx" msgBytes =3D String(msg).getBytes() input =3D ByteArrayInputStream(msgBytes) service =3D Service() call =3D service.createCall() soapEnvelope =3D SOAPEnvelope() call.setTargetEndPointAddress(URL(url)) if action !=3D None: call.setUseSOAPAction(TRUE) call.setSOAPActionURI(action) result =3D call.invoke(env) #except print 'Request:\n', msg print '\n\nResponse:\n', result # was: env print '=3D=3D=3D (toStr)\n', result.toString() # was:env.toString() return result if __name__ =3D=3D '__main__': =09#start things off. =09doTest(url, servicename) =3D=3D=3D I can provide an example xml file if needed but it starts out as usual... <?xml version=3D"1.0" encoding=3D"utf-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=3D"http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC=3D"http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <GetReportXml xmlns=3D"http://[someHostName]/Ecommerce/Services/Credit"> =09<xmlrequest> =09<!-- bunch of stuff here --> </xmlrequest> </GetReportXml> </SOAP-ENV:Body> </SOAP-ENV:Envelope> This message and any attachments are intended only for the use of the add= ressee and may contain information that is privileged and confidential. I= f the reader of the message is not the intended recipient or an authorize= d representative of the intended recipient, you are hereby notified that = any dissemination of this communication is strictly prohibited. If you ha= ve received this communication in error, please notify us immediately by = e-mail and delete the message and any attachments from your system. |