1 /* 2 * RestServlet.java 3 * 4 * Created on October22, 2002, 5:22 PM 5 * 6 * $Header: /cvsroot/ebxmlrr/ebxmlrr/test/com/sun/ebxml/registry/interfaces/rest/RESTSender.java,v 1.4 2003/04/04 07:19:28 skchonghk Exp $ 7 * 8 */ 9 package> com.sun.ebxml.registry.interfaces.rest; 10 11 import java.net.*; 12 import java.io.*; 13 import java.net.HttpURLConnection; 14 import java.net.MalformedURLException; 15 16 /*** 17 * This is a test program for the REST interface to the registry server 18 * 19 * @see 20 * @author Uday Subbarayan(uday.s@sun.com) 21 */ 22 public class RESTSender { 23 String restURL="http://localhost:8080/ebxmlrr/registry/rest"; 24 //constructor 25 public RESTSender(){} 26 27 //testing the AdhocQueryRequest method in the QueryManger thru the Http POST 28 public void testQMAdhocQueryRequest(String xmlFileName)throws FileNotFoundException,IOException,MalformedURLException{ 29 //System.out.println("xmlFileName= "+xmlFileName); 30 String xmlAdhocQueryRequest=""; 31 String input; 32 File xmlInputFile=new File(xmlFileName); 33 BufferedReader in = new BufferedReader(new FileReader(xmlInputFile)); 34 35 while((input = in.readLine()) != null){ 36 xmlAdhocQueryRequest = xmlAdhocQueryRequest + input; 37 } 38 in.close(); 39 40 URL url = new URL(restURL); 41 HttpURLConnection httpConnection = (HttpURLConnection)(url.openConnection()); 42 httpConnection.setRequestMethod("POST"); 43 httpConnection.setDoOutput(true); 44 45 PrintWriter out = new PrintWriter(httpConnection.getOutputStream()); 46 out.println("xmldoc=" + URLEncoder.encode(xmlAdhocQueryRequest, "UTF-8")); 47 out.close(); 48 49 BufferedReader in2 = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); 50 51 String inputLine; 52 while((inputLine = in2.readLine()) != null) 53 System.out.println(inputLine); 54 in2.close(); 55 56 } 57 58 //main method 59 public static void main(String[] args) throws Exception { 60 if(args.length!=1){ 61 System.out.println("Usage: java RESTSender <input-AdhocQueryRequest-XML>"); 62 System.exit(0); 63 } 64 String xmlFileName=args[0]; 65 RESTSender rs =new RESTSender(); 66 rs.testQMAdhocQueryRequest(xmlFileName); 67 } 68 }

This page was automatically generated by Maven