1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.transformer; |
12 | |
|
13 | |
import org.mule.api.transformer.TransformerException; |
14 | |
import org.mule.config.i18n.MessageFactory; |
15 | |
import org.mule.transformer.AbstractTransformer; |
16 | |
import org.mule.util.IOUtils; |
17 | |
|
18 | |
import java.io.InputStream; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | 0 | public class ValidateResponse extends AbstractTransformer |
24 | |
{ |
25 | |
@Override |
26 | |
protected Object doTransform(Object src, String encoding) throws TransformerException |
27 | |
{ |
28 | 0 | String response = null; |
29 | 0 | if (src instanceof String) |
30 | |
{ |
31 | 0 | response = (String) src; |
32 | |
} |
33 | 0 | else if (src instanceof InputStream) |
34 | |
{ |
35 | 0 | response = IOUtils.toString((InputStream) src); |
36 | |
} |
37 | |
|
38 | 0 | if (response != null && response.contains("success")) |
39 | |
{ |
40 | 0 | return response; |
41 | |
} |
42 | |
else |
43 | |
{ |
44 | 0 | throw new TransformerException(MessageFactory.createStaticMessage("Invalid response from service: " + response)); |
45 | |
} |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
|