Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.net.URLEncoder;
  9.  
  10. public class EclDirectExample {
  11.      
  12.     public static String execute(String clusterAddress,
  13.                                  String clusterName,
  14.                                  String eclCode) {
  15.        try {  
  16.             String urlString = "http://" + clusterAddress + ":8008/EclDirect/RunEcl";
  17.  
  18.             // Construct data
  19.             String data = URLEncoder.encode("eclText", "UTF-8")
  20.                + "=" + URLEncoder.encode(eclCode, "UTF-8")
  21.                + "&" + URLEncoder.encode("cluster", "UTF-8")
  22.                + "=" + URLEncoder.encode(clusterName, "UTF-8");
  23.  
  24.             // Send data
  25.             URL url = new URL(urlString);
  26.             URLConnection conn = url.openConnection();
  27.             conn.setDoOutput(true);
  28.             OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  29.             wr.write(data);
  30.             wr.flush();
  31.  
  32.             // Get the response
  33.             return convertInputStreamToString(conn.getInputStream());
  34.            
  35.         } catch (Exception e) {
  36.             throw new RuntimeException(e);
  37.         }
  38.     }
  39.  
  40.  
  41.      public static String convertInputStreamToString(InputStream ists)
  42.           throws IOException {
  43.        
  44.         if (ists != null) {
  45.             StringBuilder sb = new StringBuilder();
  46.             String line;
  47.  
  48.             try {
  49.                 BufferedReader r1 = new BufferedReader(
  50.                           new InputStreamReader(ists, "UTF-8"));
  51.                 while ((line = r1.readLine()) != null) {
  52.                     sb.append(line).append("\n");
  53.                 }
  54.             } finally {
  55.                 ists.close();
  56.             }
  57.             return sb.toString();
  58.         } else {      
  59.             return "";
  60.         }
  61.     }
  62.        
  63.     public static void main(String args[]) {
  64.        
  65.            String eclCode = "OUTPUT('Hello World');";
  66.            System.out.println(
  67.               execute("192.168.59.129", "thor", eclCode));
  68.     }
  69.    
  70. }