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.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testChunkAggregatedUpload() throws IOException {
    //create a random file to be uploaded.
    int size = 69 * 1024;
    File fname = tmpFolder.newFile();
    RandomAccessFile randf = new RandomAccessFile(fname, "rw");
    randf.setLength(size);//  w w  w .j  a  v a  2s  .c o m
    randf.close();

    //test chunked upload
    HttpURLConnection urlConn = request("/test/v1/aggregate/upload", HttpMethod.PUT);
    urlConn.setChunkedStreamingMode(1024);
    Files.copy(fname, urlConn.getOutputStream());
    Assert.assertEquals(200, urlConn.getResponseCode());

    Assert.assertEquals(size, Integer.parseInt(getContent(urlConn).split(":")[1].trim()));
    urlConn.disconnect();
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

public void testChunkAggregatedUploadFailure() throws IOException {
    //create a random file to be uploaded.
    int size = 78 * 1024;
    File fname = tmpFolder.newFile();
    RandomAccessFile randf = new RandomAccessFile(fname, "rw");
    randf.setLength(size);/*w  w  w . j  a v a2s  .c  o m*/
    randf.close();

    //test chunked upload
    HttpURLConnection urlConn = request("/test/v1/aggregate/upload", HttpMethod.PUT);
    urlConn.setChunkedStreamingMode(1024);
    Files.copy(fname, urlConn.getOutputStream());
    Assert.assertEquals(500, urlConn.getResponseCode());
    urlConn.disconnect();
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testPathWithMultipleMethods() throws IOException {
    HttpURLConnection urlConn = request("/test/v1/tweets/1", HttpMethod.GET);
    Assert.assertEquals(200, urlConn.getResponseCode());
    urlConn.disconnect();/*from   w w  w.ja v  a 2 s.c o  m*/

    urlConn = request("/test/v1/tweets/1", HttpMethod.PUT);
    writeContent(urlConn, "data");
    Assert.assertEquals(200, urlConn.getResponseCode());
    urlConn.disconnect();
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testPutWithData() throws IOException {
    HttpURLConnection urlConn = request("/test/v1/facebook/1/message", HttpMethod.PUT);
    writeContent(urlConn, "Hello, World");
    Assert.assertEquals(200, urlConn.getResponseCode());

    String content = getContent(urlConn);

    Map<String, String> map = GSON.fromJson(content, STRING_MAP_TYPE);
    Assert.assertEquals(1, map.size());/*from  w  w  w  .  j  a  v  a 2 s . co m*/
    Assert.assertEquals("Handled put in tweets end-point, id: 1. Content: Hello, World", map.get("result"));
    urlConn.disconnect();
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testKeepAlive() throws IOException {
    HttpURLConnection urlConn = request("/test/v1/tweets/1", HttpMethod.PUT, true);
    writeContent(urlConn, "data");
    Assert.assertEquals(200, urlConn.getResponseCode());

    Assert.assertEquals("keep-alive", urlConn.getHeaderField(HttpHeaders.Names.CONNECTION));
    urlConn.disconnect();//from  w w  w .j  a v  a2  s  .  c o  m
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testMultiMatchParamPut() throws Exception {
    HttpURLConnection urlConn = request("/test/v1/multi-match/bar", HttpMethod.PUT);
    Assert.assertEquals(405, urlConn.getResponseCode());
    urlConn.disconnect();//from   www .  j a va2  s  . c o  m
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testMultiMatchFooPut() throws Exception {
    testContent("/test/v1/multi-match/foo", "multi-match-put-actual-foo", HttpMethod.PUT);
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

@Test
public void testNoPathPutMethod() throws Exception {
    HttpURLConnection urlConn = request("/test/v1", HttpMethod.PUT);
    Assert.assertEquals("no-@Path-PUT", getContent(urlConn));
    urlConn.disconnect();/*from   w w  w .j  a  v a 2 s  .  co m*/
}

From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java

License:Open Source License

protected HttpURLConnection request(String path, HttpMethod method, boolean keepAlive) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method == HttpMethod.POST || method == HttpMethod.PUT) {
        urlConn.setDoOutput(true);/*  w  w  w  .j  a v a  2 s.c  om*/
    }
    urlConn.setRequestMethod(method.name());
    if (!keepAlive) {
        urlConn.setRequestProperty(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
    }

    return urlConn;
}

From source file:org.wso2.carbon.mss.internal.router.HttpsServerTest.java

License:Open Source License

@Override
protected HttpURLConnection request(String path, HttpMethod method, boolean keepAlive) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getClientContext().getSocketFactory());
    HostnameVerifier allHostsValid = (hostname1, session) -> true;

    // Install the all-trusting host verifier
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
    HttpURLConnection urlConn = (HttpsURLConnection) url.openConnection();
    if (method == HttpMethod.POST || method == HttpMethod.PUT) {
        urlConn.setDoOutput(true);/*  w  ww. j  a v  a 2  s. c  om*/
    }
    urlConn.setRequestMethod(method.name());
    if (!keepAlive) {
        urlConn.setRequestProperty(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
    }
    return urlConn;
}