List of usage examples for org.apache.commons.httpclient HttpClient executeMethod
public int executeMethod(HttpMethod paramHttpMethod) throws IOException, HttpException
From source file:$.EndpointIT.java
@Test public void testServlet() throws Exception { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(URL); try {/*from w w w . j a v a 2 s . c om*/ int statusCode = client.executeMethod(method); assertEquals("HTTP GET failed", HttpStatus.SC_OK, statusCode); String response = method.getResponseBodyAsString(1000); assertTrue("Unexpected response body", response.contains("Hello! How are you today?")); } finally { method.releaseConnection(); } }
From source file:net.morphbank.webclient.RemoteImageProcessing.java
public void sendImage(String strURL, String id, String originalFileName, String imageFileName) throws Exception { File input = new File(imageFileName); // Prepare HTTP post PostMethod post = new PostMethod(strURL); Part[] parts = { new StringPart("id", id), new StringPart("fileName", originalFileName), new FilePart("image", originalFileName, input) }; RequestEntity entity = new MultipartRequestEntity(parts, post.getParams()); post.setRequestEntity(entity);// w ww . ja v a 2 s.co m // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { System.out.println("Trying post"); int postStatus = httpclient.executeMethod(post); // Display status code System.out.println("Response status code: " + postStatus); // Display response System.out.print("Response body: "); InputStream response = post.getResponseBodyAsStream(); for (int i = response.read(); i != -1; i = response.read()) { System.out.write(i); } System.out.flush(); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } }
From source file:com.predic8.membrane.core.http.MethodTest.java
@Test public void testDELETE() throws Exception { HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod("http://localhost:4000/method-test/"); int status = client.executeMethod(delete); assertTrue(status < 400);//from ww w. j ava 2 s . c om }
From source file:exception.handler.configuration.compatibility.ExceptionHandlerRedirectConfigTest.java
@Test public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); client.executeMethod(method); String message = method.getResponseBodyAsString(); assertTrue(message.contains("Called the page /error_page")); }
From source file:exception.handler.configuration.ExceptionHandlerDefaultConfigTest.java
@Test public void defaultConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); client.executeMethod(method); String message = method.getResponseBodyAsString(); assertTrue(message.contains("Called the page /application_error")); }
From source file:com.thoughtworks.go.agent.functional.X509CertificateTest.java
@Test public void shouldSaveCertificateInAgentTrustStore() throws Exception { Protocol authhttps = new Protocol("https", protocolSocketFactory, sslPort); Protocol.registerProtocol("https", authhttps); HttpClient client = new HttpClient(); GetMethod httpget = new GetMethod("https://localhost:" + sslPort + "/go/"); client.executeMethod(httpget); assertTrue("Should have created trust store", truststore.exists()); }
From source file:hydrograph.ui.communication.debugservice.DebugServiceClient.java
private void executePostMethod(PostMethod postMethod) throws IOException, HttpException { HttpClient httpClient = new HttpClient(); httpClient.executeMethod(postMethod); }
From source file:net.jadler.AbstractJadlerResetIntegrationTest.java
private void assertStatus(int expected) throws IOException { final HttpClient client = new HttpClient(); final GetMethod method = new GetMethod("http://localhost:" + port() + "/"); assertThat(client.executeMethod(method), is(expected)); method.releaseConnection();//from w ww .ja v a 2s. c o m }
From source file:net.morphbank.webclient.PostXML.java
public void post(String strURL, String strXMLFilename) throws Exception { File input = new File(strXMLFilename); // Prepare HTTP post PostMethod post = new PostMethod(strURL); // Request content will be retrieved directly // from the input stream Part[] parts = { Part[] parts = { new FilePart("uploadFile", strXMLFilename, input) }; RequestEntity entity = new MultipartRequestEntity(parts, post.getParams()); // RequestEntity entity = new FileRequestEntity(input, // "text/xml;charset=utf-8"); post.setRequestEntity(entity);//from w w w . j a va2s . c om // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { System.out.println("Trying post"); int result = httpclient.executeMethod(post); // Display status code System.out.println("Response status code: " + result); // Display response System.out.println("Response body: "); InputStream response = post.getResponseBodyAsStream(); //int j = response.read(); System.out.write(j); for (int i = response.read(); i != -1; i = response.read()) { System.out.write(i); } //System.out.flush(); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } }
From source file:com.robonobo.common.io.HttpInputStream.java
protected InputStream createInputStream() throws IOException { HttpClient client = new HttpClient(); HttpMethod method = createMethod(url); int status = client.executeMethod(method); switch (status) { case 200:/*from w w w . ja v a2 s . c om*/ case 206: return method.getResponseBodyAsStream(); default: throw new IOException("Unable to connect to url '" + url + "', status code: " + status); } }