1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.servlet; |
11 | |
|
12 | |
import org.mule.api.transformer.TransformerException; |
13 | |
import org.mule.transformer.AbstractDiscoverableTransformer; |
14 | |
|
15 | |
import java.io.IOException; |
16 | |
|
17 | |
import javax.servlet.http.HttpServletRequest; |
18 | |
|
19 | |
import org.apache.commons.io.IOUtils; |
20 | |
import org.apache.commons.io.output.ByteArrayOutputStream; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class HttpRequestToByteArray extends AbstractDiscoverableTransformer |
27 | |
{ |
28 | |
|
29 | |
public HttpRequestToByteArray() |
30 | 0 | { |
31 | 0 | registerSourceType(HttpServletRequest.class); |
32 | 0 | setReturnClass(byte[].class); |
33 | 0 | } |
34 | |
|
35 | |
protected Object doTransform(Object src, String encoding) throws TransformerException |
36 | |
{ |
37 | 0 | ByteArrayOutputStream baos = new ByteArrayOutputStream(8192); |
38 | |
try |
39 | |
{ |
40 | 0 | IOUtils.copy(((HttpServletRequest) src).getInputStream(), baos); |
41 | |
} |
42 | 0 | catch (IOException e) |
43 | |
{ |
44 | 0 | throw new TransformerException(this, e); |
45 | 0 | } |
46 | 0 | return baos.toByteArray(); |
47 | |
} |
48 | |
|
49 | |
} |