private String getRealUrl(HttpContext httpContext){ Object target = httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); Object reqUri = httpContext.getAttribute(HttpCoreContext.HTTP_REQUEST); if (target==null||reqUri==null){ return null; } HttpHost t = (HttpHost) target; HttpUriRequest r = (HttpUriRequest)reqUri; return r.getURI().isAbsolute()?r.getURI().toString():t.toString()+r.getURI().toString(); } }
final HttpHost proxyHost = new HttpHost(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()); httpRoutePlanner = new DefaultProxyRoutePlanner(proxyHost); proxyString = proxyHost.toString(); if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername()) || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) { credentialsProvider.setCredentials(new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()),
/** * {@inheritDoc} */ @Override public String toString() { return httpHost.toString(); }
public void recoverRemovedNodes(List<HttpHost> hosts) { if(hosts == null || hosts.size() == 0){ return; } for(HttpHost httpHost: hosts) { ESAddress address = this.addressMap.get(httpHost.toString()); if(address != null ){ if(address.getStatus() == 2){//节点还原 address.onlySetStatus(0); } } } }
logger.debug("ProxyHost: " + proxy.toString());
logger.debug("ProxyHost: " + proxy.toString());
public void recoverRemovedNodes(List<HttpHost> hosts) { if(hosts == null || hosts.size() == 0){ return; } for(HttpHost httpHost: hosts) { ESAddress address = this.addressMap.get(httpHost.toString()); if(address != null ){ if(address.getStatus() == 2){//节点还原 address.onlySetStatus(0); } } } }
logger.debug("ProxyHost: " + proxy.toString());
@Override protected void prepareRequest(HttpHost target, HttpRequest request) throws ClientProtocolException { super.prepareRequest(target, request); String key = target.toString(); synchronized (routedHosts) { if (!routedHosts.contains(key)) { String group = ".*"; for (String searchGroup : groupLimits.keySet()) { if (key.matches(searchGroup) && searchGroup.length() > group.length()) { group = searchGroup; } } int maxRequests = groupLimits.get(group); LOG.debug("IO download host: {}; rule: {}, maxRequests: {}", key, group, maxRequests); routedHosts.add(key); HttpRoute httpRoute = new HttpRoute(target); connManager.setMaxPerRoute(httpRoute, maxRequests); } } }
private void handleDiscoverHosts(List<HttpHost> hosts){ List<ESAddress> newAddress = new ArrayList<ESAddress>(); //恢复移除节点 elasticSearchRestClient.recoverRemovedNodes(hosts); //识别新增节点 for(int i = 0; i < hosts.size();i ++){ ESAddress address = new ESAddress(hosts.get(i).toString()); if(!elasticSearchRestClient.containAddress(address)){ newAddress.add(address); } } //处理新增节点 if(newAddress.size() > 0) { if (logger.isInfoEnabled()) { logger.info(new StringBuilder().append("Discovery new elasticsearch server[").append(newAddress).append("].").toString()); } elasticSearchRestClient.addAddresses(newAddress); } //处理删除节点 elasticSearchRestClient.handleRemoved( hosts); } @Override
private void handleDiscoverHosts(List<HttpHost> hosts){ List<ESAddress> newAddress = new ArrayList<ESAddress>(); //恢复移除节点 elasticSearchRestClient.recoverRemovedNodes(hosts); //识别新增节点 for(int i = 0; i < hosts.size();i ++){ ESAddress address = new ESAddress(hosts.get(i).toString()); if(!elasticSearchRestClient.containAddress(address)){ newAddress.add(address); } } //处理新增节点 if(newAddress.size() > 0) { if (logger.isInfoEnabled()) { logger.info(new StringBuilder().append("Discovery new elasticsearch server[").append(newAddress).append("].").toString()); } elasticSearchRestClient.addAddresses(newAddress); } //处理删除节点 elasticSearchRestClient.handleRemoved( hosts); } @Override
public HttpComponentsRamlRequest(HttpHost host, HttpRequest request) { this.request = request; path = UriComponents.fromHttpUrl(request.getRequestLine().getUri()).getPath(); url = host.toString() + request.getRequestLine().getUri(); }
boolean exist = false; for (HttpHost httpHost : hosts) { if (httpHost.toString().equals(host)) { exist = true; break;
public HttpComponentsRamlRequest(HttpHost host, HttpRequest request) { this.request = request; path = UriComponents.fromHttpUrl(request.getRequestLine().getUri()).getPath(); url = host.toString() + request.getRequestLine().getUri(); }
boolean exist = false; for (HttpHost httpHost : hosts) { if (httpHost.toString().equals(host)) { exist = true; break;
/** * For a given {@link HttpHost} and {@link HttpRequest} get a URI from the * pair that I can use as an identifier KEY into my HttpCache * * @param host The host for this request * @param req the {@link HttpRequest} * @return String the extracted URI */ public String getURI(final HttpHost host, final HttpRequest req) { if (isRelativeRequest(req)) { return canonicalizeUri(String.format("%s%s", host.toString(), req.getRequestLine().getUri())); } return canonicalizeUri(req.getRequestLine().getUri()); }
/** * For a given {@link HttpHost} and {@link HttpRequest} get a URI from the * pair that I can use as an identifier KEY into my HttpCache * * @param host The host for this request * @param req the {@link HttpRequest} * @return String the extracted URI */ public String getURI(HttpHost host, HttpRequest req) { if (isRelativeRequest(req)) { return canonicalizeUri(String.format("%s%s", host.toString(), req.getRequestLine().getUri())); } return canonicalizeUri(req.getRequestLine().getUri()); }
private void sendRequestThruProxy() throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext; sslContext = SSLContexts.custom().loadTrustMaterial((chain, authType) -> true).build(); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new String[] {"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}, null, NoopHostnameVerifier.INSTANCE); try (CloseableHttpClient httpClient = HttpClients.custom() .setSSLSocketFactory(sslConnectionSocketFactory) .build()) { HttpHost target = new HttpHost(BurpClientIT.TARGET_HOST); HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT, PROXY_SCHEME); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); HttpGet request = new HttpGet("/"); request.setConfig(config); log.info("Executing request {} to {} via {} proxy", request.getRequestLine(), target.toString(), proxy.toString()); httpClient.execute(target, request); } } }
public HttpRequest generateRequest(final HttpContext context) throws IOException, HttpException { HttpHost target = this.route.getTargetHost(); HttpRequest connect = new BasicHttpRequest("CONNECT", target.toHostString(), HttpVersion.HTTP_1_1); connect.setHeader(HttpHeaders.HOST, target.toHostString()); this.httpProcessor.process(connect, context); context.setAttribute(SynapseHTTPRequestFactory.ENDPOINT_URL, target.toString()); return connect; }