Example usage for org.apache.commons.httpclient HttpMethodBase HttpMethodBase

List of usage examples for org.apache.commons.httpclient HttpMethodBase HttpMethodBase

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase HttpMethodBase.

Prototype

public HttpMethodBase(String uri) throws IllegalArgumentException, IllegalStateException 

Source Link

Document

Constructor specifying a URI.

Usage

From source file:org.eclipse.ecf.tests.remoteservice.rest.service.RestServiceTest.java

public void testSimpleRequest() {
    String serverUrl = service.getServerUrl();
    HttpClient client = new HttpClient();
    HttpMethod method = new HttpMethodBase(serverUrl + "/getTest") {
        public String getName() {
            return "GET";
        }/*from  w w w  .  j a  v  a  2  s . c  om*/
    };
    int responseCode = 0;
    try {
        responseCode = client.executeMethod(method);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(HttpStatus.SC_OK, responseCode);
}

From source file:org.eclipse.ecf.tests.remoteservice.rest.service.RestServiceTest.java

public void testXMLRequest() {
    String serverUrl = service.getServerUrl();
    HttpClient client = new HttpClient();
    HttpMethod method = new HttpMethodBase(serverUrl + "/test.xml") {
        public String getName() {
            return "GET";
        }/*from  w ww. j a  va2s . c om*/
    };
    int responseCode = 0;
    try {
        responseCode = client.executeMethod(method);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(HttpStatus.SC_OK, responseCode);
    try {
        String body = method.getResponseBodyAsString();
        assertEquals(SimpleRestService.XML_RESPONSE, body);
    } catch (IOException e) {
        e.printStackTrace();
        fail("body was not set correctly");
    }
}

From source file:org.eclipse.ecf.tests.remoteservice.rest.service.RestServiceTest.java

public void testJsonResponse() {
    String serverUrl = service.getServerUrl();
    HttpClient client = new HttpClient();
    HttpMethod method = new HttpMethodBase(serverUrl + "/test.json") {
        public String getName() {
            return "GET";
        }/*  w ww . j  ava2  s .co m*/
    };
    int responseCode = 0;
    try {
        responseCode = client.executeMethod(method);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(HttpStatus.SC_OK, responseCode);
    try {
        String body = method.getResponseBodyAsString();
        assertEquals(SimpleRestService.JSON_RESPONSE, body);
    } catch (IOException e) {
        e.printStackTrace();
        fail("body was not set correctly");
    }
}

From source file:org.eclipse.ecf.tests.remoteservice.rest.service.RestServiceTest.java

public void testPost() {
    String serverUrl = service.getServerUrl();
    HttpClient client = new HttpClient();
    HttpMethod method = new HttpMethodBase(serverUrl + "/test.json") {
        public String getName() {
            return "POST";
        }// w ww  . jav  a 2s  .c  o  m
    };
    try {
        client.executeMethod(method);
    } catch (HttpException e) {
        e.printStackTrace();
        fail();
    } catch (IOException e) {
        assertTrue(e instanceof NoHttpResponseException);
    }
}