Java源码示例:io.vertx.core.net.ProxyType
示例1
private void mapClientOptionsBase(AmqpProperties from, AmqpClientOptions to) {
to.setConnectTimeout(from.getConnectTimeout());
to.setTrustAll(from.isTrustAll());
to.setMetricsName(from.getMetricsName());
to.setLocalAddress(from.getLocalAddress());
if (from.getProxy().isEnabled()) {
ProxyOptions proxyOptions = new ProxyOptions()
.setHost(from.getProxy().getHost())
.setPort(from.getProxy().getPort())
.setUsername(from.getProxy().getUsername())
.setPassword(from.getProxy().getPassword())
.setType(ProxyType.valueOf(from.getProxy().getType().name()));
to.setProxyOptions(proxyOptions);
}
}
示例2
@Test
public void testSetUpProxy(TestContext context) throws Exception {
this.testContext = context;
MailConfig mailConfig = configLogin().setProxyOptions(new ProxyOptions().setType(ProxyType.SOCKS5).setPort(11080));
proxy = new SocksProxy(null);
proxy.start(vertx);
Async async = testContext.async();
MailClient client = MailClient.createShared(vertx, mailConfig);
client.sendMail(exampleMessage(), r -> {
if (r.succeeded()) {
assertEquals("localhost:1587", proxy.getLastUri());
async.complete();
} else {
log.debug("Failed to send mail", r.cause());
testContext.fail(r.cause());
}
});
}
示例3
@Test
public void testSetUpProxyAuth(TestContext context) throws Exception {
this.testContext = context;
MailConfig mailConfig = configLogin().setProxyOptions(new ProxyOptions()
.setType(ProxyType.SOCKS5)
.setPort(11080)
.setUsername("proxyUser")
.setPassword("proxyUser")
);
proxy = new SocksProxy("proxyUser");
proxy.start(vertx);
Async async = testContext.async();
MailClient client = MailClient.createShared(vertx, mailConfig);
client.sendMail(exampleMessage(), r -> {
if (r.succeeded()) {
assertEquals("localhost:1587", proxy.getLastUri());
async.complete();
} else {
log.debug("Failed to send mail", r.cause());
testContext.fail(r.cause());
}
});
}
示例4
private WebClient createWebClient(Vertx vertx, URL url) {
final int port = url.getPort() != -1 ? url.getPort() : (HTTPS_SCHEME.equals(url.getProtocol()) ? 443 : 80);
WebClientOptions options = new WebClientOptions()
.setDefaultPort(port)
.setDefaultHost(url.getHost())
.setKeepAlive(true)
.setMaxPoolSize(10)
.setTcpKeepAlive(true)
.setConnectTimeout(httpClientTimeout)
.setSsl(url.getProtocol().equals(HTTPS_SCHEME));
if (this.isProxyConfigured) {
ProxyOptions proxyOptions = new ProxyOptions();
proxyOptions.setType(ProxyType.valueOf(httpClientProxyType));
if (HTTPS_SCHEME.equals(url.getProtocol())) {
proxyOptions.setHost(httpClientProxyHttpsHost);
proxyOptions.setPort(httpClientProxyHttpsPort);
proxyOptions.setUsername(httpClientProxyHttpsUsername);
proxyOptions.setPassword(httpClientProxyHttpsPassword);
} else {
proxyOptions.setHost(httpClientProxyHttpHost);
proxyOptions.setPort(httpClientProxyHttpPort);
proxyOptions.setUsername(httpClientProxyHttpUsername);
proxyOptions.setPassword(httpClientProxyHttpPassword);
}
options.setProxyOptions(proxyOptions);
}
return WebClient.create(vertx, options);
}
示例5
private HttpClient getHttpClient(String uriScheme, Boolean useSystemProxy) {
boolean ssl = HTTPS_SCHEME.equalsIgnoreCase(uriScheme);
final HttpClientOptions options = new HttpClientOptions()
.setSsl(ssl)
.setTrustAll(true)
.setMaxPoolSize(1)
.setKeepAlive(false)
.setTcpKeepAlive(false)
.setConnectTimeout(httpClientTimeout);
if ((useSystemProxy != null && useSystemProxy == Boolean.TRUE) || (useSystemProxy == null && this.isProxyConfigured)) {
ProxyOptions proxyOptions = new ProxyOptions();
proxyOptions.setType(ProxyType.valueOf(httpClientProxyType));
if (HTTPS_SCHEME.equals(uriScheme)) {
proxyOptions.setHost(httpClientProxyHttpsHost);
proxyOptions.setPort(httpClientProxyHttpsPort);
proxyOptions.setUsername(httpClientProxyHttpsUsername);
proxyOptions.setPassword(httpClientProxyHttpsPassword);
} else {
proxyOptions.setHost(httpClientProxyHttpHost);
proxyOptions.setPort(httpClientProxyHttpPort);
proxyOptions.setUsername(httpClientProxyHttpUsername);
proxyOptions.setPassword(httpClientProxyHttpPassword);
}
options.setProxyOptions(proxyOptions);
}
return vertx.createHttpClient(options);
}
示例6
/**
* Constructor.
*
* @param vertx the vertx
* @param vxEngineConfig the engine config
* @param config the plugin config
*/
public VertxPluginRegistry(Vertx vertx, VertxEngineConfig vxEngineConfig, Map<String, String> config) {
super(config);
this.vertx = vertx;
//Get HTTPS Proxy settings (useful for local dev tests and corporate CI)
String sslProxyHost = System.getProperty("https.proxyHost", "none");
Integer sslProxyPort = Integer.valueOf(System.getProperty("https.proxyPort", "443"));
sslNoProxy = System.getProperty("https.nonProxyHosts", "none");
//Set HTTPS proxy if defined
if (!"none".equalsIgnoreCase(sslProxyHost)) {
sslProxy = new ProxyOptions();
sslProxy.setHost(sslProxyHost);
sslProxy.setPort(sslProxyPort);
sslProxy.setType(ProxyType.HTTP);
}
//Get HTTP Proxy settings (useful for local dev tests and corporate CI)
String proxyHost = System.getProperty("http.proxyHost", "none");
Integer proxyPort = Integer.valueOf(System.getProperty("http.proxyPort", "80"));
noProxy = System.getProperty("http.nonProxyHosts", "none");
//Set HTTPS proxy if defined
if (!"none".equalsIgnoreCase(proxyHost)) {
proxy = new ProxyOptions();
proxy.setHost(proxyHost);
proxy.setPort(proxyPort);
proxy.setType(ProxyType.HTTP);
}
}