本文整理匯總了Java中org.apache.commons.httpclient.HttpState.setProxyCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpState.setProxyCredentials方法的具體用法?Java HttpState.setProxyCredentials怎麽用?Java HttpState.setProxyCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.HttpState
的用法示例。
在下文中一共展示了HttpState.setProxyCredentials方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setBasicAuth
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public void setBasicAuth(HttpState httpState) {
// Setting basic authentication for proxy
if ((!this.proxyServer.equals("")) && (!this.proxyUser.equals(""))) {
httpState.setProxyCredentials(
new AuthScope(this.proxyServer, -1, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(this.proxyUser, this.proxyPassword));
Engine.logProxyManager.debug("(ProxyManager) Using credentials: " + promptUser
+ ", <password not logged, set engine logger log level to TRACE to see it>");
Engine.logProxyManager.trace("(ProxyManager) Using password: " + proxyPassword);
}
}
示例2: setNtlmAuth
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public void setNtlmAuth(HttpState httpState) {
// Setting NTLM authentication for proxy
int indexSlash = this.proxyUser.indexOf("\\");
String domain = this.proxyUser.substring(0, indexSlash);
String username = this.proxyUser.substring(indexSlash + 1);
Engine.logProxyManager.debug("(ProxyManager) Using NTLM authentication on domain: " + domain);
httpState.setProxyCredentials(
new AuthScope(this.proxyServer, -1, AuthScope.ANY_REALM),
new NTCredentials(username, this.proxyPassword, this.proxyServer, domain));
}
示例3: setAnonymAuth
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public void setAnonymAuth(HttpState httpState) {
// Setting anonym authentication for proxy
if ((!this.proxyServer.equals("")) && (!this.proxyUser.equals(""))) {
httpState.setProxyCredentials(
new AuthScope(AuthScope.ANY),
new Credentials() {
});
Engine.logProxyManager.debug("(ProxyManager) Proxy credentials: anonym");
}
}
示例4: createHttpClient
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public HttpClient createHttpClient() {
HttpClient client = new HttpClient();
String proxyHost = System.getProperty(HTTPS_PROXY_HOST);
String proxyPort = System.getProperty(HTTPS_PROXY_PORT);
String proxyUser = System.getProperty(HTTPS_PROXY_USER);
String proxyPassword = System.getProperty(HTTPS_PROXY_PASSWORD);
int proxyPortInt = 0;
try {
proxyPortInt = Integer.parseInt(proxyPort);
} catch (NumberFormatException e) {
// ignore
}
if (!useProxyByPass(this.apiUrl)) {
if (proxyHost != null && proxyPortInt > 0) {
client.getHostConfiguration().setProxy(proxyHost, proxyPortInt);
if (proxyUser != null && proxyUser.length() > 0
&& proxyPassword != null && proxyPassword.length() > 0) {
HttpState state = new HttpState();
Credentials proxyCredentials = new UsernamePasswordCredentials(
proxyUser, proxyPassword);
state.setProxyCredentials(new AuthScope(proxyHost,
proxyPortInt), proxyCredentials);
client.setState(state);
}
}
}
return client;
}
示例5: setProxy
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private static void setProxy(HostConfiguration config, HttpState state, ProxyData data) {
// set Proxy
if(ProxyDataImpl.isValid(data)) {
config.setProxy(data.getServer(),data.getPort()<=0?80:data.getPort());
if(ProxyDataImpl.hasCredentials(data)) {
state.setProxyCredentials(null,null,new UsernamePasswordCredentials(data.getUsername(),StringUtil.emptyIfNull(data.getPassword())));
}
}
}
示例6: setProxyHost
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public static void setProxyHost(HttpClient httpClient, UsernamePasswordCredentials proxyCredentials,
String proxyHost, int proxyPort) {
if (proxyHost != null && !proxyHost.isEmpty()) {
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
if (proxyCredentials != null) {
HttpState state = new HttpState();
state.setProxyCredentials(new AuthScope(proxyHost, proxyPort), proxyCredentials);
httpClient.setState(state);
}
}
}
示例7: getHttpState
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
/**
* Get the HTTPState for a transfer target
* @param target TransferTarget
* @return HttpState
*/
private HttpState getHttpState(TransferTarget target)
{
HttpState httpState = new HttpState();
httpState.setCredentials(new AuthScope(target.getEndpointHost(), target.getEndpointPort(),
AuthScope.ANY_REALM),
new UsernamePasswordCredentials(target.getUsername(), new String(target.getPassword())));
String requiredProtocol = target.getEndpointProtocol();
if (requiredProtocol == null)
{
throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
}
Protocol protocol = protocolMap.get(requiredProtocol.toLowerCase().trim());
if (protocol == null)
{
log.error("Unsupported protocol: " + requiredProtocol);
throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
}
// Use the appropriate Proxy credentials if required
if (httpProxyHost != null && HTTP_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
{
if (httpProxyCredentials != null)
{
httpState.setProxyCredentials(httpAuthScope, httpProxyCredentials);
if (log.isDebugEnabled())
{
log.debug("Using HTTP proxy credentials for proxy: " + httpProxyHost.getHostName());
}
}
}
else if (httpsProxyHost != null && HTTPS_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
{
if (httpsProxyCredentials != null)
{
httpState.setProxyCredentials(httpsAuthScope, httpsProxyCredentials);
if (log.isDebugEnabled())
{
log.debug("Using HTTPS proxy credentials for proxy: " + httpsProxyHost.getHostName());
}
}
}
return httpState;
}
示例8: CrowdManager
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private CrowdManager() {
try {
// loading crowd.properties file
CrowdProperties crowdProps = new CrowdProperties();
MultiThreadedHttpConnectionManager threadedConnectionManager = new MultiThreadedHttpConnectionManager();
HttpClient hc = new HttpClient(threadedConnectionManager);
HttpClientParams hcParams = hc.getParams();
hcParams.setAuthenticationPreemptive(true);
HttpConnectionManagerParams hcConnectionParams = hc.getHttpConnectionManager().getParams();
hcConnectionParams.setDefaultMaxConnectionsPerHost(crowdProps.getHttpMaxConnections());
hcConnectionParams.setMaxTotalConnections(crowdProps.getHttpMaxConnections());
hcConnectionParams.setConnectionTimeout(crowdProps.getHttpConnectionTimeout());
hcConnectionParams.setSoTimeout(crowdProps.getHttpSocketTimeout());
crowdServer = new URI(crowdProps.getCrowdServerUrl()).resolve("rest/usermanagement/latest/");
// setting BASIC authentication in place for connection with Crowd
HttpState httpState = hc.getState();
Credentials crowdCreds = new UsernamePasswordCredentials(crowdProps.getApplicationName(), crowdProps.getApplicationPassword());
httpState.setCredentials(new AuthScope(crowdServer.getHost(), crowdServer.getPort()), crowdCreds);
// setting Proxy config in place if needed
if (StringUtils.isNotBlank(crowdProps.getHttpProxyHost()) && crowdProps.getHttpProxyPort() > 0) {
hc.getHostConfiguration().setProxy(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort());
if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername()) || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) {
Credentials proxyCreds = new UsernamePasswordCredentials(crowdProps.getHttpProxyUsername(), crowdProps.getHttpProxyPassword());
httpState.setProxyCredentials(new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()), proxyCreds);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("HTTP Client config");
LOG.debug(crowdServer.toString());
LOG.debug("Max connections:" + hcConnectionParams.getMaxTotalConnections());
LOG.debug("Socket timeout:" + hcConnectionParams.getSoTimeout());
LOG.debug("Connect timeout:" + hcConnectionParams.getConnectionTimeout());
LOG.debug("Proxy host:" + crowdProps.getHttpProxyHost() + ":" + crowdProps.getHttpProxyPort());
LOG.debug("Crowd application name:" + crowdProps.getApplicationName());
}
client = hc;
} catch (Exception e) {
LOG.error("Failure to load the Crowd manager", e);
}
}
示例9: CrowdManager
import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private CrowdManager() {
try {
// loading crowd.properties file
CrowdProperties crowdProps = new CrowdProperties();
MultiThreadedHttpConnectionManager threadedConnectionManager = new MultiThreadedHttpConnectionManager();
HttpClient hc = new HttpClient(threadedConnectionManager);
HttpClientParams hcParams = hc.getParams();
hcParams.setAuthenticationPreemptive(true);
HttpConnectionManagerParams hcConnectionParams = hc.getHttpConnectionManager().getParams();
hcConnectionParams.setDefaultMaxConnectionsPerHost(crowdProps.getHttpMaxConnections());
hcConnectionParams.setMaxTotalConnections(crowdProps.getHttpMaxConnections());
hcConnectionParams.setConnectionTimeout(crowdProps.getHttpConnectionTimeout());
hcConnectionParams.setSoTimeout(crowdProps.getHttpSocketTimeout());
crowdServer = new URI(crowdProps.getCrowdServerUrl()).resolve("rest/usermanagement/latest/");
// setting BASIC authentication in place for connection with Crowd
HttpState httpState = hc.getState();
Credentials crowdCreds = new UsernamePasswordCredentials(crowdProps.getApplicationName(), crowdProps.getApplicationPassword());
httpState.setCredentials(new AuthScope(crowdServer.getHost(), crowdServer.getPort()), crowdCreds);
// setting Proxy config in place if needed
if (StringUtils.isNotBlank(crowdProps.getHttpProxyHost()) && crowdProps.getHttpProxyPort() > 0) {
hc.getHostConfiguration().setProxy(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort());
if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername()) || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) {
Credentials proxyCreds = new UsernamePasswordCredentials(crowdProps.getHttpProxyUsername(), crowdProps.getHttpProxyPassword());
httpState.setProxyCredentials(new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()), proxyCreds);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("HTTP Client config");
LOG.debug(crowdServer.toString());
LOG.debug("Max connections:" + hcConnectionParams.getMaxTotalConnections());
LOG.debug("Socket timeout:" + hcConnectionParams.getSoTimeout());
LOG.debug("Connect timeout:" + hcConnectionParams.getConnectionTimeout());
LOG.debug("Proxy host:" + crowdProps.getHttpProxyHost() + ":" + crowdProps.getHttpProxyPort());
LOG.debug("Crowd application name:" + crowdProps.getApplicationName());
}
client = hc;
} catch (Exception e) {
LOG.error("Failure to load the Crowd manager", e);
}
}