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.URLRewriterTest.java

License:Open Source License

@Test
public void testUrlRewrite() throws Exception {
    int status = doGet("/rewrite/test/v1/resource");
    Assert.assertEquals(HttpResponseStatus.OK.code(), status);

    HttpURLConnection urlConn = request("/rewrite/test/v1/tweets/7648", HttpMethod.PUT);
    Assert.assertEquals(HttpResponseStatus.OK.code(), urlConn.getResponseCode());
    Map<String, String> stringMap = GSON.fromJson(getContent(urlConn), new TypeToken<Map<String, String>>() {
    }.getType());//from w  w  w . j a  v  a 2s  .c  o m
    Assert.assertEquals(ImmutableMap.of("status", "Handled put in tweets end-point, id: 7648"), stringMap);

    urlConn.disconnect();
}

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

License:Open Source License

private HttpURLConnection request(String path, HttpMethod method) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method == HttpMethod.POST || method == HttpMethod.PUT) {
        urlConn.setDoOutput(true);//from   ww  w  .  j a va  2  s  . c  o  m
    }
    urlConn.setRequestMethod(method.name());

    return urlConn;
}

From source file:org.wso2.carbon.transport.http.netty.util.TestUtil.java

License:Open Source License

public static HttpURLConnection request(URI baseURI, String path, String method, boolean keepAlive)
        throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);/*from  w  w w. ja  v  a2  s.  co  m*/
    }
    urlConn.setRequestMethod(method);
    if (!keepAlive) {
        urlConn.setRequestProperty("Connection", "Keep-Alive");
    }

    return urlConn;
}

From source file:org.wso2.extension.siddhi.io.http.source.util.HttpServerUtil.java

License:Open Source License

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

From source file:org.wso2.extension.siddhi.map.text.sourcemapper.util.HttpServerUtil.java

License:Open Source License

static HttpURLConnection request(URI baseURI, String path, String method) throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);//  www  .  ja  va 2  s.  co  m
    }
    urlConn.setRequestMethod(method);
    return urlConn;
}

From source file:org.wso2.extension.siddhi.store.rdbms.test.osgi.util.TestUtil.java

License:Open Source License

public static HTTPResponseMessage sendHRequest(String body, URI baseURI, String path, String contentType,
        String methodType, Boolean auth, String userName, String password) {
    try {/*from   w w  w.  ja  v  a  2s  .  c  om*/
        HttpURLConnection urlConn = null;
        try {
            urlConn = TestUtil.generateRequest(baseURI, path, methodType, false);
        } catch (IOException e) {
            TestUtil.handleException("IOException occurred while running the HttpsSourceTestCaseForSSL", e);
        }
        if (auth) {
            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;
        HTTPResponseMessage httpResponseMessage = new HTTPResponseMessage(urlConn.getResponseCode(),
                urlConn.getContentType(), urlConn.getResponseMessage());
        urlConn.disconnect();
        return httpResponseMessage;
    } catch (IOException e) {
        TestUtil.handleException("IOException occurred while running the HttpsSourceTestCaseForSSL", e);
    }
    return new HTTPResponseMessage();
}

From source file:org.wso2.siddhi.extension.input.transport.http.Util.ServerUtil.java

License:Open Source License

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

From source file:ozy.client.PutTenant.java

License:Open Source License

public PutTenant(String scheme, String host, int port, String instanceId, String tenantId) {
    super(HttpMethod.PUT, scheme, host, port);
    if (instanceId == null)
        throw new NullPointerException("instanceId");
    if (tenantId == null)
        throw new NullPointerException("tenantId");
    _instanceId = instanceId;/*from  w w  w .  j a  v a 2  s .  c  o m*/
    _tenantId = tenantId;
    setParams(testParams());
    _bodyObject = new JSONObject();
    JSONObject adminObject = new JSONObject();
    _bodyObject.put("admin", adminObject);
    adminObject.put("userId", "admin");
    adminObject.put("secret", "c68a52015f4640a99f7465072b3ba6cb");
}

From source file:reactor.ipc.netty.http.client.HttpClient.java

License:Open Source License

/**
 * HTTP PUT the passed URL. When connection has been made, the passed handler is
 * invoked and can be used to build precisely the request and write data to it.
 *
 * @param url the target remote URL//  w  ww .  ja  v  a  2  s . com
 * @param handler the {@link Function} to invoke on open channel
 *
 * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for
 * response
 */
public final Mono<HttpClientResponse> put(String url,
        Function<? super HttpClientRequest, ? extends Publisher<Void>> handler) {
    return request(HttpMethod.PUT, url, handler);
}

From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java

License:Open Source License

/**
 * @param factory the factory used to create InterfaceHttpData
 * @param request the request to encode/* w  ww .  j  av a2  s .  c  o m*/
 * @param multipart True if the FORM is a ENCTYPE="multipart/form-data"
 * @param charset the charset to use as default
 * @param encoderMode the mode for the encoder to use. See {@link EncoderMode} for the
 * details.
 *
 * @throws NullPointerException      for request or charset or factory
 * @throws ErrorDataEncoderException if the request is not a POST
 */
HttpClientFormEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset,
        EncoderMode encoderMode) throws ErrorDataEncoderException {
    if (factory == null) {
        throw new NullPointerException("factory");
    }
    if (request == null) {
        throw new NullPointerException("request");
    }
    if (charset == null) {
        throw new NullPointerException("charset");
    }
    HttpMethod method = request.method();
    if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)
            || method.equals(HttpMethod.OPTIONS))) {
        throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST");
    }
    this.request = request;
    this.charset = charset;
    this.newCharset = charset;
    this.factory = factory;
    this.progressFlux = DirectProcessor.create();
    this.cleanOnTerminate = true;
    this.newMode = encoderMode;
    this.newMultipart = multipart;

    // Fill default values
    bodyListDatas = new ArrayList<>();
    // default mode
    isLastChunk = false;
    isLastChunkSent = false;
    isMultipart = multipart;
    multipartHttpDatas = new ArrayList<>();
    this.encoderMode = encoderMode;
    if (isMultipart) {
        initDataMultipart();
    }
}