本文整理汇总了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);
}