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.servlet.transformers;
8   
9   import org.mule.api.transformer.TransformerException;
10  import org.mule.transformer.AbstractDiscoverableTransformer;
11  import org.mule.transformer.types.DataTypeFactory;
12  
13  import java.io.IOException;
14  import java.io.InputStream;
15  
16  import javax.servlet.http.HttpServletRequest;
17  
18  /**
19   * Converts a {@link HttpServletRequest} into an {@link InputStream}.
20   */
21  public class HttpRequestToInputStream extends AbstractDiscoverableTransformer
22  {
23      public HttpRequestToInputStream()
24      {
25          super();
26          registerSourceType(DataTypeFactory.create(HttpServletRequest.class));
27          setReturnDataType(DataTypeFactory.INPUT_STREAM);
28      }
29  
30      @Override
31      protected Object doTransform(Object src, String outputEncoding) throws TransformerException
32      {
33          try
34          {
35              return ((HttpServletRequest) src).getInputStream();
36          }
37          catch (IOException e)
38          {
39              throw new TransformerException(this, e);
40          }
41      }
42  }
43  
44