Search in sources :

Example 86 with StringRequestEntity

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);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 87 with StringRequestEntity

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);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 88 with StringRequestEntity

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());
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity)

Example 89 with StringRequestEntity

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());
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 90 with StringRequestEntity

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());
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) SimpleResponse(org.apache.commons.httpclient.server.SimpleResponse) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Aggregations

StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)102 PostMethod (org.apache.commons.httpclient.methods.PostMethod)63 HttpClient (org.apache.commons.httpclient.HttpClient)33 Test (org.junit.Test)23 PutMethod (org.apache.commons.httpclient.methods.PutMethod)19 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)18 IOException (java.io.IOException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 AuthRequestHandler (org.apache.commons.httpclient.server.AuthRequestHandler)12 HttpRequestHandlerChain (org.apache.commons.httpclient.server.HttpRequestHandlerChain)12 HttpServiceHandler (org.apache.commons.httpclient.server.HttpServiceHandler)12 Header (org.apache.commons.httpclient.Header)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)9 InputStream (java.io.InputStream)8 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 StringWriter (java.io.StringWriter)6 Map (java.util.Map)6 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)6 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)6