KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > RPCDispatch > Service


1 package test.RPCDispatch;
2
3 import org.apache.axis.Message;
4 import org.apache.axis.MessageContext;
5 import org.apache.axis.AxisFault;
6 import org.apache.axis.message.RPCElement;
7 import org.apache.axis.utils.DOM2Writer;
8 import org.w3c.dom.Node JavaDoc;
9 import org.w3c.dom.NodeList JavaDoc;
10
11 /**
12  * Test WebService
13  */

14 public class Service {
15
16     /**
17      * Reverse the order of characters in a string
18      */

19     public String JavaDoc reverseString(String JavaDoc input) throws Exception JavaDoc {
20        String JavaDoc result = "";
21        for (int i=input.length(); i>0; ) result+=input.charAt(--i);
22        return result;
23     }
24
25     /**
26      * Concatenate two strings - used to test out-of-order parameter
27      * matching.
28      */

29     public String JavaDoc concatenate(String JavaDoc a1, String JavaDoc a2)
30     {
31         return a1 + a2;
32     }
33
34     /**
35      * Reverse the order of a struct
36      */

37     public Data reverseData(Data input) throws Exception JavaDoc {
38        Data result = new Data();
39        result.setField1(input.getField3());
40        result.setField2(reverseString(input.getField2()));
41        result.setField3(input.getField1());
42        return result;
43     }
44
45     /**
46      * Return the target service (should be this!)
47      */

48     public String JavaDoc targetServiceImplicit() throws Exception JavaDoc {
49        return MessageContext.getCurrentContext().getTargetService();
50     }
51
52     /**
53      * Return the target service (should be this!)
54      */

55     public String JavaDoc argAsDOM(Data input) throws Exception JavaDoc {
56
57        // get the first parameter
58
Message message = MessageContext.getCurrentContext().getRequestMessage();
59        RPCElement body = (RPCElement)message.getSOAPEnvelope().getFirstBody();
60        NodeList JavaDoc parms = body.getAsDOM().getChildNodes();
61        Node JavaDoc parm1 = null;
62        for (int i=0; i<parms.getLength(); i++) {
63            parm1 = parms.item(i);
64            if (parm1.getNodeType() == Node.ELEMENT_NODE) break;
65        }
66
67        // convert it to a DOM and back to a string, and return the result.
68
return DOM2Writer.nodeToString(parm1, true);
69
70     }
71
72     /**
73      * Return the value passed (including nulls!)
74      */

75     public Integer JavaDoc echoInt(Integer JavaDoc value) throws Exception JavaDoc {
76        return value;
77     }
78
79     /**
80      * Return the boolean and String arguments concatenated
81      */

82     public String JavaDoc overloaded(boolean b, String JavaDoc s)
83     {
84         return b + s;
85     }
86
87     /**
88      * Return the String and boolean arguments concatenated
89      */

90     public String JavaDoc overloaded(String JavaDoc s, boolean b)
91     {
92         return s + b;
93     }
94
95     /**
96      * Return the boolean value passed in
97      */

98     public boolean overloaded(boolean b)
99     {
100         return b;
101     }
102
103     /**
104      * Return the Boolean value passed in
105      */

106     public Boolean JavaDoc testBoolean(Boolean JavaDoc b)
107     {
108         return b;
109     }
110
111     /**
112      * Return the Float value passed in
113      */

114     public Float JavaDoc testFloat(Float JavaDoc b)
115     {
116         return b;
117     }
118
119     /**
120      * Return the Double value passed in
121      */

122     public Double JavaDoc testDouble(Double JavaDoc b)
123     {
124         return b;
125     }
126
127     /**
128      * Return the int passed in (this and the function above test overloaded
129      * method dispatch)
130      */

131     public int overloaded(int i)
132     {
133         return i;
134     }
135
136     /**
137      * Return the int and String arguments concatenated
138      */

139     public String JavaDoc overloaded(int i, String JavaDoc s)
140     {
141         return i + s;
142     }
143     
144     /**
145      * Echo a string array (this is for testing that String->String[]
146      * conversions do NOT happen when using encoded arrays)
147      */

148     public void arrayMethod(String JavaDoc [] arg) throws AxisFault {
149         throw new AxisFault("You shouldn't have called me!");
150     }
151
152     /**
153      * Simple exception to be used in generating faults
154      */

155     class TestFault extends Exception JavaDoc {
156         TestFault(String JavaDoc msg) throws Exception JavaDoc {
157             super(msg);
158             if (msg == null) throw new Exception JavaDoc("default value");
159         }
160     }
161
162     /**
163      * Simple fault.
164      */

165     public String JavaDoc simpleFault(String JavaDoc value) throws Exception JavaDoc {
166        TestFault fault = new TestFault(value);
167        throw fault;
168     }
169
170
171 }
172
Popular Tags