@ -63,6 +63,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
@@ -63,6 +63,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients ;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager ;
import org.apache.http.message.BasicHeader ;
import org.apache.http.message.BasicHttpEntityEnclosingRequest ;
import org.apache.http.message.BasicHttpRequest ;
import org.apache.http.protocol.HttpContext ;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper ;
@ -271,11 +272,33 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
@@ -271,11 +272,33 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
URL host = RequestContext . getCurrentContext ( ) . getRouteHost ( ) ;
HttpHost httpHost = getHttpHost ( host ) ;
uri = StringUtils . cleanPath ( ( host . getPath ( ) + uri ) . replaceAll ( "/{2,}" , "/" ) ) ;
HttpRequest httpRequest ;
int contentLength = request . getContentLength ( ) ;
InputStreamEntity entity = new InputStreamEntity ( requestEntity , contentLength ,
request . getContentType ( ) ! = null
? ContentType . create ( request . getContentType ( ) ) : null ) ;
HttpRequest httpRequest = buildHttpRequest ( verb , uri , entity , headers , params ) ;
try {
log . debug ( httpHost . getHostName ( ) + " " + httpHost . getPort ( ) + " "
+ httpHost . getSchemeName ( ) ) ;
HttpResponse zuulResponse = forwardRequest ( httpclient , httpHost , httpRequest ) ;
this . helper . appendDebug ( info , zuulResponse . getStatusLine ( ) . getStatusCode ( ) ,
revertHeaders ( zuulResponse . getAllHeaders ( ) ) ) ;
return zuulResponse ;
}
finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpclient.getConnectionManager().shutdown();
}
}
protected HttpRequest buildHttpRequest ( String verb , String uri , InputStreamEntity entity ,
MultiValueMap < String , String > headers , MultiValueMap < String , String > params )
{
HttpRequest httpRequest ;
switch ( verb . toUpperCase ( ) ) {
case "POST" :
HttpPost httpPost = new HttpPost ( uri + this . helper . getQueryString ( params ) ) ;
@ -292,26 +315,20 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
@@ -292,26 +315,20 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
httpRequest = httpPatch ;
httpPatch . setEntity ( entity ) ;
break ;
case "DELETE" :
BasicHttpEntityEnclosingRequest entityRequest = new BasicHttpEntityEnclosingRequest ( verb ,
uri + this . helper . getQueryString ( params ) ) ;
httpRequest = entityRequest ;
entityRequest . setEntity ( entity ) ;
break ;
default :
httpRequest = new BasicHttpRequest ( verb ,
uri + this . helper . getQueryString ( params ) ) ;
log . debug ( uri + this . helper . getQueryString ( params ) ) ;
}
try {
httpRequest . setHeaders ( convertHeaders ( headers ) ) ;
log . debug ( httpHost . getHostName ( ) + " " + httpHost . getPort ( ) + " "
+ httpHost . getSchemeName ( ) ) ;
HttpResponse zuulResponse = forwardRequest ( httpclient , httpHost , httpRequest ) ;
this . helper . appendDebug ( info , zuulResponse . getStatusLine ( ) . getStatusCode ( ) ,
revertHeaders ( zuulResponse . getAllHeaders ( ) ) ) ;
return zuulResponse ;
}
finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpclient.getConnectionManager().shutdown();
}
return httpRequest ;
}
private MultiValueMap < String , String > revertHeaders ( Header [ ] headers ) {