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