Passer au contenu principal
Adaptive Insights
Knowledge and Support - Adaptive Insights

Sample Client Java Program

Below is a sample java program that calls the "exportAccounts" API method. The results of the API method call are just printed to the screen. In a real application, the XML data would be parsed and the underlying account data would be pro­cessed.

public class WebServiceClient {
    * Make an "exportAccounts" method call.
   public static void main(String[] args) throws Exception {
       String request = "<?xml version='1.0' encoding='UTF-8'?>\n" +
                        "<call method=\"exportAccounts\">\n" +
" <credentials login=\"\" password=\"\"/ callerName=\"test program\">\n" +
       // Make a URL connection to the Adaptive Planning web service URL
       URL url = new URL("");
       HttpURLConnection conn = (HttpURLConnection) url.openConnection();
       // Set the content type, the HTTP method, and tell the connection we expect output
       conn.setRequestProperty("content-type", "text/xml;charset=UTF-8");
       // Send the request
       writeRequest(conn, request);
       // Read the response
       String response = readResponse(conn);
       // Print it out
    * Write the request to the given URLConnection
   private static void writeRequest(HttpURLConnection conn, String request) throws Exception {
    * Read the response from the given URL Connection
   private static String readResponse(HttpURLConnection conn) throws Exception {
       byte[] buffer = new byte[4096];
       StringBuilder sb = new StringBuilder();
       int amt;
       while ((amt = conn.getInputStream().read(buffer)) != -1) {
           String s = new String(buffer, 0, amt, "UTF-8");
       return sb.toString();
  • Cet article vous a été utile ?