View Javadoc

1   /*
2    * $Id: StreamPayloadRequestEntity.java 10787 2008-02-12 18:51:50Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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 true;
35      }
36  
37      public void writeRequest(OutputStream outputStream) throws IOException
38      {
39          outputHandler.write(event, outputStream);
40      }
41  
42      public long getContentLength()
43      {
44          return -1L;
45      }
46  
47      public String getContentType()
48      {
49          return event.getMessage().getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, 
50              HttpConstants.DEFAULT_CONTENT_TYPE);
51      }
52  }
53