本文整理汇总了Java中io.vertx.ext.web.client.WebClient.create方法的典型用法代码示例。如果您正苦于以下问题:Java WebClient.create方法的具体用法?Java WebClient.create怎么用?Java WebClient.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.client.WebClient
的用法示例。
在下文中一共展示了WebClient.create方法的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") // <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));
}
示例3: 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");
}
}
示例4: 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();
});
}
示例5: 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();
}
示例6: 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);
}
}
示例7: 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());
}
});
}
示例8: 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);
}
}
示例9: 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;
}
示例10: 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());
}
}
示例11: start
import io.vertx.ext.web.client.WebClient; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
String tradingPair="BTC-ARK";
config = new JsonObject()
.put("tradingPair", tradingPair);
String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
WebClientOptions webclientoptions = new WebClientOptions().setUserAgent(userAgent);
webclientoptions.setKeepAlive(false);
restclient = WebClient.create(vertx, webclientoptions);
vertx.eventBus()
.<String>consumer(MessageDefinitions.REDEPLOYBITTREXVERTICLES)
.handler(handleVerticleRedeploy());
options = new DeploymentOptions();
options.setConfig(config);
redeployVerticles(options);
Router router = Router.router(vertx);
router.route("/eventbus/*").handler(eventBusHandler());
router.get("/api/tradingpairs")
.handler(this::handleGetTradingPairs);
router.route().failureHandler(errorHandler());
router.route("/*").handler(StaticHandler.create("static").setCachingEnabled(false));
router.route().handler(FaviconHandler.create("static/favicon.ico"));
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(config().getInteger("http.port", 8080));
}
示例12: main
import io.vertx.ext.web.client.WebClient; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a =new App(vertx,http,"test");
Node n = new Node(a,"localhost", 8080, 1);
n.addCircuitBreaker(vertx, 1000, 2, 30*1000);
Handler<AsyncResult<HttpResponse<Buffer>>> h = r->{
if(r.succeeded())
System.out.println("OK "+n.status());
else
System.out.println("Fail "+n.status());
};
n.get("/test", null, h);
n.get("/test", null, h);
n.get("/test", null, h);
for(int i=0;i<20;i++){
Thread.sleep(10* 1000);
n.get("/test", null, h);
n.get("/test", null, h);
n.get("/test", null, h);
}
}
示例13: before
import io.vertx.ext.web.client.WebClient; //导入方法依赖的package包/类
@Before
public void before(TestContext context) {
vertx = Vertx.vertx();
vertx.exceptionHandler(context.exceptionHandler());
vertx.deployVerticle(TradeRecommendationsService.class.getName(), context.asyncAssertSuccess());
client = WebClient.create(vertx);
}
示例14: start
import io.vertx.ext.web.client.WebClient; //导入方法依赖的package包/类
public void start() throws Exception {
JsonObject conf = vertx.getOrCreateContext().config();
HttpServerOptions options = new HttpServerOptions();
options.setCompressionSupported(true);
HttpServer server = vertx.createHttpServer(options);
/*
<property name="inside.host">172.18.7.20</property>
<property name="inside.port">8999</property>
*/
String host = conf.getString("inside.host");
String port = conf.getString("inside.port");
if(S.isBlank(host) || S.isBlank(port))
return;
// ============初始化======================
this.upload_dir = conf.getString("upload.dir");
this.webclient = WebClient.create(vertx);
this.appContain = gsetting.getAppContain(vertx,this.webclient);
this.initRoutes();
server.requestHandler(router::accept);
server.listen(Integer.parseInt(port), host,ar -> {
if (ar.succeeded()) {
log.info("InsideServer listen on " + port);
} else {
log.error("InsideServer Failed to start!", ar.cause());
}
});
}
示例15: SlimVaultClient
import io.vertx.ext.web.client.WebClient; //导入方法依赖的package包/类
/**
* Creates an instance of {@link SlimVaultClient}.
*
* @param vertx the vert.x instance
* @param configuration the configuration. This configuration can contain the underlying Web Client configuration.
*/
public SlimVaultClient(Vertx vertx, JsonObject configuration) {
String host = configuration.getString("host");
Integer port = configuration.getInteger("port", 8200);
Objects.requireNonNull(host, "The Vault host must be set");
client = WebClient.create(vertx, new WebClientOptions(configuration)
.setDefaultPort(port).setDefaultHost(host)
);
setToken(configuration.getString("token"));
}