本文整理匯總了Java中io.vertx.core.http.HttpClientOptions.setSsl方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientOptions.setSsl方法的具體用法?Java HttpClientOptions.setSsl怎麽用?Java HttpClientOptions.setSsl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.http.HttpClientOptions
的用法示例。
在下文中一共展示了HttpClientOptions.setSsl方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hello3
import io.vertx.core.http.HttpClientOptions; //導入方法依賴的package包/類
@Path("3")
@GET
public void hello3(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
System.err.println("Creating client");
HttpClientOptions options = new HttpClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
HttpClient client = vertx.createHttpClient(options);
client.getNow(443,
"www.google.com",
"/robots.txt",
resp -> {
System.err.println("Got response");
resp.bodyHandler(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.toString()).build());
});
});
System.err.println("Created client");
}
示例2: hello4
import io.vertx.core.http.HttpClientOptions; //導入方法依賴的package包/類
@Path("4")
@GET
public void hello4(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
System.err.println("Creating client");
HttpClientOptions options = new HttpClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
HttpClient client = vertx.createHttpClient(options);
ObservableHandler<HttpClientResponse> responseHandler = RxHelper.observableHandler();
client.getNow(443,
"www.google.com",
"/robots.txt",
responseHandler.toHandler());
ObservableHandler<Buffer> bodyHandler = RxHelper.observableHandler();
responseHandler.subscribe(resp -> {
System.err.println("Got response");
resp.bodyHandler(bodyHandler.toHandler());
});
bodyHandler.subscribe(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.toString()).build());
});
System.err.println("Created client");
}
示例3: hello5
import io.vertx.core.http.HttpClientOptions; //導入方法依賴的package包/類
@Path("5")
@GET
public void hello5(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
HttpClientOptions options = new HttpClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
io.vertx.rxjava.core.http.HttpClient client = rxVertx.createHttpClient(options);
// DOES NOT WORK: https://github.com/vert-x3/vertx-rx/issues/13
Observable<io.vertx.rxjava.core.http.HttpClientResponse> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").toObservable();
responseHandler.map(resp -> {
System.err.println("Got response");
return resp.toObservable();
})
.subscribe(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.toString()).build());
});
System.err.println("Created client");
}
示例4: AbstractMeshRestHttpClient
import io.vertx.core.http.HttpClientOptions; //導入方法依賴的package包/類
public AbstractMeshRestHttpClient(String host, int port, boolean ssl, Vertx vertx) {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultHost(host);
options.setTryUseCompression(true);
options.setDefaultPort(port);
options.setSsl(ssl);
this.clientOptions = options;
this.vertx = vertx;
}
示例5: doDownload
import io.vertx.core.http.HttpClientOptions; //導入方法依賴的package包/類
/**
* Download a file
* @param downloadUrl the URL to download from
* @param dest the destination file
* @return a single emitting exactly one item once the file has been
* downloaded
*/
private Single<Void> doDownload(String downloadUrl, AsyncFile dest) {
ObservableFuture<Void> observable = RxHelper.observableFuture();
Handler<AsyncResult<Void>> handler = observable.toHandler();
HttpClientOptions options = new HttpClientOptions();
if (downloadUrl.startsWith("https")) {
options.setSsl(true);
}
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest req = client.getAbs(downloadUrl);
req.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
req.handler(res -> {
if (res.statusCode() != 200) {
handler.handle(Future.failedFuture(new HttpException(res.statusCode(),
res.statusMessage())));
return;
}
// get content-length
int length;
int[] read = { 0 };
int[] lastOutput = { 0 };
String contentLength = res.getHeader("Content-Length");
if (contentLength != null) {
length = Integer.parseInt(contentLength);
} else {
length = 0;
}
res.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
// download file contents, log progress
res.handler(buf -> {
read[0] += buf.length();
if (lastOutput[0] == 0 || read[0] - lastOutput[0] > 1024 * 2048) {
logProgress(length, read[0]);
lastOutput[0] = read[0];
}
dest.write(buf);
});
res.endHandler(v -> {
logProgress(length, read[0]);
handler.handle(Future.succeededFuture());
});
});
req.end();
return observable.toSingle();
}