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;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.transport.OutputHandler;
11  
12  import java.io.IOException;
13  import java.io.OutputStream;
14  
15  import org.apache.commons.httpclient.methods.RequestEntity;
16  
17  public class StreamPayloadRequestEntity implements RequestEntity
18  {
19      private OutputHandler outputHandler;
20      private MuleEvent event;
21  
22      public StreamPayloadRequestEntity(OutputHandler outputHandler, MuleEvent event)
23      {
24          this.outputHandler = outputHandler;
25          this.event = event;
26      }
27  
28      public boolean isRepeatable()
29      {
30          return false;
31      }
32  
33      public void writeRequest(OutputStream outputStream) throws IOException
34      {
35          outputHandler.write(event, outputStream);
36          outputStream.flush();
37      }
38  
39      public long getContentLength()
40      {
41          return -1L;
42      }
43  
44      public String getContentType()
45      {
46          return event.getMessage().getOutboundProperty(HttpConstants.HEADER_CONTENT_TYPE, HttpConstants.DEFAULT_CONTENT_TYPE);
47      }
48  }
49