KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > hello > HttpRequestToString


1 /*
2  * $Id: HttpRequestToString.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.samples.hello;
12
13 import java.io.UnsupportedEncodingException JavaDoc;
14
15 import org.mule.config.i18n.Message;
16 import org.mule.transformers.AbstractTransformer;
17 import org.mule.umo.transformer.TransformerException;
18
19 /**
20  * <code>NameStringToChatString</code> This is test class only for use with the
21  * Hello world test application.
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public class HttpRequestToString extends AbstractTransformer
27 {
28     /**
29      * Serial version
30      */

31     private static final long serialVersionUID = -6438813035354275131L;
32
33     public HttpRequestToString()
34     {
35         super();
36         this.registerSourceType(String JavaDoc.class);
37         this.registerSourceType(byte[].class);
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.mule.transformers.AbstractTransformer#doTransform(java.lang.Object)
44      */

45     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
46     {
47         String JavaDoc param = null;
48         if (src instanceof byte[])
49         {
50             if (encoding != null)
51             {
52                 try
53                 {
54                     param = new String JavaDoc((byte[])src, encoding);
55                 }
56                 catch (UnsupportedEncodingException JavaDoc ex)
57                 {
58                     param = new String JavaDoc((byte[])src);
59                 }
60             }
61             else
62             {
63                 param = new String JavaDoc((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