本文整理匯總了Java中org.apache.commons.httpclient.auth.AuthScope.ANY_SCHEME屬性的典型用法代碼示例。如果您正苦於以下問題:Java AuthScope.ANY_SCHEME屬性的具體用法?Java AuthScope.ANY_SCHEME怎麽用?Java AuthScope.ANY_SCHEME使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.commons.httpclient.auth.AuthScope
的用法示例。
在下文中一共展示了AuthScope.ANY_SCHEME屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeHttpRequest
public static String makeHttpRequest(HttpMethod method, String username, String password)
{
try
{
HttpClient httpClient = new HttpClient();
AuthScope authScope = new AuthScope(method.getURI().getHost(), AuthScope.ANY_PORT, null,
AuthScope.ANY_SCHEME);
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(username, password));
httpClient.executeMethod(method);
return method.getResponseBodyAsString();
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
示例2: getCredentials
private Credentials getCredentials() {
Credentials credentials = null;
if (httpState != null) {
if (host != null) {
AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME);
credentials = httpState.getCredentials(authScope);
}
}
return credentials;
}
示例3: addAuth
@Override
public void addAuth(AuthCredentials creds) {
String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();
String realm = (StringUtils.isBlank(creds.getRealm()) || "*".equals(creds.getRealm())) ? AuthScope.ANY_REALM : creds.getRealm();
int port = NumberUtils.toInt(creds.getPortString(), AuthScope.ANY_PORT);
String scheme = creds.getScheme() != null ? creds.getScheme().getRepresentation() : AuthScope.ANY_SCHEME;
Credentials defaultcreds = new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword());
httpclient.getState().setCredentials(new AuthScope(host, port, realm, scheme), defaultcreds);
}
示例4: getCommonsHttpSolrServer
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);
}