本文整理汇总了Java中org.apache.commons.httpclient.ProxyHost类的典型用法代码示例。如果您正苦于以下问题:Java ProxyHost类的具体用法?Java ProxyHost怎么用?Java ProxyHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProxyHost类属于org.apache.commons.httpclient包,在下文中一共展示了ProxyHost类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createHttpClient
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
private HttpClient createHttpClient() {
HttpClient client = new HttpClient();
// added by Unicon to handle proxy hosts
String proxyHost = System.getProperty( "http.proxyHost" );
if ( proxyHost != null ) {
int proxyPort = -1;
String proxyPortStr = System.getProperty( "http.proxyPort" );
if (proxyPortStr != null) {
try {
proxyPort = Integer.parseInt( proxyPortStr );
} catch (NumberFormatException e) {
logger.warn("Invalid number for system property http.proxyPort ("+proxyPortStr+"), using default port instead");
}
}
ProxyHost proxy = new ProxyHost( proxyHost, proxyPort );
client.getHostConfiguration().setProxyHost( proxy );
}
// added by Unicon to force encoding to UTF-8
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8_CHARSET);
client.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, UTF8_CHARSET);
client.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, UTF8_CHARSET);
HttpConnectionManagerParams connParams = client.getHttpConnectionManager().getParams();
if(this.kalturaConfiguration.getTimeout() != 0) {
connParams.setSoTimeout(this.kalturaConfiguration.getTimeout());
connParams.setConnectionTimeout(this.kalturaConfiguration.getTimeout());
}
client.getHttpConnectionManager().setParams(connParams);
return client;
}
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:32,代码来源:KalturaClientBase.java
示例2: getProxyHost
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
public String getProxyHost(String urlString) {
String result = urlString;
try {
URL url = new URL(urlString);
ProxyHost hostInfo = PluginProxyUtil.detectProxy(url);
if (hostInfo != null) {
result = hostInfo.getHostName();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:14,代码来源:PluginProxyTestApplet.java
示例3: getProxyPort
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
public int getProxyPort(String urlString) {
int result = 80;
try {
URL url = new URL(urlString);
ProxyHost hostInfo = PluginProxyUtil.detectProxy(url);
if (hostInfo != null) {
result = hostInfo.getPort();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:14,代码来源:PluginProxyTestApplet.java
示例4: tokenAuthen
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
public SlackInfo tokenAuthen(String token, String proxyUrl, int proxyPort) {
HttpClient client = new HttpClient();
if (proxyUrl != null) {
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setProxyHost(new ProxyHost(proxyUrl, proxyPort));
client.setHostConfiguration(hostConfiguration);
}
GetMethod getMethod = new GetMethod(SLACK_RTM_AUTHEN_URL + token);
SlackInfo slackInfo = new SlackInfo();
try {
int httpStatus = client.executeMethod(getMethod);
if (httpStatus == HttpStatus.SC_OK) {
ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper.readValue(getMethod.getResponseBodyAsStream(), SlackInfo.class);
} else {
slackInfo.setError("http_status_" + httpStatus);
return slackInfo;
}
} catch (IOException ex) {
slackInfo.setError("exception " + ex.getMessage());
Logger.getLogger(SlackAuthen.class.getName()).log(Level.SEVERE, null, ex);
} finally {
getMethod.releaseConnection();
}
return slackInfo;
}
开发者ID:mockupcode,项目名称:slack-rtm-api,代码行数:31,代码来源:SlackAuthen.java
示例5: detectProxy
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
/**
* Returns the Proxy Host information using settings from the java plugin.
*
* @param sampleURL the url target for which proxy host information is
* required
* @return the proxy host info (name and port) or null if a direct
* connection is allowed to the target url.
* @throws ProxyDetectionException if detection failed
*/
public static ProxyHost detectProxy(URL sampleURL)
throws ProxyDetectionException
{
ProxyHost result = null;
String javaVers = System.getProperty("java.runtime.version");
if (LOG.isDebugEnabled()) {
LOG.debug("About to attempt auto proxy detection under Java " +
"version:"+javaVers);
}
// If specific, known detection methods fail may try fallback
// detection method
boolean invokeFailover = false;
if (javaVers.startsWith("1.3")) {
result = detectProxySettingsJDK13(sampleURL);
if (result == null) {
invokeFailover = true;
}
} else if (javaVers.startsWith("1.4") || (javaVers.startsWith("1.5") || javaVers.startsWith("1.6"))) {
result = detectProxySettingsJDK14_JDK15_JDK16(sampleURL);
if (result == null) {
invokeFailover = true;
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Sun Plugin reported java version not 1.3.X, " +
"1.4.X, 1.5.X or 1.6.X - trying failover detection...");
}
invokeFailover = true;
}
if (invokeFailover) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using failover proxy detection...");
}
result = getPluginProxyConfigSettings();
}
if (NO_PROXY_HOST.equals(result)) {
result = null;
}
return result;
}
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:54,代码来源:PluginProxyUtil.java
示例6: execute
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
/**
* This method performs the proxying of the request to the target address.
*
* @param target The target address. Has to be a fully qualified address. The request is send as-is to this address.
* @param hsRequest The request data which should be send to the
* @param hsResponse The response data which will contain the data returned by the proxied request to target.
* @throws java.io.IOException Passed on from the connection logic.
*/
public static void execute(final String target, final HttpServletRequest hsRequest, final HttpServletResponse hsResponse) throws IOException {
if ( log.isInfoEnabled() ) {
log.info("execute, target is " + target);
log.info("response commit state: " + hsResponse.isCommitted());
}
if (StringUtils.isBlank(target)) {
log.error("The target address is not given. Please provide a target address.");
return;
}
log.info("checking url");
final URL url;
try {
url = new URL(target);
} catch (MalformedURLException e) {
log.error("The provided target url is not valid.", e);
return;
}
log.info("seting up the host configuration");
final HostConfiguration config = new HostConfiguration();
ProxyHost proxyHost = getUseProxyServer((String) hsRequest.getAttribute("use-proxy"));
if (proxyHost != null) config.setProxyHost(proxyHost);
final int port = url.getPort() != -1 ? url.getPort() : url.getDefaultPort();
config.setHost(url.getHost(), port, url.getProtocol());
if ( log.isInfoEnabled() ) log.info("config is " + config.toString());
final HttpMethod targetRequest = setupProxyRequest(hsRequest, url);
if (targetRequest == null) {
log.error("Unsupported request method found: " + hsRequest.getMethod());
return;
}
//perform the reqeust to the target server
final HttpClient client = new HttpClient(new SimpleHttpConnectionManager());
if (log.isInfoEnabled()) {
log.info("client state" + client.getState());
log.info("client params" + client.getParams().toString());
log.info("executeMethod / fetching data ...");
}
final int result;
if (targetRequest instanceof EntityEnclosingMethod) {
final RequestProxyCustomRequestEntity requestEntity = new RequestProxyCustomRequestEntity(
hsRequest.getInputStream(), hsRequest.getContentLength(), hsRequest.getContentType());
final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) targetRequest;
entityEnclosingMethod.setRequestEntity(requestEntity);
result = client.executeMethod(config, entityEnclosingMethod);
} else {
result = client.executeMethod(config, targetRequest);
}
//copy the target response headers to our response
setupResponseHeaders(targetRequest, hsResponse);
InputStream originalResponseStream = targetRequest.getResponseBodyAsStream();
//the body might be null, i.e. for responses with cache-headers which leave out the body
if (originalResponseStream != null) {
OutputStream responseStream = hsResponse.getOutputStream();
copyStream(originalResponseStream, responseStream);
}
log.info("set up response, result code was " + result);
}
开发者ID:paultuckey,项目名称:urlrewritefilter,代码行数:79,代码来源:RequestProxy.java
示例7: detectProxy
import org.apache.commons.httpclient.ProxyHost; //导入依赖的package包/类
/**
* Returns the Proxy Host information using settings from the java plugin.
*
* @param sampleURL the url target for which proxy host information is
* required
* @return the proxy host info (name and port) or null if a direct
* connection is allowed to the target url.
* @throws ProxyDetectionException if detection failed
*/
public static ProxyHost detectProxy(URL sampleURL)
throws ProxyDetectionException
{
ProxyHost result = null;
String javaVers = System.getProperty("java.runtime.version");
if (LOG.isDebugEnabled()) {
LOG.debug("About to attempt auto proxy detection under Java " +
"version:"+javaVers);
}
// If specific, known detection methods fail may try fallback
// detection method
boolean invokeFailover = false;
if (javaVers.startsWith("1.3")) {
result = detectProxySettingsJDK13(sampleURL);
if (result == null) {
invokeFailover = true;
}
} else if (javaVers.startsWith("1.4")) {
result = detectProxySettingsJDK14(sampleURL);
if (result == null) {
invokeFailover = true;
}
} else if (javaVers.startsWith("1.5")) {
invokeFailover = true;
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Sun Plugin reported java version not 1.3.X, " +
"1.4.X or 1.5.X - trying failover detection...");
}
invokeFailover = true;
}
if (invokeFailover) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using failover proxy detection...");
}
result = getPluginProxyConfigSettings();
}
if (NO_PROXY_HOST.equals(result)) {
result = null;
}
return result;
}
开发者ID:magneticmoon,项目名称:httpclient3-ntml,代码行数:56,代码来源:PluginProxyUtil.java
注:本文中的org.apache.commons.httpclient.ProxyHost类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论