use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestMethodCharEncoding method testLatinAccentInRequestBody.
public void testLatinAccentInRequestBody() throws IOException {
PostMethod httppost = new PostMethod("/");
String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
// Test default encoding ISO-8859-1
httppost.setRequestEntity(new StringRequestEntity(s, "text/plain", CHARSET_DEFAULT));
verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_ISO8859_1);
// Test UTF-8 encoding
httppost.setRequestEntity(new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_UTF8);
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestMethodCharEncoding method testRussianInRequestBody.
public void testRussianInRequestBody() throws IOException {
PostMethod httppost = new PostMethod("/");
String s = constructString(RUSSIAN_STUFF_UNICODE);
// Test UTF-8 encoding
httppost.setRequestEntity(new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_UTF8);
// Test KOI8-R
httppost.setRequestEntity(new StringRequestEntity(s, "text/plain", CHARSET_KOI8_R));
verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_KOI8R);
// Test WIN1251
httppost.setRequestEntity(new StringRequestEntity(s, "text/plain", CHARSET_WIN1251));
verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_WIN1251);
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestMethodCharEncoding method testRequestEntityLength.
public void testRequestEntityLength() throws IOException {
String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
RequestEntity requestentity = new StringRequestEntity(s, "text/plain", CHARSET_UTF8);
assertEquals(s.getBytes(CHARSET_UTF8).length, requestentity.getContentLength());
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestConnectionPersistence method testConnClose.
public void testConnClose() throws Exception {
this.server.setHttpService(new EchoService());
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.getParams().setVersion(HttpVersion.HTTP_1_1);
this.client.setHttpConnectionManager(connman);
PostMethod httppost = new PostMethod("/test/");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertTrue(connman.getConection().isOpen());
httppost = new PostMethod("/test/");
httppost.setRequestHeader("Connection", "close");
httppost.setRequestEntity(new StringRequestEntity("more stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestConnectionPersistence method testRequestConnClose.
public void testRequestConnClose() throws Exception {
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
// Make sure the request if fully consumed
request.getBodyBytes();
SimpleResponse response = new SimpleResponse();
response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
response.setBodyString("stuff back");
conn.setKeepAlive(true);
conn.writeResponse(response);
return true;
}
});
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
this.client.setHttpConnectionManager(connman);
PostMethod httppost = new PostMethod("/test/");
httppost.setRequestHeader("Connection", "close");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
}
Aggregations