1 package http; 2 3 import java.net.*; 4 import java.io.*; 5 import java.util.*; 6 import dinamica.*; 7 8 17 public class HttpTunnelTest 18 { 19 20 public static void main(String [] args) throws Throwable 21 { 22 HashMap map = httpGet("http://localhost/sdk/action/tunnel", true); 23 Recordset rs1 = (Recordset)map.get("query.sql"); 24 Recordset rs2 = (Recordset)map.get("query.sql.metadata"); 25 System.out.println(rs1); 26 System.out.println(rs2); 27 } 28 29 36 public static HashMap httpGet(String url, boolean logStdout) throws Throwable 37 { 38 39 URL page = new URL(url); 41 HttpURLConnection urlc = (HttpURLConnection)page.openConnection(); 42 urlc.setUseCaches(false); 43 44 if (logStdout) 45 { 46 System.out.println("Waiting for reply...:" + url); 47 System.out.println("Content-type = " + urlc.getContentType()); 48 System.out.println("Content-length = " + urlc.getContentLength()); 49 System.out.println("Response-code = " + urlc.getResponseCode()); 50 System.out.println("Response-message = " + urlc.getResponseMessage()); 51 } 52 53 int retCode = urlc.getResponseCode(); 55 String retMsg = urlc.getResponseMessage(); 56 if (retCode>=400) 57 throw new Throwable ("HTTP Error: " + retCode + " - " + retMsg); 58 59 ObjectInputStream in = new ObjectInputStream( new BufferedInputStream(urlc.getInputStream(), urlc.getContentLength()) ); 61 HashMap map = (HashMap)in.readObject(); 62 in.close(); 63 64 if (logStdout) 65 { 66 System.out.println("Document received."); 67 } 68 69 return map; 70 71 } 72 73 } 74 | Popular Tags |