本文整理汇总了Java中io.vertx.ext.web.client.WebClient类的典型用法代码示例。如果您正苦于以下问题:Java WebClient类的具体用法?Java WebClient怎么用?Java WebClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebClient类属于io.vertx.ext.web.client包,在下文中一共展示了WebClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: prepare
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Before
public void prepare(TestContext context) {
vertx = Vertx.vertx();
JsonObject dbConf = new JsonObject()
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true")
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4);
vertx.deployVerticle(new WikiDatabaseVerticle(),
new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess());
vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess());
webClient = WebClient.create(vertx, new WebClientOptions()
.setDefaultHost("localhost")
.setDefaultPort(8080)
.setSsl(true)
.setTrustOptions(new JksOptions().setPath("server-keystore.jks").setPassword("secret")));
}
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:19,代码来源:ApiTest.java
示例2: prepare
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Before
public void prepare(TestContext context) {
vertx = Vertx.vertx();
JsonObject dbConf = new JsonObject()
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true")
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4);
vertx.deployVerticle(new WikiDatabaseVerticle(),
new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess());
vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess());
// tag::test-https[]
webClient = WebClient.create(vertx, new WebClientOptions()
.setDefaultHost("localhost")
.setDefaultPort(8080)
.setSsl(true) // <1>
.setTrustOptions(new JksOptions().setPath("server-keystore.jks").setPassword("secret"))); // <2>
// end::test-https[]
}
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:21,代码来源:ApiTest.java
示例3: prepare
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Before
public void prepare(TestContext context) {
vertx = Vertx.vertx();
JsonObject dbConf = new JsonObject()
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:mem:testdb;shutdown=true") // <1>
.put(WikiDatabaseVerticle.CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 4);
vertx.deployVerticle(new WikiDatabaseVerticle(),
new DeploymentOptions().setConfig(dbConf), context.asyncAssertSuccess());
vertx.deployVerticle(new HttpServerVerticle(), context.asyncAssertSuccess());
webClient = WebClient.create(vertx, new WebClientOptions()
.setDefaultHost("localhost")
.setDefaultPort(8080));
}
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:18,代码来源:ApiTest.java
示例4: initWebClient
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
private WebClient initWebClient() {
if (this.client == null) {
final WebClientOptions wco = new WebClientOptions();
final String proxyHost = this.getConsumerConfig().getProxy();
final int proxyPort = this.getConsumerConfig().getProxyPort();
if ((proxyHost != null) && (proxyPort > 0)) {
final ProxyOptions po = new ProxyOptions();
wco.setProxyOptions(po);
po.setHost(proxyHost).setPort(proxyPort);
}
// TODO: more options
wco.setUserAgent("SFDC VertX REST Provider");
wco.setTryUseCompression(true);
this.client = WebClient.create(this.vertx, wco);
}
return this.client;
}
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:18,代码来源:RestConsumer.java
示例5: login
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Override
protected void login(final Future<AuthInfo> futureAuthinfo) {
final WebClientOptions wco = new WebClientOptions();
final String proxyHost = this.getAuthConfig().getProxy();
final int proxyPort = this.getAuthConfig().getProxyPort();
if ((proxyHost != null) && (proxyPort > 0)) {
final ProxyOptions po = new ProxyOptions();
wco.setProxyOptions(po);
po.setHost(proxyHost).setPort(proxyPort);
}
wco.setUserAgent("SDFC VertX Authenticator");
wco.setTryUseCompression(true);
final WebClient authClient = WebClient.create(this.vertx, wco);
final Buffer body = this.getAuthBody(this.getAuthConfig().getSfdcUser(),
this.getAuthConfig().getSfdcPassword());
if (!this.shuttingDown && !this.shutdownCompleted) {
authClient.post(Constants.TLS_PORT, this.getAuthConfig().getServerURL(), Constants.AUTH_SOAP_LOGIN)
.putHeader("Content-Type", "text/xml").ssl(true).putHeader("SOAPAction", "Login")
.putHeader("PrettyPrint", "Yes").sendBuffer(body, postReturn -> {
this.resultOfAuthentication(postReturn, futureAuthinfo);
});
} else {
this.shutdownCompleted = true;
futureAuthinfo.fail("Auth disruped by stop command");
}
}
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:27,代码来源:SoapApi.java
示例6: testAPIListening
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testAPIListening(final TestContext context) {
final Async async = context.async();
final WebClientOptions wco = new WebClientOptions();
wco.setUserAgent("SDFC VertX Unit Tester");
wco.setTryUseCompression(true);
final WebClient client = WebClient.create(this.vertx, wco);
client.get(8044, "localhost", "/api").send(result -> {
if (result.succeeded()) {
context.assertEquals(200, result.result().statusCode());
} else {
context.fail(result.cause());
}
async.complete();
});
}
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:18,代码来源:ApplicationStarterTest.java
示例7: start
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Override
public void start() throws Exception {
tradingPair = config().getString("tradingPair");
handleFillsMessage = MessageDefinitions.HANDLE_FILLS+":"+tradingPair;
initOrderBookMessage = MessageDefinitions.INIT_ORDERBOOK+":"+tradingPair;
updateOrderBookMessage = MessageDefinitions.UPDATE_ORDERBOOK+":"+tradingPair;
setTicksMessage = MessageDefinitions.SET_LASTTICKS+":"+tradingPair;
tickIntervalStrings = new HashMap<Integer, String>();
tickIntervalStrings.put(1, "oneMin");
tickIntervalStrings.put(5, "fiveMin");
tickIntervalStrings.put(30, "thirtyMin");
tickIntervalStrings.put(60, "hour");
tickIntervalStrings.put(24*60, "day");
String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
WebClientOptions options = new WebClientOptions().setUserAgent(userAgent);
headers.add("User-Agent", userAgent);
options.setKeepAlive(false);
restclient = WebClient.create(vertx, options);
getConnectionToken();
}
开发者ID:AlxGDev,项目名称:BittrexGatherer,代码行数:27,代码来源:BittrexRemoteVerticle.java
示例8: initWebClient
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
private WebClient initWebClient() {
if (this.client == null) {
final WebClientOptions wco = new WebClientOptions();
final String proxyHost = this.getListenerConfig().getProxy();
final int proxyPort = this.getListenerConfig().getProxyPort();
if ((proxyHost != null) && (proxyPort > 0)) {
final ProxyOptions po = new ProxyOptions();
wco.setProxyOptions(po);
po.setHost(proxyHost).setPort(proxyPort);
}
// TODO: more options
wco.setUserAgent("SDFC VertX EventBus Client");
wco.setTryUseCompression(true);
this.client = WebClient.create(this.vertx, wco);
}
return this.client;
}
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:18,代码来源:CometD.java
示例9: testImplicitMode
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
public void testImplicitMode() {
vertx = Vertx.vertx();
WebClient client = WebClient.create(vertx);
HttpRequest<Buffer> request = client.postAbs("http://admin:[email protected]:8080/oauth/authorize?response_type=token&scope=read%20write&client_id=myClientId&redirect_uri=http://example.com");
request.putHeader("Authorization", getHeader());
request.send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
//String location = response.getHeader("Location");
String body = response.bodyAsString();
System.out.println("Implicit Mode Get Token" + body + " status code" + response.statusCode() + " Location=");
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
开发者ID:openmg,项目名称:metagraph-auth,代码行数:17,代码来源:VertxWebTest.java
示例10: main
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
// 1 - Create a Web client
WebClient client = WebClient.create(vertx);
vertx.createHttpServer()
.requestHandler(req -> {
// 2 - In the request handler, retrieve a Twitter feed
client
.getAbs("https://twitter.com/vertx_project")
.send(res -> {
// 3 - Write the response based on the result
if (res.failed()) {
req.response().end("Cannot access "
+ "the twitter feed: "
+ res.cause().getMessage());
} else {
req.response().end(res.result()
.bodyAsString());
}
});
})
.listen(8080);
}
开发者ID:jponge,项目名称:oracle-javamag-vertx-rxjava,代码行数:24,代码来源:TwitterFeedApplication.java
示例11: createWebClient
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
private void createWebClient(JsonObject conf){
int app_maxWaitQueueSize = S.getInt(conf,"app.maxWaitQueueSize",100);
int app_maxPoolSize = S.getInt(conf,"app.maxPoolSize",50);
int connectTimeout = S.getInt(conf,"app.connect.timeout",5000);
int idleTimeout = S.getInt(conf,"app.idle.timeout",60);
log.info("upstream connection pool size:{}, max wait queue size: {}", app_maxPoolSize,app_maxWaitQueueSize);
WebClientOptions op = new WebClientOptions();
op.setMaxWaitQueueSize(app_maxWaitQueueSize)
.setIdleTimeout(idleTimeout)
.setKeepAlive(true)
.setTcpKeepAlive(true)
// .setPipelining(true)
// .setPipeliningLimit(5)
.setConnectTimeout(connectTimeout)
.setSsl(false)
.setMaxPoolSize(app_maxPoolSize)
.setLogActivity(true);
this.webclient = WebClient.create(vertx,op);
}
开发者ID:troopson,项目名称:etagate,代码行数:22,代码来源:OutServerVerticle.java
示例12: testGetNode
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testGetNode() {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a = new App(vertx,http,"test");
WeightNodeStrategy w = new WeightNodeStrategy();
w.addNode(a.createDevNode("10.10.10.1",80,1));
w.addNode(a.createDevNode("10.10.10.2",80,2));
w.addNode(a.createDevNode("10.10.10.3",80,3));
w.addNode(a.createDevNode("10.10.10.4",80,4));
w.addNode(a.createDevNode("10.10.10.5",80,5));
w.addNode(a.createDevNode("10.10.10.6",80,6));
w.addNode(a.createDevNode("10.10.10.7",80,7));
w.addNode(a.createDevNode("10.10.10.8",80,8));
w.addNode(a.createDevNode("10.10.10.9",80,9));
w.addNode(a.createDevNode("10.10.10.10",80,10));
for(int i=0; i<100 ;i++){
// Node n = w.getNode(null);
// System.out.println(n);
System.out.println(w.getNode(null).toString());
}
}
开发者ID:troopson,项目名称:etagate,代码行数:26,代码来源:TestNodeSelectStrategy.java
示例13: testRoundStrategy
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testRoundStrategy() {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a = new App(vertx,http,"test");
RoundNodeStrategy w = new RoundNodeStrategy();
Node n1 = a.createDevNode("10.10.10.1",80,1);
Node n2 = a.createDevNode("10.10.10.1",80,1);
Node n3 = a.createDevNode("10.10.10.1",80,1);
Node n4 = a.createDevNode("10.10.10.1",80,1);
Node n5 = a.createDevNode("10.10.10.1",80,1);
w.addNode(n1);
w.addNode(n2);
w.addNode(n3);
w.addNode(n4);
w.addNode(n5);
for(int i=0; i<100 ;i++){
System.out.println(w.getNode(null).toString());
}
}
开发者ID:troopson,项目名称:etagate,代码行数:25,代码来源:TestNodeSelectStrategy.java
示例14: testRoundNodeStrategy
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testRoundNodeStrategy() {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a =new App(vertx,http,"test");
RoundNodeStrategy r = new RoundNodeStrategy();
r.addNode(new Node(a,"1.1.1.1", 80, 0));
r.addNode(new DownNode(a,"1.1.1.2", 80, 0));
r.addNode(new Node(a,"1.1.1.3", 80, 0));
System.out.println("==========RoundNodeStrategy =================");
for(int i=0;i<1000;i++){
Node n = r.getNode(null);
Assert.assertTrue(n.canTake());
System.out.println(n.host);
}
}
开发者ID:troopson,项目名称:etagate,代码行数:21,代码来源:TestNodeStrategy.java
示例15: testWeightNodeStrategy
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testWeightNodeStrategy() {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a =new App(vertx,http,"test");
WeightNodeStrategy r = new WeightNodeStrategy();
r.addNode(new Node(a,"1.1.1.1", 80, 1));
r.addNode(new DownNode(a,"1.1.1.2", 80, 2));
r.addNode(new Node(a,"1.1.1.3", 80, 1));
r.addNode(new Node(a,"1.1.1.4", 80, 3));
System.out.println("==========WeightNodeStrategy =================");
for(int i=0;i<1000;i++){
Node n = r.getNode(null);
Assert.assertTrue(n.canTake());
System.out.println(n.host);
}
}
开发者ID:troopson,项目名称:etagate,代码行数:20,代码来源:TestNodeStrategy.java
示例16: example2_webclient
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
public void example2_webclient(ServiceDiscovery discovery) {
// Get the record
discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> {
if (ar.succeeded() && ar.result() != null) {
// Retrieve the service reference
ServiceReference reference = discovery.getReference(ar.result());
// Retrieve the service object
WebClient client = reference.getAs(WebClient.class);
// You need to path the complete path
client.get("/api/persons").send(
response -> {
// ...
// Dont' forget to release the service
reference.release();
});
}
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:23,代码来源:HTTPEndpointExamples.java
示例17: example3_webclient
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
public void example3_webclient(ServiceDiscovery discovery) {
HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "some-http-service"), ar -> {
if (ar.succeeded()) {
WebClient client = ar.result();
// You need to path the complete path
client.get("/api/persons")
.send(response -> {
// ...
// Dont' forget to release the service
ServiceDiscovery.releaseServiceObject(discovery, client);
});
}
});
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:HTTPEndpointExamples.java
示例18: load
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
public void load(Handler<AsyncResult<Void>> resultHandler) {
WebClientOptions options = new WebClientOptions();
if (!"none".equalsIgnoreCase(PROXY_HOST)) {
options.setProxyOptions(new ProxyOptions()
.setType(ProxyType.HTTP)
.setHost(PROXY_HOST)
.setPort(PROXY_PORT));
}
String wellKnownUrl = this.config.getWellKnownUrl();
WebClient.create(this.vertx, options)
.getAbs(wellKnownUrl)
.ssl(wellKnownUrl.startsWith("https://") ? true : false)
.send(ar -> {
if (ar.succeeded()) {
JsonObject response = Optional.ofNullable(ar.result().bodyAsJsonObject()).orElseGet(JsonObject::new);
this.parseAndStoreWellKnownFields(response, resultHandler);
} else {
LOG.error("Unable to retrieve well known fields from {}", wellKnownUrl, ar.cause());
resultHandler.handle(Future.failedFuture(ar.cause()));
}
});
}
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:23,代码来源:JWKSAuthProviderImpl.java
示例19: evaluate
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
@Override
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
// ----
// First we need to discover and get a HTTP client for the `quotes` service:
HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "quotes"),
client -> {
if (client.failed()) {
// It failed...
resultHandler.handle(Future.failedFuture(client.cause()));
} else {
// We have the client
WebClient webClient = client.result();
computeEvaluation(webClient, resultHandler);
}
});
// ---
}
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:19,代码来源:PortfolioServiceImpl.java
示例20: getValueForCompany
import io.vertx.ext.web.client.WebClient; //导入依赖的package包/类
private Future<Double> getValueForCompany(WebClient client, String company, int numberOfShares) {
// Create the future object that will get the value once the value have been retrieved
Future<Double> future = Future.future();
//----
client.get("/?name=" + encode(company))
.as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
if (response.statusCode() == 200) {
double v = numberOfShares * response.body().getDouble("bid");
future.complete(v);
} else {
future.complete(0.0);
}
} else {
future.fail(ar.cause());
}
});
// ---
return future;
}
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:25,代码来源:PortfolioServiceImpl.java
注:本文中的io.vertx.ext.web.client.WebClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论