本文整理了Java中org.apache.commons.httpclient.HttpClient.getState()
方法的一些代码示例,展示了HttpClient.getState()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.getState()
方法的具体详情如下:
包路径:org.apache.commons.httpclient.HttpClient
类名称:HttpClient
方法名:getState
[英]Returns HttpState associated with the HttpClient.
[中]返回与HttpClient关联的HttpState。
代码示例来源:origin: jenkinsci/jenkins
Credentials credentials = createCredentials(userName, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, credentials);
代码示例来源:origin: openhab/openhab1-addons
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
if (StringUtils.isNotBlank(proxyUser)) {
client.getState().setProxyCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(proxyUser, proxyPassword));
if (credentials != null) {
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, credentials);
代码示例来源:origin: commons-httpclient/commons-httpclient
hostconfig,
this.params,
(state == null ? getState() : state));
methodDirector.executeMethod(method);
return method.getStatusCode();
代码示例来源:origin: geotools/geotools
private void resetCredentials() {
client.getState().clearCredentials();
if (user != null && password != null) {
AuthScope authscope = AuthScope.ANY;
Credentials credentials = new UsernamePasswordCredentials(user, password);
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(authscope, credentials);
} else {
client.getParams().setAuthenticationPreemptive(false);
}
}
代码示例来源:origin: geotools/geotools
private void resetCredentials() {
client.getState().clearCredentials();
if (user != null && password != null) {
AuthScope authscope = AuthScope.ANY;
Credentials credentials = new UsernamePasswordCredentials(user, password);
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(authscope, credentials);
} else {
client.getParams().setAuthenticationPreemptive(false);
}
}
代码示例来源:origin: KylinOLAP/Kylin
private void init(String host, int port, String userName, String password) {
this.host = host;
this.port = port;
this.userName = userName;
this.password = password;
this.baseUrl = "http://" + host + ":" + port + "/kylin/api";
client = new HttpClient();
if (userName != null && password != null) {
client.getParams().setAuthenticationPreemptive(true);
Credentials creds = new UsernamePasswordCredentials(userName, password);
client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), creds);
}
}
代码示例来源:origin: geotools/geotools
+ " setting proxy auth credentials");
HttpState state = client.getState();
if (state == null) {
state = new HttpState();
代码示例来源:origin: geotools/geotools
+ " setting proxy auth credentials");
HttpState state = client.getState();
if (state == null) {
state = new HttpState();
代码示例来源:origin: apache/cloudstack
public static InputStream getInputStreamFromUrl(String url, String user, String password) {
try {
Pair<String, Integer> hostAndPort = validateUrl(url);
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
}
// Execute the method.
GetMethod method = new GetMethod(url);
int statusCode = httpclient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
return method.getResponseBodyAsStream();
} catch (Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
代码示例来源:origin: apache/cloudstack
private void checkCredentials(String user, String password) {
try {
Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
if ((user != null) && (password != null)) {
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
} else {
s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
}
} catch (IllegalArgumentException iae) {
errorString = iae.getMessage();
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
inited = false;
}
}
代码示例来源:origin: apache/cloudstack
/**
* @param username
* @param password
* @param httpClient
*/
public static void setCredentials(String username, String password, HttpClient httpClient) {
if (username != null && password != null && httpClient != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
}
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(
new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
}
}
代码示例来源:origin: apache/cloudstack
private void checkProxy(Proxy proxy) {
if (proxy != null) {
client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
if (proxy.getUserName() != null) {
Credentials proxyCreds = new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword());
client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds);
}
}
}
代码示例来源:origin: apache/cloudstack
/**
* @param proxy
* @param httpClient
*/
public static void setProxy(Proxy proxy, HttpClient httpClient) {
if (proxy != null && httpClient != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Setting proxy with host " + proxy.getHost() + " and port " + proxy.getPort() + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
}
httpClient.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
if (proxy.getUserName() != null && proxy.getPassword() != null) {
httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()));
}
}
}
代码示例来源:origin: naver/ngrinder
@Ignore
@Test
public void testRestAPI() throws IOException {
HttpClient client = new HttpClient();
// To be avoided unless in debug mode
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "111111");
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
PutMethod method = new PutMethod("http://localhost:8080/agent/api/36");
final HttpMethodParams params = new HttpMethodParams();
params.setParameter("action", "approve");
method.setParams(params);
final int i = client.executeMethod(method);
System.out.println(method.getResponseBodyAsString());
}
}
代码示例来源:origin: org.phenotips/xwiki-platform-test-overrides
public TestUtils()
{
this.adminHTTPClient = new HttpClient();
this.adminHTTPClient.getState().setCredentials(AuthScope.ANY, ADMIN_CREDENTIALS);
this.adminHTTPClient.getParams().setAuthenticationPreemptive(true);
}
代码示例来源:origin: com.github.bingoohuang/diamond-client
private void setBasicAuth(String host, int port) {
String basicAuth = ClientProperties.getBasicAuth();
if (Strings.isNullOrEmpty(basicAuth)) return;
List<String> splits = Splitter.on(':').trimResults().splitToList(basicAuth);
if (splits.size() < 2) return;
String userName = splits.get(0);
String passWord = splits.get(1);
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials credentials = new UsernamePasswordCredentials(userName, passWord);
AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
httpClient.getState().setCredentials(authScope, credentials);
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui
public TestUtils()
{
this.httpClient = new HttpClient();
this.httpClient.getState().setCredentials(AuthScope.ANY, SUPER_ADMIN_CREDENTIALS);
this.httpClient.getParams().setAuthenticationPreemptive(true);
this.rest = new RestTestUtils(this);
}
代码示例来源:origin: io.hawt/hawtio-system
public HttpClient createHttpClient(HttpMethod httpMethodProxyRequest) {
HttpClient client = new HttpClient();
if (userName != null) {
//client.getParams().setAuthenticationPreemptive(true);
httpMethodProxyRequest.setDoAuthentication(true);
Credentials defaultcreds = new UsernamePasswordCredentials(userName, password);
client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds);
}
return client;
}
代码示例来源:origin: org.codehaus.sonar/sonar-ws-client
private void configureCredentials() {
if (server.getUsername() != null) {
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());
httpClient.getState().setCredentials(AuthScope.ANY, defaultcreds);
}
}
代码示例来源:origin: org.n52.security/52n-security-facade
private void initHttpClient() {
m_client = new HttpClient();
ProxyManager proxyManager = new ProxyManager();
ProxyHost proxy = proxyManager.getProxyHost(m_endpointUrl);
if (proxy != null) {
LOG.debug("for server " + getURL() + " using proxy: '" + proxy.getHostName() + "'");
} else {
LOG.debug("for server " + getURL() + " not using proxy!");
}
m_client.getHostConfiguration().setProxyHost(proxy);
m_client.getState().setProxyCredentials(AuthScope.ANY, proxyManager.getProxyCredentials(getURL()));
}
内容来源于网络,如有侵权,请联系作者删除!