View Javadoc

1   /*
2    * $Id: HttpRequestToInputStream.java 12238 2008-07-06 22:13:50Z rossmason $
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.servlet;
12  
13  import org.mule.api.transformer.TransformerException;
14  import org.mule.transformer.AbstractDiscoverableTransformer;
15  
16  import java.io.IOException;
17  import java.io.InputStream;
18  
19  import javax.servlet.http.HttpServletRequest;
20  /**
21   * Converts an {@link javax.servlet.http.HttpServletRequest} into an {@link InputStream}.
22   */
23  public class HttpRequestToInputStream extends AbstractDiscoverableTransformer
24  {
25  
26      public HttpRequestToInputStream()
27      {
28          super();
29          setReturnClass(InputStream.class);
30          registerSourceType(HttpServletRequest.class);
31      }
32  
33      protected Object doTransform(Object src, String encoding) throws TransformerException
34      {
35          try
36          {
37              return ((HttpServletRequest) src).getInputStream();
38          }
39          catch (IOException e)
40          {
41              throw new TransformerException(this, e);
42          }
43      }
44  
45  }
46  
47