本文整理汇总了Java中io.vertx.ext.web.client.WebClient类的典型用法代码示例。如果您正苦于以下问题:Java WebClient类的具体用法?Java WebClient怎么用?Java WebClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebClient类属于io.vertx.ext.web.client包,在下文中一共展示了WebClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")));
}
示例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[]
}
示例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));
}
示例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;
}
示例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");
}
}
示例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();
});
}
示例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();
}
示例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;
}
示例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());
}
});
}
示例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);
}
示例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);
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}