Browse Source

Allow user to set system properties to control http client in zuul

The SimpleHostRoutingFilter now accepts normal -Dhttps.proxy= and
-Dhttps.port= settings (and other things that generally work with
java.net).

Fixes gh-510
pull/6/head
Dave Syer 9 years ago
parent
commit
f094ecfd88
  1. 19
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java

19
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java

@ -181,8 +181,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter { @@ -181,8 +181,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
setResponse(response);
}
catch (Exception ex) {
context.set(ERROR_STATUS_CODE,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
context.set(ERROR_STATUS_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
context.set("error.exception", ex);
}
return null;
@ -211,7 +210,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter { @@ -211,7 +210,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.INSTANCE);
if (sslHostnameValidationEnabled) {
if (this.sslHostnameValidationEnabled) {
registryBuilder.register("https",
new SSLConnectionSocketFactory(sslContext));
}
@ -240,24 +239,24 @@ public class SimpleHostRoutingFilter extends ZuulFilter { @@ -240,24 +239,24 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpClientBuilder httpClientBuilder = HttpClients.custom();
if (!sslHostnameValidationEnabled) {
if (!this.sslHostnameValidationEnabled) {
httpClientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}
return httpClientBuilder.setConnectionManager(newConnectionManager())
.setDefaultRequestConfig(requestConfig)
.useSystemProperties().setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
.setRedirectStrategy(new RedirectStrategy() {
@Override
public boolean isRedirected(HttpRequest request,
HttpResponse response, HttpContext context)
throws ProtocolException {
throws ProtocolException {
return false;
}
@Override
public HttpUriRequest getRedirect(HttpRequest request,
HttpResponse response, HttpContext context)
throws ProtocolException {
throws ProtocolException {
return null;
}
}).build();
@ -266,7 +265,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter { @@ -266,7 +265,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
private HttpResponse forward(HttpClient httpclient, String verb, String uri,
HttpServletRequest request, MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity)
throws Exception {
throws Exception {
Map<String, Object> info = this.helper.debug(verb, uri, headers, params,
requestEntity);
URL host = RequestContext.getCurrentContext().getRouteHost();
@ -380,9 +379,9 @@ public class SimpleHostRoutingFilter extends ZuulFilter { @@ -380,9 +379,9 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
/**
* Determines whether the filter enables the validation for ssl hostnames.
* @return
* @return true if enabled
*/
boolean isSslHostnameValidationEnabled() {
return sslHostnameValidationEnabled;
return this.sslHostnameValidationEnabled;
}
}

Loading…
Cancel
Save