List of usage examples for org.apache.commons.httpclient HttpClient executeMethod
public int executeMethod(HttpMethod paramHttpMethod) throws IOException, HttpException
From source file:HttpClientTest.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); GetMethod method = new GetMethod("http://www.google.com"); int returnCode = client.executeMethod(method); System.err.println(method.getResponseBodyAsString()); method.releaseConnection();//from w w w .ja v a 2s . c om }
From source file:example.HelloIvy.java
public static void main(String[] args) throws Exception { String message = "Hello Ivy!"; System.out.println("standard message : " + message); System.out.println(/*from w ww. ja v a2s .c o m*/ "capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); HttpClient client = new HttpClient(); HeadMethod head = new HeadMethod("http://www.ibiblio.org/"); client.executeMethod(head); int status = head.getStatusCode(); System.out.println("head status code with httpclient: " + status); head.releaseConnection(); System.out.println("now check if httpclient dependency on commons-logging has been realized"); Class<?> clss = Class.forName("org.apache.commons.logging.Log"); System.out.println("found logging class in classpath: " + clss); }
From source file:com.discursive.jccook.httpclient.SSLExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); String url = "https://www.amazon.com/gp/flex/sign-in.html"; HttpMethod method = new GetMethod(url); client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection();/*from www.j av a2 s .c o m*/ method.recycle(); }
From source file:com.fusesource.demo.controller.Client.java
public static void main(String args[]) throws Exception { Client client = new Client(); PostMethod post = new PostMethod("http://localhost:" + port + "/controller/process"); post.addRequestHeader("Accept", "text/xml"); RequestEntity entity = new StringRequestEntity(DATA, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, null); post.setRequestEntity(entity);/*w w w . ja v a2 s .com*/ HttpClient httpclient = new HttpClient(); try { System.out.println("Sending data:\n" + DATA); int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println("Response data:\n" + post.getResponseBodyAsString()); } finally { post.releaseConnection(); } System.out.println("\n"); System.exit(0); }
From source file:com.discursive.jccook.httpclient.DebuggingExample.java
public static void main(String[] args) throws HttpException, IOException { // Configure Logging System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); HttpClient client = new HttpClient(); String url = "http://www.discursive.com/jccook/"; HttpMethod method = new GetMethod(url); client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection();//from w w w .j ava 2 s .c o m method.recycle(); }
From source file:com.discursive.jccook.httpclient.GetExample.java
public static void main(String[] args) { HttpClient client = new HttpClient(); String url = "http://www.discursive.com/jccook/"; HttpMethod method = new GetMethod(url); try {//from w w w. java 2 s. c o m client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (HttpException he) { System.out.println("HTTP Problem: " + he.getMessage()); } catch (IOException ioe) { System.out.println("IO Exeception: " + ioe.getMessage()); } finally { method.releaseConnection(); method.recycle(); } }
From source file:PostXML.java
/** * * Usage://ww w. j a v a2 s. c om * java PostXML http://mywebserver:80/ c:\foo.xml * * @param args command line arguments * Argument 0 is a URL to a web server * Argument 1 is a local filename * */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println( "Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostXML <url> <filename>]"); System.out.println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar"); System.out.println("<loglevel> - one of error, warn, info, debug, trace"); System.out.println("<url> - the URL to post the file to"); System.out.println("<filename> - file to post to the URL"); System.out.println(); System.exit(1); } // Get target URL String strURL = args[0]; // Get file to be posted String strXMLFilename = args[1]; File input = new File(strXMLFilename); // Prepare HTTP post PostMethod post = new PostMethod(strURL); // Request content will be retrieved directly // from the input stream RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { int result = httpclient.executeMethod(post); // Display status code System.out.println("Response status code: " + result); // Display response System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are done post.releaseConnection(); } }
From source file:PostSOAP.java
/** * * Usage://from ww w . j a v a 2 s. c o m * java PostSOAP http://mywebserver:80/ SOAPAction c:\foo.xml * * @param args command line arguments * Argument 0 is a URL to a web server * Argument 1 is the SOAP Action * Argument 2 is a local filename * */ public static void main(String[] args) throws Exception { if (args.length != 3) { System.out.println( "Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostSOAP <url> <soapaction> <filename>]"); System.out.println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar"); System.out.println("<loglevel> - one of error, warn, info, debug, trace"); System.out.println("<url> - the URL to post the file to"); System.out.println("<soapaction> - the SOAP action header value"); System.out.println("<filename> - file to post to the URL"); System.out.println(); System.exit(1); } // Get target URL String strURL = args[0]; // Get SOAP action String strSoapAction = args[1]; // Get file to be posted String strXMLFilename = args[2]; File input = new File(strXMLFilename); // Prepare HTTP post PostMethod post = new PostMethod(strURL); // Request content will be retrieved directly // from the input stream RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); // consult documentation for your web service post.setRequestHeader("SOAPAction", strSoapAction); // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { int result = httpclient.executeMethod(post); // Display status code System.out.println("Response status code: " + result); // Display response System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are done post.releaseConnection(); } }
From source file:com.zxm.servicemix.examples.cxf.jaxrs.client.Client.java
public static void main(String args[]) throws Exception { // Sent HTTP GET request to query all customer info // Sent HTTP GET request to query customer info System.out.println("Sent HTTP GET request to query customer info"); URL url = new URL("http://localhost:8181/cxf/crm/customerservice/customers/123"); InputStream in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP GET request to query sub resource product info System.out.println("\n"); System.out.println("Sent HTTP GET request to query sub resource product info"); url = new URL("http://localhost:8181/cxf/crm/customerservice/orders/223/products/323"); in = url.openStream();/*from w w w.ja va 2 s . c o m*/ System.out.println(getStringFromInputStream(in)); // Sent HTTP PUT request to update customer info System.out.println("\n"); System.out.println("Sent HTTP PUT request to update customer info"); Client client = new Client(); String inputFile = client.getClass().getResource("update_customer.xml").getFile(); File input = new File(inputFile); PutMethod put = new PutMethod("http://localhost:8181/cxf/crm/customerservice/customers"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(put); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(put.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } // Sent HTTP POST request to add customer System.out.println("\n"); System.out.println("Sent HTTP POST request to add customer"); inputFile = client.getClass().getResource("add_customer.xml").getFile(); input = new File(inputFile); PostMethod post = new PostMethod("http://localhost:8181/cxf/crm/customerservice/customers"); post.addRequestHeader("Accept", "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } System.out.println("\n"); System.exit(0); }
From source file:com.mycompany.jaxrsexample.client.Client.java
public static void main(String args[]) throws Exception { // Sent HTTP GET request to query all students info System.out.println("Invoking server through HTTP GET to query all students info"); URL url = new URL("http://localhost:9000/studentservice/students"); InputStream in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP GET request to query student info System.out.println("Sent HTTP GET request to query customer info"); url = new URL("http://localhost:9000/studentservice/students/1"); in = url.openStream();//from w ww. j a v a 2 s.c om System.out.println(getStringFromInputStream(in)); // Sent HTTP PUT request to update student info System.out.println("\n"); System.out.println("Sent HTTP PUT request to update student info"); Client client = new Client(); String inputFile = client.getClass().getResource("/update_student.xml").getFile(); URIResolver resolver = new URIResolver(inputFile); File input = new File(resolver.getURI()); PutMethod put = new PutMethod("http://localhost:9000/studentservice/students"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(put); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(put.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } // Sent HTTP POST request to add student System.out.println("\n"); System.out.println("Sent HTTP POST request to add student"); inputFile = client.getClass().getResource("/add_student.xml").getFile(); resolver = new URIResolver(inputFile); input = new File(resolver.getURI()); PostMethod post = new PostMethod("http://localhost:9000/studentservice/students"); post.addRequestHeader("Accept", "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } System.out.println("\n"); System.exit(0); }