Software AG Products 10.7 | Service Development Help | Submitting and Receiving XML Documents | Submitting and Receiving XML in $xmldata | Sample Client Code to Submit an XML Document in $xmldata
 
Sample Client Code to Submit an XML Document in $xmldata
The following sample code for a Java client that runs in Integration Server illustrates how to read an XML document from a file, assign the XML to a variable named $xmldata, and invoke the target service sales:getOrder passing it the $xmldata variable.
import com.wm.app.b2b.client.*;
import com.wm.util.*;
import com.wm.data.*;
import java.io.*;

public class ArbitraryXMLClient

{
public static void main(String args[])
throws Exception
{
//--Read the XML document from a specified file (or from stdin)
Context c = new Context();
IData inputs = IDataFactory.create();
IDataCursor inputsCursor = inputs.getCursor();
Reader in = null;
if (args.length > 0)
{
in = new InputStreamReader(new FileInputStream(args[0]));
}
else
in = new InputStreamReader(System.in);
}
char[] buf = new char[8192];
int count = 0;
StringBuffer sb = new StringBuffer();
while((count = in.read(buf)) != -1)
{
sb.append(buf, 0, count);
}

//--Assign the XML document to a String variable
String xmldata = sb.toString();

//--Put the XML document into $xmldata in the IData object
inputsCursor.insertAfter("$xmldata", xmldata);

//--Submit the request to the sales:getOrder service on the server
c.connect("localhost:5555", "null", null);
IData outputs = c.invoke("sales", "getOrder", inputs);
c.disconnect();

//--Display the returned output values
System.out.println(outputs);
}
}
Important:
This example shows a Java-based client. However, you can use any type of IS client, including a browser-based client. For a browser-based client, post the XML document as the value portion of a $xmldata=value pair. You can post other name=value pairs with the request. For more information, see Building a Browser-Based Client.