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