本文整理汇总了Java中org.apache.commons.httpclient.params.HttpClientParams.setAuthenticationPreemptive方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientParams.setAuthenticationPreemptive方法的具体用法?Java HttpClientParams.setAuthenticationPreemptive怎么用?Java HttpClientParams.setAuthenticationPreemptive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.params.HttpClientParams
的用法示例。
在下文中一共展示了HttpClientParams.setAuthenticationPreemptive方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setConnectionAuthorization
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* Extracts all the required authorization for that particular URL request
* and sets it in the <code>HttpMethod</code> passed in.
*
* @param client the HttpClient object
*
* @param u
* <code>URL</code> of the URL request
* @param authManager
* the <code>AuthManager</code> containing all the authorisations for
* this <code>UrlConfig</code>
*/
private void setConnectionAuthorization(HttpClient client, URL u, AuthManager authManager) {
HttpState state = client.getState();
if (authManager != null) {
HttpClientParams params = client.getParams();
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()){
log.debug(username + " > D="+ username + " D="+domain+" R="+realm);
}
state.setCredentials(
new AuthScope(u.getHost(),u.getPort(),
realm.length()==0 ? null : realm //"" is not the same as no realm
,AuthScope.ANY_SCHEME),
// NT Includes other types of Credentials
new NTCredentials(
username,
auth.getPass(),
localHost,
domain
));
// We have credentials - should we set pre-emptive authentication?
if (canSetPreEmptive){
log.debug("Setting Pre-emptive authentication");
params.setAuthenticationPreemptive(true);
}
} else {
state.clearCredentials();
if (canSetPreEmptive){
params.setAuthenticationPreemptive(false);
}
}
} else {
state.clearCredentials();
}
}
示例2: Stubs
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public Stubs(ConfigurationContext ctx, String bbUrl) throws AxisFault
{
this.ctx = ctx;
this.bbUrl = bbUrl;
/*
* Must use deprecated class of setting up security because the SOAP
* response doesn't include a security header. Using the deprecated
* OutflowConfiguration class we can specify that the security
* header is only for the outgoing SOAP message.
*/
ofc = new OutflowConfiguration();
ofc.setActionItems("UsernameToken Timestamp");
ofc.setUser("session");
ofc.setPasswordType("PasswordText");
final MultiThreadedHttpConnectionManager conMan = new MultiThreadedHttpConnectionManager();
final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setMaxTotalConnections(1000);
params.setDefaultMaxConnectionsPerHost(100);
params.setSoTimeout(60000);
params.setConnectionTimeout(30000);
conMan.setParams(params);
httpClient = new HttpClient(conMan);
final HttpClientParams clientParams = httpClient.getParams();
clientParams.setAuthenticationPreemptive(false);
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
contextWebservice = new ContextWSStub(ctx, PathUtils.filePath(bbUrl, "webapps/ws/services/Context.WS"));
initStub(contextWebservice);
}
示例3: buildClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
* been created.
*
* @return the created client.
*/
public HttpClient buildClient() {
if (httpsProtocolSocketFactory != null) {
Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
clientParams.setContentCharset(getContentCharSet());
clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
connectionRetryAttempts, false));
HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
connMgrParams.setConnectionTimeout(getConnectionTimeout());
connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
connMgrParams.setSendBufferSize(getSendBufferSize());
connMgrParams.setTcpNoDelay(isTcpNoDelay());
MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
connMgr.setParams(connMgrParams);
HttpClient httpClient = new HttpClient(clientParams, connMgr);
if (proxyHost != null) {
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setProxy(proxyHost, proxyPort);
httpClient.setHostConfiguration(hostConfig);
if (proxyUsername != null) {
AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
proxyPassword);
httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
}
}
return httpClient;
}
示例4: setClientParams
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
@Override
protected void setClientParams(HttpClientParams params) {
super.setClientParams(params);
params.setAuthenticationPreemptive(true);
}
示例5: getCommonsHttpSolrServer
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {
HttpClient client=new HttpClient();
// Check for username/password
if (job.getBoolean(SolrConstants.USE_AUTH, false)) {
String username = job.get(SolrConstants.USERNAME);
LOG.info("Authenticating as: " + username);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));
HttpClientParams params = client.getParams();
params.setAuthenticationPreemptive(true);
client.setParams(params);
}
return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);
}
示例6: CrowdManager
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的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);
}
}
示例7: CrowdManager
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的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);
}
}