use of org.apache.commons.httpclient.HostConfiguration in project pinpoint by naver.
the class HttpClientIT method hostConfig.
@Test
public void hostConfig() throws Exception {
HttpClient client = new HttpClient();
client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
client.getParams().setSoTimeout(SO_TIMEOUT);
HostConfiguration config = new HostConfiguration();
config.setHost("weather.naver.com", 80, "http");
GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn");
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });
try {
// Execute the method.
client.executeMethod(config, method);
} catch (Exception ignored) {
} finally {
method.releaseConnection();
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
}
use of org.apache.commons.httpclient.HostConfiguration in project zaproxy by zaproxy.
the class HttpSender method executeMethod.
public int executeMethod(HttpMethod method, HttpState state) throws IOException {
int responseCode = -1;
String hostName;
hostName = method.getURI().getHost();
method.setDoAuthentication(true);
HostConfiguration hc = null;
HttpClient requestClient;
if (isConnectionUpgrade(method)) {
requestClient = new HttpClient(new ZapHttpConnectionManager());
if (param.isUseProxy(hostName)) {
requestClient.getHostConfiguration().setProxy(param.getProxyChainName(), param.getProxyChainPort());
if (param.isUseProxyChainAuth()) {
requestClient.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param));
}
}
} else if (param.isUseProxy(hostName)) {
requestClient = clientViaProxy;
} else {
requestClient = client;
}
if (this.initiator == CHECK_FOR_UPDATES_INITIATOR) {
// Use the 'strict' SSLConnector, ie one that performs all the usual cert checks
// The 'standard' one 'trusts' everything
// This is to ensure that all 'check-for update' calls are made to the expected https urls
// without this is would be possible to intercept and change the response which could result
// in the user downloading and installing a malicious add-on
hc = new HostConfiguration() {
@Override
public synchronized void setHost(URI uri) {
try {
setHost(new HttpHost(uri.getHost(), uri.getPort(), getProtocol()));
} catch (URIException e) {
throw new IllegalArgumentException(e.toString());
}
}
;
};
hc.setHost(hostName, method.getURI().getPort(), new Protocol("https", (ProtocolSocketFactory) new SSLConnector(false), 443));
if (param.isUseProxy(hostName)) {
hc.setProxyHost(new ProxyHost(param.getProxyChainName(), param.getProxyChainPort()));
if (param.isUseProxyChainAuth()) {
requestClient.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param));
}
}
}
// ZAP: Check if a custom state is being used
if (state != null) {
// Make sure cookies are enabled
method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
}
responseCode = requestClient.executeMethod(hc, method, state);
return responseCode;
}
use of org.apache.commons.httpclient.HostConfiguration in project maven-plugins by apache.
the class ClassicJiraDownloader method doExecute.
/**
* Execute the query on the JIRA server.
*
* @throws Exception on error
*/
public void doExecute() throws Exception {
try {
HttpClient client = new HttpClient();
// MCHANGES-89 Allow circular redirects
HttpClientParams clientParams = client.getParams();
clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// MCHANGES-237
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpState state = new HttpState();
HostConfiguration hc = new HostConfiguration();
client.setHostConfiguration(hc);
client.setState(state);
String baseUrl = JiraHelper.getBaseUrl(project.getIssueManagement().getUrl());
getLog().debug("JIRA lives at: " + baseUrl);
// Here we only need the host part of the URL
determineProxy(baseUrl, client);
prepareBasicAuthentication(client);
boolean jiraAuthenticationSuccessful = false;
if (isJiraAuthenticationConfigured()) {
// Here we only need the parts up to and including the host part of the URL
jiraAuthenticationSuccessful = doJiraAuthentication(client, baseUrl);
}
if ((isJiraAuthenticationConfigured() && jiraAuthenticationSuccessful) || !isJiraAuthenticationConfigured()) {
String fullUrl;
if (useJql) {
fullUrl = getJqlQueryURL();
} else {
fullUrl = getParameterBasedQueryURL(client);
}
if (log.isDebugEnabled()) {
log.debug("download jira issues from url " + fullUrl);
}
// execute the GET
download(client, fullUrl);
}
} catch (Exception e) {
if (project.getIssueManagement() != null) {
getLog().error("Error accessing " + project.getIssueManagement().getUrl(), e);
} else {
getLog().error("Error accessing mock project issues", e);
}
}
}
Aggregations