1616
1717package org .springframework .ws .transport .http ;
1818
19+ import static org .hamcrest .core .IsEqual .*;
20+ import static org .springframework .test .util .MatcherAssertionErrors .*;
21+
1922import java .io .IOException ;
2023import java .net .URI ;
2124import java .net .URISyntaxException ;
2831import javax .xml .soap .MessageFactory ;
2932
3033import org .apache .commons .httpclient .URIException ;
34+ import org .apache .http .HttpHost ;
35+ import org .apache .http .conn .routing .HttpRoute ;
36+ import org .apache .http .impl .conn .PoolingClientConnectionManager ;
3137import org .junit .Test ;
3238import org .mortbay .jetty .Server ;
3339import org .mortbay .jetty .servlet .Context ;
@@ -49,13 +55,43 @@ protected AbstractHttpWebServiceMessageSender createMessageSender() {
4955
5056 @ Test
5157 public void testMaxConnections () throws URISyntaxException , URIException {
58+ final String url1 = "https://www.example.com" ;
59+ URI uri1 = new URI (url1 );
60+ HttpHost host1 = new HttpHost (uri1 .getHost (), uri1 .getPort (), uri1 .getScheme ());
61+ HttpRoute route1 = new HttpRoute (host1 , null , true );
62+ assertThat (route1 .isSecure (), equalTo (true ));
63+ assertThat (route1 .getTargetHost ().getHostName (), equalTo ("www.example.com" ));
64+ assertThat (route1 .getTargetHost ().getPort (), equalTo (-1 ));
65+
66+ final String url2 = "http://www.example.com:8080" ;
67+ URI uri2 = new URI (url2 );
68+ HttpHost host2 = new HttpHost (uri2 .getHost (), uri2 .getPort (), uri2 .getScheme ());
69+ HttpRoute route2 = new HttpRoute (host2 );
70+ assertThat (route2 .isSecure (), equalTo (false ));
71+ assertThat (route2 .getTargetHost ().getHostName (), equalTo ("www.example.com" ));
72+ assertThat (route2 .getTargetHost ().getPort (), equalTo (8080 ));
73+
74+ final String url3 = "http://www.springframework.org" ;
75+ URI uri3 = new URI (url3 );
76+ HttpHost host3 = new HttpHost (uri3 .getHost (), uri3 .getPort (), uri3 .getScheme ());
77+ HttpRoute route3 = new HttpRoute (host3 );
78+ assertThat (route3 .isSecure (), equalTo (false ));
79+ assertThat (route3 .getTargetHost ().getHostName (), equalTo ("www.springframework.org" ));
80+ assertThat (route3 .getTargetHost ().getPort (), equalTo (-1 ));
81+
5282 HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender ();
5383 messageSender .setMaxTotalConnections (2 );
5484 Map <String , String > maxConnectionsPerHost = new HashMap <String , String >();
55- maxConnectionsPerHost .put ("https://www.example.com" , "1" );
56- maxConnectionsPerHost .put ("http://www.example.com:8080" , "7" );
57- maxConnectionsPerHost .put ("http://www.springframework.org" , "10" );
85+ maxConnectionsPerHost .put (url1 , "1" );
86+ maxConnectionsPerHost .put (url2 , "7" );
87+ maxConnectionsPerHost .put (url3 , "10" );
5888 messageSender .setMaxConnectionsPerHost (maxConnectionsPerHost );
89+
90+ PoolingClientConnectionManager poolingClientConnectionManager =
91+ (PoolingClientConnectionManager ) messageSender .getHttpClient ().getConnectionManager ();
92+ assertThat (poolingClientConnectionManager .getMaxPerRoute (route1 ), equalTo (1 ));
93+ assertThat (poolingClientConnectionManager .getMaxPerRoute (route2 ), equalTo (7 ));
94+ assertThat (poolingClientConnectionManager .getMaxPerRoute (route3 ), equalTo (10 ));
5995 }
6096
6197 @ Test
0 commit comments