r1 - 07 Dec 2006 - 18:04:46 - JonPriddeyYou are here: TWiki >  Main Web  >  ElixirEnsemble > ElixirEnsembleCookbook > CallingASOAPService

Calling a SOAP Service

Because the Object DataSource supports arbitrary JavaScript, it is quite simple to call any external APIs to obtain data. As an example, here's a SOAP client that invokes the getVersion service that is in the default configuration supplied by Apache Axis.

Preparation

You need to download Apache Axis and copy the jars in the axis lib directory into the Elixir ext directory.

Also, you need to add the Apache Axis webapps\axis directory to your web server. I used Jetty 6, but any compliant web server should work. I also had to add tools.jar from my JDK lib directory into the webapps\axis\lib directory so that JSP files could be compiled.

See the Apache Axis documentation if you need more help setting up the server side. With the server running, you should be able to connect to http://localhost:8080/axis/services/Version?wsdl and see the WSDL for the getVersion service. Horrible, isn't it?

Creating an Object DataSource

Start Elixir Ensemble and Add a new Object DataSource. Give it a name and click Next. Add one field to the schema definition - Version - with type String. Click Next.

Copy and Paste the following code into the JavaScript editor:

importClass(Packages.javax.xml.namespace.QName);

function pushTo(/*PushContext*/ cxt, /*DataListener*/ dl)
{
  // call soap
  var endpoint = "http://localhost:8080/axis/services/Version";
  var service = new Packages.org.apache.axis.client.Service();
  var call = service.createCall();
  call.setTargetEndpointAddress(new java.net.URL(endpoint));
  call.setOperationName(new QName("http://localhost:8080/axis/services/Version", "getVersion"));
  var version = call.invoke(new Array());

  // now send the record
  dl.startData(this);
  rec = this.newRecordInstance();
  data = rec.getData();
  data[0] = version;
  dl.processRecord(rec);
  dl.endData(this);
}

Finish the wizard and then Save. Finally, click the Load Data button and you should see a single record with a single field (Version) produced. Mine says:

Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)

You can now experiment with SOAP services that supply more records and/or fields. Remember if you pass parameters into the invocation (eg. call.invoke(new Array("1","2")) etc. that you can use dynamic substitution to pass the values in from outside:

call.invoke(new Array("${First}","${Second}"));

-- JonPriddey - 07 Dec 2006

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback