@Test(expected = ConnectTimeoutException.class)
 public void testConnectionTimeout() throws Exception {
   CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
   messageSender.setConnectionTimeout(1);
   WebServiceConnection connection =
       messageSender.createConnection(new URI("http://example.com/"));
   WebServiceMessage message = new MockWebServiceMessage();
   connection.send(message);
 }
 @Test
 public void testMaxConnections() throws URISyntaxException, URIException {
   CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
   messageSender.setMaxTotalConnections(2);
   Map<String, String> maxConnectionsPerHost = new HashMap<String, String>();
   maxConnectionsPerHost.put("https://www.example.com", "1");
   maxConnectionsPerHost.put("http://www.example.com:8080", "7");
   maxConnectionsPerHost.put("www.springframework.org", "10");
   maxConnectionsPerHost.put("*", "5");
   messageSender.setMaxConnectionsPerHost(maxConnectionsPerHost);
 }
  @Test
  public void testContextClose() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    int port = FreePortScanner.getFreePort();
    Server jettyServer = new Server(port);
    Context jettyContext = new Context(jettyServer, "/");
    jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/");
    jettyServer.start();
    WebServiceConnection connection = null;
    try {

      StaticApplicationContext appContext = new StaticApplicationContext();
      appContext.registerSingleton("messageSender", CommonsHttpMessageSender.class);
      appContext.refresh();

      CommonsHttpMessageSender messageSender =
          appContext.getBean("messageSender", CommonsHttpMessageSender.class);
      connection = messageSender.createConnection(new URI("http://localhost:" + port));

      appContext.close();

      connection.send(new SaajSoapMessage(messageFactory.createMessage()));
      connection.receive(new SaajSoapMessageFactory(messageFactory));
    } finally {
      if (connection != null) {
        try {
          connection.close();
        } catch (IOException ex) {
          // ignore
        }
      }
      if (jettyServer.isRunning()) {
        jettyServer.stop();
      }
    }
  }