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.route.RouteMapping.java

License:Apache License

public RouteMapping() {
    super();//w  w  w.  j av  a 2 s . c  om
    routes = new HashMap<HttpMethod, List<Route>>();
    routes.put(HttpMethod.DELETE, deleteRoutes);
    routes.put(HttpMethod.GET, getRoutes);
    routes.put(HttpMethod.POST, postRoutes);
    routes.put(HttpMethod.PUT, putRoutes);
    routes.put(HttpMethod.HEAD, headRoutes);
    routes.put(HttpMethod.OPTIONS, optionRoutes);
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldResolvePostRoute() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/foo.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    Action action = resolver.resolve(request);
    assertNotNull(action);//  w  w  w  . j a  v a 2 s .c o  m
    assertEquals(HttpMethod.POST, action.getRoute().getMethod());
    assertEquals("/foo", action.getRoute().getPattern());
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldResolveAliasFooPostRoute() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/yada/yada.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    Action action = resolver.resolve(request);
    assertNotNull(action);/*from   w w  w.  ja  v  a2  s. c  om*/
    assertEquals(HttpMethod.POST, action.getRoute().getMethod());
    assertEquals("/foo", action.getRoute().getPattern());
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldResolveCrudRouteForPost() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/foo/foo23.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    Action action = resolver.resolve(request);
    assertNotNull(action);/*from w ww  . j a  va 2  s  . c  om*/
    assertEquals(HttpMethod.POST, action.getRoute().getMethod());
    assertEquals("/foo/{fooId}", action.getRoute().getPattern());
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldResolveAliasCrudRouteForPost() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "/blah/foo/foo23.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    Action action = resolver.resolve(request);
    assertNotNull(action);/*  w  w w  . j  a  v  a 2s  .c  o  m*/
    assertEquals(HttpMethod.POST, action.getRoute().getMethod());
    assertEquals("/foo/{fooId}", action.getRoute().getPattern());
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldSendAllowedMethodsForCrudRoute() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS,
            "/foo/foo23.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    try {//from w  w w.  j  a  v  a2  s  .  c o  m
        resolver.resolve(request);
    } catch (MethodNotAllowedException e) {
        List<HttpMethod> allowed = e.getAllowedMethods();
        assertEquals(4, allowed.size());
        assertTrue(allowed.contains(HttpMethod.GET));
        assertTrue(allowed.contains(HttpMethod.PUT));
        assertTrue(allowed.contains(HttpMethod.POST));
        assertTrue(allowed.contains(HttpMethod.DELETE));
    }
}

From source file:org.restexpress.route.RouteResolverTest.java

License:Apache License

@Test
public void shouldSendAllowedMethodsForPostRoute() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS,
            "/foo.json?value=ignored");
    httpRequest.headers().add("Host", "testing-host");
    Request request = new Request(httpRequest, null);
    try {// w  w  w .j  av  a 2s .c  om
        resolver.resolve(request);
    } catch (MethodNotAllowedException e) {
        List<HttpMethod> allowed = e.getAllowedMethods();
        assertEquals(1, allowed.size());
        assertTrue(allowed.contains(HttpMethod.POST));
    }
}

From source file:org.sp.tests.util.TestUtil.java

License:Open Source License

public static HTTPResponse sendHRequest(String body, URI baseURI, String path, String contentType,
        String methodType, String userName, String password) throws IOException {

    HttpURLConnection urlConn = null;
    try {// ww  w .ja  va  2s .  c  o m
        urlConn = TestUtil.generateRequest(baseURI, path, methodType, false);

        TestUtil.setHeader(urlConn, "Authorization", "Basic "
                + java.util.Base64.getEncoder().encodeToString((userName + ":" + password).getBytes()));
        if (contentType != null) {
            TestUtil.setHeader(urlConn, "Content-Type", contentType);
        }
        TestUtil.setHeader(urlConn, "HTTP_METHOD", methodType);
        if (methodType.equals(HttpMethod.POST.name()) || methodType.equals(HttpMethod.PUT.name())) {
            TestUtil.writeContent(urlConn, body);
        }
        assert urlConn != null;

        HTTPResponse httpResponseMessage = new HTTPResponse(urlConn.getResponseCode(), urlConn.getContentType(),
                TestUtil.getResponseMessage(urlConn));
        urlConn.disconnect();
        return httpResponseMessage;
    } catch (IOException e) {
        throw new IOException("Error generating request to " + baseURI + path, e);
    }
}

From source file:org.sp.tests.util.TestUtil.java

License:Open Source License

private static HttpURLConnection generateRequest(URI baseURI, String path, String method, boolean keepAlive)
        throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    urlConn.setRequestMethod(method);/*from ww  w. j  av a 2  s . co  m*/
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);
    }
    if (keepAlive) {
        urlConn.setRequestProperty("Connection", "Keep-Alive");
    }
    return urlConn;
}

From source file:org.vertx.java.core.http.impl.DefaultHttpServerRequest.java

License:Open Source License

@Override
public HttpServerRequest expectMultiPart(boolean expect) {
    if (expect) {
        String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE);
        if (contentType != null) {
            HttpMethod method = request.getMethod();
            String lowerCaseContentType = contentType.toLowerCase();
            isURLEncoded = lowerCaseContentType
                    .startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
            if ((lowerCaseContentType.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA) || isURLEncoded)
                    && (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)
                            || method.equals(HttpMethod.PATCH))) {
                decoder = new HttpPostRequestDecoder(new DataFactory(), request);
            }/* ww w  . j a va2 s.co m*/
        }
    } else {
        decoder = null;
    }
    return this;
}