Example usage for io.netty.handler.codec.http HttpMethod POST

List of usage examples for io.netty.handler.codec.http HttpMethod POST

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod POST.

Prototype

HttpMethod POST

To view the source code for io.netty.handler.codec.http HttpMethod POST.

Click Source Link

Document

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.

Usage

From source file:org.restexpress.pipeline.RawWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapPostInRawJsonUsingQueryString() {
    sendEvent(HttpMethod.POST, "/normal_post?format=json", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("\"Normal POST action\"", httpResponse.toString());
}

From source file:org.restexpress.pipeline.RawWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapPostInRawXml() {
    sendEvent(HttpMethod.POST, "/normal_post.xml", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("<string>Normal POST action</string>", httpResponse.toString());
}

From source file:org.restexpress.pipeline.RawWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapPostInRawXmlUsingQueryString() {
    sendEvent(HttpMethod.POST, "/normal_post?format=xml", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("<string>Normal POST action</string>", httpResponse.toString());
}

From source file:org.restexpress.Request.java

License:Apache License

public boolean isMethodPost() {
    return getEffectiveHttpMethod().equals(HttpMethod.POST);
}

From source file:org.restexpress.Request.java

License:Apache License

/**
 * If the request HTTP method is post, allow a query string parameter to determine
 * the request HTTP method of the post (e.g. _method=DELETE or _method=PUT).  This
 * supports DELETE and PUT from the browser.
 *///w ww .  ja va2  s  .  co m
private void determineEffectiveHttpMethod(HttpRequest request) {
    if (!HttpMethod.POST.equals(request.getMethod()))
        return;

    String methodString = request.headers().get(Parameters.Query.METHOD_TUNNEL);

    if ("PUT".equalsIgnoreCase(methodString) || "DELETE".equalsIgnoreCase(methodString)) {
        effectiveHttpMethod = HttpMethod.valueOf(methodString.toUpperCase());
    }
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldBePostRequest() {
    Request postRequest = new Request(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/foo"),
            null);/*from ww w  .  j ava 2  s .c  o  m*/
    assertEquals(HttpMethod.POST, postRequest.getHttpMethod());
    assertEquals(HttpMethod.POST, postRequest.getEffectiveHttpMethod());
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldBeEffectivePutRequest() {
    Request putRequest = new Request(
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/foo?_method=pUt"), null);
    assertEquals(HttpMethod.POST, putRequest.getHttpMethod());
    assertEquals(HttpMethod.PUT, putRequest.getEffectiveHttpMethod());
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldBeEffectiveDeleteRequest() {
    Request deleteRequest = new Request(
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/foo?_method=DeLeTe"), null);
    assertEquals(HttpMethod.POST, deleteRequest.getHttpMethod());
    assertEquals(HttpMethod.DELETE, deleteRequest.getEffectiveHttpMethod());
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldBeEffectivePostRequest() {
    Request deleteRequest = new Request(
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/foo?_method=xyzt"), null);
    assertEquals(HttpMethod.POST, deleteRequest.getHttpMethod());
    assertEquals(HttpMethod.POST, deleteRequest.getEffectiveHttpMethod());
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldParseUrlFormEncodedBody() throws Exception {
    String formValue1 = "http://login.berlin.ecollege-labs.com/google-service/google/sso/callback/google.JSON?successUrl=http%3A%2F%2Fdashboard.berlin.ecollege-labs.com%2Ftransfer.html&failureUrl=http%3A%2F%2Flogin.berlin.ecollege-labs.com&domain=GOOGLE_NON_MARKET_PLACE_DOMAIN";
    String formValue2 = "https://www.google.com/accounts/o8/id?id=AItOawkHDpeMEfe_xM14z_ge7UATYOSg_QlPeDg";
    String formValue3 = "https://www.google.com/accounts/o8/id?id=AItOawkHDpeMEfe_xM14z_ge7UATYOSg_QlPeDg";
    DefaultFullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/foo?_method=xyzt",
            Unpooled.wrappedBuffer(("openid.return_to=" + URLEncoder.encode(formValue1, ContentType.ENCODING)
                    + "&openid.identity=" + URLEncoder.encode(formValue2, ContentType.ENCODING)
                    + "&openid.claimed_id=" + URLEncoder.encode(formValue3, ContentType.ENCODING)).getBytes()));
    Request formPost = new Request(httpRequest, null);
    Map<String, List<String>> form = formPost.getBodyFromUrlFormEncoded();
    assertEquals(3, form.size());//  w w w .j a va 2 s  .  c om
    assertNotNull(form.get("openid.return_to"));
    assertNotNull(form.get("openid.identity"));
    assertNotNull(form.get("openid.claimed_id"));
    assertEquals(formValue1, form.get("openid.return_to").get(0));
    assertEquals(formValue2, form.get("openid.identity").get(0));
    assertEquals(formValue3, form.get("openid.claimed_id").get(0));
}