1 10 11 package org.mule.samples.hello; 12 13 import java.io.UnsupportedEncodingException ; 14 15 import org.mule.config.i18n.Message; 16 import org.mule.transformers.AbstractTransformer; 17 import org.mule.umo.transformer.TransformerException; 18 19 26 public class HttpRequestToString extends AbstractTransformer 27 { 28 31 private static final long serialVersionUID = -6438813035354275131L; 32 33 public HttpRequestToString() 34 { 35 super(); 36 this.registerSourceType(String .class); 37 this.registerSourceType(byte[].class); 38 } 39 40 45 public Object doTransform(Object src, String encoding) throws TransformerException 46 { 47 String param = null; 48 if (src instanceof byte[]) 49 { 50 if (encoding != null) 51 { 52 try 53 { 54 param = new String ((byte[])src, encoding); 55 } 56 catch (UnsupportedEncodingException ex) 57 { 58 param = new String ((byte[])src); 59 } 60 } 61 else 62 { 63 param = new String ((byte[])src); 64 } 65 } 66 else 67 { 68 param = src.toString(); 69 } 70 int equals = param.indexOf("="); 71 if (equals > -1) 72 { 73 return param.substring(equals + 1); 74 } 75 else 76 { 77 throw new TransformerException(Message.createStaticMessage("Failed to parse param string: " 78 + param), this); 79 } 80 } 81 } 82 | Popular Tags |