use of org.apache.commons.httpclient.HttpClient in project camel by apache.
the class HttpMethodRestrictTest method testImproperHttpMethod.
@Test
public void testImproperHttpMethod() throws Exception {
HttpClient httpClient = new HttpClient();
GetMethod httpGet = new GetMethod(getUrl());
int status = httpClient.executeMethod(httpGet);
assertEquals("Get a wrong response status", 405, status);
}
use of org.apache.commons.httpclient.HttpClient in project camel by apache.
the class HttpMethodRestrictTest method testProperHttpMethod.
@Test
public void testProperHttpMethod() throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod httpPost = new PostMethod(getUrl());
StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
httpPost.setRequestEntity(reqEntity);
int status = httpClient.executeMethod(httpPost);
assertEquals("Get a wrong response status", 200, status);
String result = httpPost.getResponseBodyAsString();
assertEquals("Get a wrong result", "This is a test response", result);
}
use of org.apache.commons.httpclient.HttpClient in project camel by apache.
the class HttpRouteTest method testPostParameter.
@Test
public void testPostParameter() throws Exception {
NameValuePair[] data = { new NameValuePair("request", "PostParameter"), new NameValuePair("others", "bloggs") };
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter");
post.setRequestBody(data);
client.executeMethod(post);
InputStream response = post.getResponseBodyAsStream();
String out = context.getTypeConverter().convertTo(String.class, response);
assertEquals("Get a wrong output ", "PostParameter", out);
}
use of org.apache.commons.httpclient.HttpClient in project camel by apache.
the class HttpRouteTest method testPostParameterInURI.
@Test
public void testPostParameterInURI() throws Exception {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter?request=PostParameter&others=bloggs");
StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8");
post.setRequestEntity(entity);
client.executeMethod(post);
InputStream response = post.getResponseBodyAsStream();
String out = context.getTypeConverter().convertTo(String.class, response);
assertEquals("Get a wrong output ", "PostParameter", out);
}
use of org.apache.commons.httpclient.HttpClient in project camel by apache.
the class HttpRouteTest method testPutParameterInURI.
@Test
public void testPutParameterInURI() throws Exception {
HttpClient client = new HttpClient();
PutMethod put = new PutMethod("http://localhost:" + port1 + "/parameter?request=PutParameter&others=bloggs");
StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8");
put.setRequestEntity(entity);
client.executeMethod(put);
InputStream response = put.getResponseBodyAsStream();
String out = context.getTypeConverter().convertTo(String.class, response);
assertEquals("Get a wrong output ", "PutParameter", out);
}
Aggregations