View Javadoc

1   /*
2    * $Id: HttpContinueFunctionalTestCase.java 20297 2010-11-22 18:49:18Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.http.functional;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  import org.mule.transport.http.HttpConnector;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.commons.httpclient.HttpVersion;
22  import org.apache.commons.httpclient.params.HttpClientParams;
23  import org.apache.commons.lang.time.StopWatch;
24  
25  public class HttpContinueFunctionalTestCase extends DynamicPortTestCase
26  {
27      /**
28       * HttpClient has default 3 seconds wait for Expect-Continue calls.
29       */
30      private static final int DEFAULT_HTTP_CLIENT_CONTINUE_WAIT = 3000;
31  
32      protected StopWatch stopWatch;
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "http-functional-test.xml";
38      }
39  
40      public void testSendWithContinue() throws Exception
41      {
42          stopWatch = new StopWatch();
43          MuleClient client = new MuleClient(muleContext);
44          
45          //Need to use Http1.1 for Expect: Continue
46          HttpClientParams params = new HttpClientParams();
47          params.setVersion(HttpVersion.HTTP_1_1);
48          params.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, true);
49  
50          Map<String, Object> props = new HashMap<String, Object>();
51          props.put(HttpConnector.HTTP_PARAMS_PROPERTY, params);
52  
53          stopWatch.start();
54          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
55          stopWatch.stop();
56  
57          assertNotNull(result);
58          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
59  
60          if (stopWatch.getTime() > DEFAULT_HTTP_CLIENT_CONTINUE_WAIT)
61          {
62              fail("Server did not handle Expect=100-continue header properly,");
63          }
64      }
65  
66      @Override
67      protected int getNumPortsToFind()
68      {
69  
70          return 1;
71      }
72  }