本文整理了Java中io.vertx.core.http.HttpClient.put()
方法的一些代码示例,展示了HttpClient.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.put()
方法的具体详情如下:
包路径:io.vertx.core.http.HttpClient
类名称:HttpClient
方法名:put
[英]Create an HTTP PUT request to send to the server at the specified host and port.
[中]创建HTTP PUT请求以发送到指定主机和端口的服务器。
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
});
request.setChunked(true);
for (int i = 0; i < 10; i++) {
request.write("client-chunk-" + i);
}
request.end();
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClientRequest req = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/someurl", resp -> {
System.out.println("Response " + resp.statusCode());
});
String filename = "upload.txt";
FileSystem fs = vertx.fileSystem();
fs.props(filename, ares -> {
FileProps props = ares.result();
System.out.println("props is " + props);
long size = props.size();
req.headers().set("content-length", "" + size);
fs.open(filename, new OpenOptions(), ares2 -> {
AsyncFile file = ares2.result();
Pump pump = Pump.pump(file, req);
file.endHandler(v -> {
req.end();
});
pump.start();
});
});
}
}
代码示例来源:origin: eclipse-vertx/vert.x
}).listen(DEFAULT_HTTP_PORT, ar -> {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somerui", handler -> {
代码示例来源:origin: eclipse-vertx/vert.x
HttpClient client = vertx.createHttpClient();
checker.accept(expectedThread.get(), expectedContext.get());
HttpClientRequest req = client.put(8080, "localhost", "/");
req.handler(resp -> {
executeInVanillaThread(() -> {
代码示例来源:origin: eclipse-vertx/vert.x
});
startServer();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTPS_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
resp.endHandler(v -> {
testComplete();
代码示例来源:origin: eclipse-vertx/vert.x
awaitLatch(latch);
HttpClient client = vertx.createHttpClient();
client.put(8080, "localhost", "/", onSuccess(resp -> {
resp.netSocket().closeHandler(v -> {
vertx.close(v4 -> {
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions()
.setSsl(true)
.setTrustAll(true)
.setVerifyHost(false)
.setProxyOptions(new ProxyOptions()
.setType(ProxyType.HTTP)
.setHost("localhost")
.setPort(8080)))
.put(8282, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
});
request.setChunked(true);
for (int i = 0; i < 10; i++) {
request.write("client-chunk-" + i);
}
request.end();
}
}
代码示例来源:origin: eclipse-vertx/vert.x
startServer();
AtomicBoolean called = new AtomicBoolean();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", ar -> {
assertEquals(expectFail, ar.failed());
if (ar.succeeded()) {
代码示例来源:origin: eclipse-vertx/vert.x
private void testFollowRedirectWithBody(Function<Buffer, Buffer> translator) throws Exception {
Buffer expected = TestUtils.randomBuffer(2048);
AtomicBoolean redirected = new AtomicBoolean();
server.requestHandler(req -> {
if (redirected.compareAndSet(false, true)) {
assertEquals(HttpMethod.PUT, req.method());
req.bodyHandler(body -> {
assertEquals(body, expected);
String scheme = createBaseServerOptions().isSsl() ? "https" : "http";
req.response().setStatusCode(303).putHeader(HttpHeaders.LOCATION, scheme + "://localhost:8080/whatever").end();
});
} else {
assertEquals(HttpMethod.GET, req.method());
req.response().end();
}
});
startServer();
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
})).setFollowRedirects(true).end(translator.apply(expected));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testChunkedClientRequest() {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
assertEquals("chunked", req.getHeader("transfer-encoding"));
req.bodyHandler(body -> {
assertEquals("the-chunk", body.toString());
req.response().end();
});
}).listen(onSuccess(server -> {
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", res -> {
testComplete();
});
req.setChunked(true);
req.write("the-chunk");
vertx.setTimer(1, id -> {
req.end();
});
}));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testHttpClientRequestShouldExceptionHandlerWhenTheClosedHandlerIsCalled() throws Exception {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
vertx.setTimer(1000, id -> {
req.response().close();
});
});
startServer();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/someuri", resp -> {
}).setChunked(true);
CountDownLatch latch = new CountDownLatch(1);
req.sendHead(version -> latch.countDown());
awaitLatch(latch);
CheckingSender sender = new CheckingSender(vertx.getOrCreateContext(), req);
req.exceptionHandler(err -> {
Throwable failure = sender.close();
if (failure != null) {
fail(failure);
} else {
testComplete();
}
});
sender.send();
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testPausedHttpServerRequestDuringLastChunkEndsTheRequest() throws Exception {
server.requestHandler(req -> {
req.handler(buff -> {
assertEquals("small", buff.toString());
req.pause();
});
req.endHandler(v -> {
req.response().end();
});
});
startServer();
client.close();
client = vertx.createHttpClient(createBaseClientOptions().setMaxPoolSize(1));
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", resp -> {
complete();
}).end("small");
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFollowRedirectSendHeadThenBody() throws Exception {
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(2048));
AtomicBoolean redirected = new AtomicBoolean();
server.requestHandler(req -> {
if (redirected.compareAndSet(false, true)) {
assertEquals(HttpMethod.PUT, req.method());
req.bodyHandler(body -> {
assertEquals(body, expected);
req.response().setStatusCode(303).putHeader(HttpHeaders.LOCATION, "/whatever").end();
});
} else {
assertEquals(HttpMethod.GET, req.method());
req.response().end();
}
});
startServer();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
})).setFollowRedirects(true);
req.putHeader("Content-Length", "" + expected.length());
req.exceptionHandler(this::fail);
req.sendHead(v -> {
req.end(expected);
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testPausedHttpServerRequestUnpauseTheConnectionAtRequestEnd() throws Exception {
int numRequests = 20;
waitFor(numRequests);
server.requestHandler(req -> {
req.handler(buff -> {
assertEquals("small", buff.toString());
req.pause();
});
req.endHandler(v -> {
req.response().end();
});
});
startServer();
client.close();
client = vertx.createHttpClient(createBaseClientOptions().setMaxPoolSize(1));
for (int i = 0; i < numRequests; i++) {
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", resp -> {
complete();
}).end("small");
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testEndServerRequestResumeTheConnection() throws Exception {
server.requestHandler(req -> {
req.response().end();
req.endHandler(v -> {
req.pause();
});
});
startServer();
client.close();
waitFor(2);
client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setMaxPoolSize(1));
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
assertEquals(200, resp.statusCode());
complete();
})).end("1");
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
assertEquals(200, resp.statusCode());
complete();
})).end("2");
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
assertTrue(Context.isOnWorkerThread());
HttpClient client = vertx.createHttpClient();
client.put(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/blah", onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertTrue(Vertx.currentContext().isWorkerContext());
代码示例来源:origin: io.vertx/vertx-core
private void testFollowRedirectWithBody(Function<Buffer, Buffer> translator) throws Exception {
Buffer expected = TestUtils.randomBuffer(2048);
AtomicBoolean redirected = new AtomicBoolean();
server.requestHandler(req -> {
if (redirected.compareAndSet(false, true)) {
assertEquals(HttpMethod.PUT, req.method());
req.bodyHandler(body -> {
assertEquals(body, expected);
String scheme = createBaseServerOptions().isSsl() ? "https" : "http";
req.response().setStatusCode(303).putHeader(HttpHeaders.LOCATION, scheme + "://localhost:8080/whatever").end();
});
} else {
assertEquals(HttpMethod.GET, req.method());
req.response().end();
}
});
startServer();
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}).setFollowRedirects(true).end(translator.apply(expected));
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testEndServerRequestResumeTheConnection() throws Exception {
server.requestHandler(req -> {
req.response().end();
req.endHandler(v -> {
req.pause();
});
});
startServer();
client.close();
waitFor(2);
client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setMaxPoolSize(1));
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
assertEquals(200, resp.statusCode());
complete();
}).end("1");
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
assertEquals(200, resp.statusCode());
complete();
}).end("2");
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testPausedHttpServerRequestDuringLastChunkEndsTheRequest() throws Exception {
server.requestHandler(req -> {
req.handler(buff -> {
assertEquals("small", buff.toString());
req.pause();
});
req.endHandler(v -> {
req.response().end();
});
});
startServer();
client.close();
client = vertx.createHttpClient(createBaseClientOptions().setMaxPoolSize(1));
client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", resp -> {
complete();
}).end("small");
await();
}
内容来源于网络,如有侵权,请联系作者删除!