View Javadoc

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