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

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

Introduction

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

Prototype

HttpMethod PUT

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

Click Source Link

Document

The PUT method requests that the enclosed entity be stored under the supplied Request-URI.

Usage

From source file:org.restexpress.Request.java

License:Apache License

public boolean isMethodPut() {
    return getEffectiveHttpMethod().equals(HttpMethod.PUT);
}

From source file:org.restexpress.RequestTest.java

License:Apache License

@Test
public void shouldBePutRequest() {
    Request putRequest = new Request(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/foo"),
            null);//from   w w  w . j  av  a 2s . c  o  m
    assertEquals(HttpMethod.PUT, putRequest.getHttpMethod());
    assertEquals(HttpMethod.PUT, putRequest.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.route.RouteMapping.java

License:Apache License

public RouteMapping() {
    super();/*from   www .  ja v a  2s .  c o  m*/
    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 shouldResolveCrudRouteForPut() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
            "/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 ww .  j av  a 2  s  .c o  m*/
    assertEquals(HttpMethod.PUT, action.getRoute().getMethod());
    assertEquals("/foo/{fooId}", action.getRoute().getPattern());
}

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

License:Apache License

@Test
public void shouldResolveAliasCrudRouteForPut() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
            "/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);/*from   w ww. jav a2s.  c  o m*/
    assertEquals(HttpMethod.PUT, 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 ww .  j ava2  s. co  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.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 {/*  w w  w  .java2  s .co 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);//  w ww .j  av  a  2s .c o 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.thingsplode.synapse.proxy.handlers.Request2HttpRequestEncoder.java

License:Apache License

private HttpRequest convert(Request request) throws SerializationException {
    if (request == null || request.getHeader() == null) {
        return null;
    }//from w w w . ja v  a 2  s. com
    HttpMethod m = null;
    if (request.getHeader().getMethod() != null) {
        m = HttpMethod.valueOf(request.getHeader().getMethod().toString());
    } else if (request.getHeader().getUri() != null && !Util.isEmpty(request.getHeader().getUri().getQuery())) {
        m = HttpMethod.GET;
    } else if (request.getBody() != null) {
        m = HttpMethod.PUT;
    } else {
        m = HttpMethod.GET;
    }
    final HttpRequest out;
    if (request.getBody() != null) {
        Optional<String> contentTypeOpt = request.getRequestHeaderProperty(HttpHeaderNames.ACCEPT.toString());
        MediaType mt = contentTypeOpt.isPresent() ? new MediaType(contentTypeOpt.get())
                : new MediaType(MediaType.APPLICATION_JSON_CT);
        request.getHeader().addProperty(AbstractMessage.PROP_BODY_TYPE,
                request.getBody().getClass().getCanonicalName());
        byte[] payload = EndpointProxy.SERIALIZATION_SERVICE.getSerializer(mt).marshall(request.getBody());
        out = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, m, request.getHeader().getUri().getPath(),
                Unpooled.wrappedBuffer(payload));
        out.headers().add(HttpHeaderNames.CONTENT_LENGTH, payload.length);
    } else {
        out = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, m, request.getHeader().getUri().getPath());
    }
    if (request.getHeader().isKeepalive()) {
        out.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }

    if (request.getHeader() != null && request.getHeader().getProperties() != null) {
        request.getHeader().getProperties().forEach((k, v) -> {
            out.headers().set(new AsciiString(k), new AsciiString(v != null ? v : ""));
        });
    }
    return out;
}