本文整理汇总了Java中com.gargoylesoftware.htmlunit.ProxyConfig类的典型用法代码示例。如果您正苦于以下问题:Java ProxyConfig类的具体用法?Java ProxyConfig怎么用?Java ProxyConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProxyConfig类属于com.gargoylesoftware.htmlunit包,在下文中一共展示了ProxyConfig类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideWebClient
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
@Provides
protected WebClient provideWebClient()
{
WebClient webClient = new WebClient();
String proxyHost = config.getProperty("ws.proxy.host");
String proxyPort = config.getProperty("ws.proxy.port");
if (proxyHost != null && !"".equals(proxyHost) && proxyPort != null && !"".equals(proxyPort))
{
ProxyConfig proxyConfig = new ProxyConfig(proxyHost, Integer.parseInt(proxyPort));
webClient.getOptions().setProxyConfig(proxyConfig);
}
webClient.getOptions().setActiveXNative(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setUseInsecureSSL(true);
return webClient;
}
示例2: setUp
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws InterruptedException {
log.debug("setUp");
webClient = new WebClient();
WebClientOptions options = webClient.getOptions();
options.setPrintContentOnFailingStatusCode(true);
options.setJavaScriptEnabled(true);
webClient.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
ProxyConfig proxy = new ProxyConfig("p-goodway.rd.francetelecom.fr", 3128);
proxy.addHostsToProxyBypass("127.0.0.1");
options.setProxyConfig(proxy);
}
示例3: setProxy
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
public static void setProxy(WebClient webClient,String host,int port) {
ProxyConfig proxyConfig = webClient.getOptions().getProxyConfig();
proxyConfig.setProxyHost(host);
proxyConfig.setProxyPort(port);
//DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
//credentialsProvider.addCredentials(proxy.getUser(), proxy.getPassword());
}
示例4: setProxyBasedOnSystemProperties
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
/**
* <p>This is the system variable we will look for to parse the Proxy configuration.</p>
* <p>TODO: There are default system properties for this? (proxy.host, proxy.port).</p>
*
* <p>Format: <host>:<port> (so, <code>localhost:8080</code> for example).</p>
*/
public static void setProxyBasedOnSystemProperties() {
final Logger logger = LoggerFactory.getLogger(WebClientFactory.class);
String proxyString = System.getProperty(PROXY_CONFIG);
if (proxyString == null) {
logger.info("No proxy configured via system property '{}'", PROXY_CONFIG);
} else {
logger.info("Using a proxy: {}", proxyString);
try {
proxy = new ProxyConfig(proxyString.split(":")[0], Integer.parseInt(proxyString.split(":")[1]));
} catch (Exception e) {
logger.error("Error parsing proxyString: {}", proxyString, e);
}
}
}
示例5: setProxy
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
synchronized void setProxy()
{
if(!(proxy.equals("")||port.equals("")))
{
ProxyConfig pgg=new ProxyConfig(proxy,Integer.parseInt(port));
webClient.setProxyConfig(pgg);
pgg=null;
}
if(puser!=""&&ppass!="")
{
credentialsProvider.addCredentials(puser,ppass);
}
}
示例6: LinkedInOAuthRequestFilter
import com.gargoylesoftware.htmlunit.ProxyConfig; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public LinkedInOAuthRequestFilter(OAuthParams oAuthParams, Map<String, Object> httpParams,
boolean lazyAuth, String[] enabledProtocols) {
this.oAuthParams = oAuthParams;
this.oAuthToken = null;
// create HtmlUnit client
webClient = new WebClient(BrowserVersion.FIREFOX_38);
final WebClientOptions options = webClient.getOptions();
options.setRedirectEnabled(true);
options.setJavaScriptEnabled(false);
options.setThrowExceptionOnFailingStatusCode(true);
options.setThrowExceptionOnScriptError(true);
options.setPrintContentOnFailingStatusCode(LOG.isDebugEnabled());
options.setSSLClientProtocols(enabledProtocols);
// add HTTP proxy if set
if (httpParams != null && httpParams.get(ConnRoutePNames.DEFAULT_PROXY) != null) {
final HttpHost proxyHost = (HttpHost) httpParams.get(ConnRoutePNames.DEFAULT_PROXY);
final Boolean socksProxy = (Boolean) httpParams.get("http.route.socks-proxy");
final ProxyConfig proxyConfig = new ProxyConfig(proxyHost.getHostName(), proxyHost.getPort(),
socksProxy != null ? socksProxy : false);
options.setProxyConfig(proxyConfig);
}
// disable default gzip compression, as error pages are sent with no compression and htmlunit doesn't negotiate
new WebConnectionWrapper(webClient) {
@Override
public WebResponse getResponse(WebRequest request) throws IOException {
request.setAdditionalHeader(HttpHeaders.ACCEPT_ENCODING, "identity");
return super.getResponse(request);
}
};
if (!lazyAuth) {
try {
updateOAuthToken();
} catch (IOException e) {
throw new IllegalArgumentException(
String.format("Error authorizing user %s: %s", oAuthParams.getUserName(), e.getMessage()), e);
}
}
}