use of org.apache.commons.httpclient.ProxyHost in project tdq-studio-se by Talend.
the class EcosystemProxyAdapter method adapt.
/**
* DOC bZhou Comment method "adapt".
*
* @param httpclient
* @param url
*/
public static void adapt(HttpClient httpclient, String url) {
IProxyService proxyService = EcosPlugin.getDefault().getProxyService();
IProxyData proxyData = null;
try {
IProxyData[] proxyDatas = proxyService.select(new URI(url));
if (proxyDatas != null && proxyDatas.length > 0) {
proxyData = proxyDatas[0];
}
} catch (URISyntaxException e) {
log.error(e, e);
}
if (proxyData == null) {
proxyData = proxyService.getProxyData(IProxyData.HTTP_PROXY_TYPE);
}
if (proxyData != null & StringUtils.isNotEmpty(proxyData.getHost())) {
// use proxy to connect
ProxyHost host = new ProxyHost(proxyData.getHost(), proxyData.getPort());
httpclient.getHostConfiguration().setProxyHost(host);
httpclient.getParams().setAuthenticationPreemptive(true);
String userId = proxyData.getUserId();
if (StringUtils.isNotEmpty(userId)) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userId, proxyData.getPassword());
httpclient.getState().setProxyCredentials(AuthScope.ANY, credentials);
}
}
}
use of org.apache.commons.httpclient.ProxyHost in project jaggery by wso2.
the class XMLHttpRequestHostObject method executeRequest.
private static void executeRequest(Context cx, XMLHttpRequestHostObject xhr) throws ScriptException {
try {
String host = xhr.method.getURI().getHost();
ProxyHost proxyHost = getProxyConfig(host);
xhr.httpClient.getHostConfiguration().setProxyHost(proxyHost);
xhr.httpClient.executeMethod(xhr.method);
xhr.statusLine = xhr.method.getStatusLine();
xhr.responseHeaders = xhr.method.getResponseHeaders();
updateReadyState(cx, xhr, HEADERS_RECEIVED);
byte[] response = xhr.method.getResponseBody();
if (response != null) {
if (response.length > 0) {
xhr.responseText = new String(response);
}
}
Header contentType = xhr.method.getResponseHeader("Content-Type");
if (contentType != null) {
xhr.responseType = contentType.getValue();
}
updateReadyState(cx, xhr, DONE);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} finally {
xhr.method.releaseConnection();
}
}
use of org.apache.commons.httpclient.ProxyHost in project jaggery by wso2.
the class XMLHttpRequestHostObject method getProxyConfig.
private static ProxyHost getProxyConfig(String host) {
ProxyHost proxyConfig = null;
String proxyHost = System.getProperty(HTTP_PROXY_HOST);
String proxyPortStr = System.getProperty(HTTP_PROXY_PORT);
String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
if (isHostInNonProxyList(host, nonProxyHosts)) {
return null;
}
int proxyPort = -1;
if (proxyHost != null) {
proxyHost = proxyHost.trim();
}
if (proxyPortStr != null) {
try {
proxyPort = Integer.parseInt(proxyPortStr);
if (!proxyHost.isEmpty()) {
proxyConfig = new ProxyHost(proxyHost, proxyPort);
}
} catch (NumberFormatException e) {
log.error(e.getMessage(), e);
}
}
return proxyConfig;
}
use of org.apache.commons.httpclient.ProxyHost 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());
setProxyAuth(requestClient);
}
} else if (param.isUseProxy(hostName)) {
requestClient = clientViaProxy;
} else {
requestClient = client;
}
if (this.initiator == CHECK_FOR_UPDATES_INITIATOR) {
// Use the 'strict' SSLConnector, i.e. 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()));
setProxyAuth(requestClient);
}
}
method.getParams().setBooleanParameter(HttpMethodDirector.PARAM_RESOLVE_HOSTNAME, param.shouldResolveRemoteHostname(hostName));
// ZAP: Check if a custom state is being used
if (state != null) {
// Make sure cookies are enabled
method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
setProxyAuth(state);
}
responseCode = requestClient.executeMethod(hc, method, state);
return responseCode;
}
Aggregations