View Javadoc

1   /*
2    * $Id: HttpContinueFunctionalTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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.tck.FunctionalTestCase;
17  import org.mule.transport.http.HttpConnector;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.httpclient.HttpVersion;
23  import org.apache.commons.httpclient.params.HttpClientParams;
24  import org.apache.commons.lang.time.StopWatch;
25  
26  public class HttpContinueFunctionalTestCase extends DynamicPortTestCase
27  {
28      /**
29       * HttpClient has default 3 seconds wait for Expect-Continue calls.
30       */
31      private static final int DEFAULT_HTTP_CLIENT_CONTINUE_WAIT = 3000;
32  
33      protected StopWatch stopWatch;
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "http-functional-test.xml";
39      }
40  
41      public void testSendWithContinue() throws Exception
42      {
43          stopWatch = new StopWatch();
44          MuleClient client = new MuleClient(muleContext);
45          
46          //Need to use Http1.1 for Expect: Continue
47          HttpClientParams params = new HttpClientParams();
48          params.setVersion(HttpVersion.HTTP_1_1);
49          params.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, true);
50  
51          Map<String, Object> props = new HashMap<String, Object>();
52          props.put(HttpConnector.HTTP_PARAMS_PROPERTY, params);
53  
54          stopWatch.start();
55          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
56          stopWatch.stop();
57  
58          assertNotNull(result);
59          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
60  
61          if (stopWatch.getTime() > DEFAULT_HTTP_CLIENT_CONTINUE_WAIT)
62          {
63              fail("Server did not handle Expect=100-continue header properly,");
64          }
65      }
66  
67      @Override
68      protected int getNumPortsToFind()
69      {
70  
71          return 1;
72      }
73  }