~ubuntu-branches/debian/squeeze/axis/squeeze

« back to all changes in this revision

Viewing changes to test/RPCDispatch/Service.java

  • Committer: Bazaar Package Importer
  • Author(s): Vladimír Lapáček
  • Date: 2006-09-06 22:31:39 UTC
  • Revision ID: james.westby@ubuntu.com-20060906223139-l7m5edxeositeppl
Tags: upstream-1.4
Import upstream version 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;
 
9
import org.w3c.dom.NodeList;
 
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 reverseString(String input) throws Exception {
 
20
       String 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 concatenate(String a1, String 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 {
 
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 targetServiceImplicit() throws Exception {
 
49
       return MessageContext.getCurrentContext().getTargetService();
 
50
    }
 
51
 
 
52
    /**
 
53
     * Return the target service (should be this!)
 
54
     */
 
55
    public String argAsDOM(Data input) throws Exception {
 
56
 
 
57
       // get the first parameter
 
58
       Message message = MessageContext.getCurrentContext().getRequestMessage();
 
59
       RPCElement body = (RPCElement)message.getSOAPEnvelope().getFirstBody();
 
60
       NodeList parms = body.getAsDOM().getChildNodes();
 
61
       Node 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 echoInt(Integer value) throws Exception {
 
76
       return value;
 
77
    }
 
78
 
 
79
    /**
 
80
     * Return the boolean and String arguments concatenated
 
81
     */
 
82
    public String overloaded(boolean b, String s)
 
83
    {
 
84
        return b + s;
 
85
    }
 
86
 
 
87
    /**
 
88
     * Return the String and boolean arguments concatenated
 
89
     */
 
90
    public String overloaded(String 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 testBoolean(Boolean b)
 
107
    {
 
108
        return b;
 
109
    }
 
110
 
 
111
    /**
 
112
     * Return the Float value passed in
 
113
     */
 
114
    public Float testFloat(Float b)
 
115
    {
 
116
        return b;
 
117
    }
 
118
 
 
119
    /**
 
120
     * Return the Double value passed in
 
121
     */
 
122
    public Double testDouble(Double 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 overloaded(int i, String 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 [] 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 {
 
156
        TestFault(String msg) throws Exception {
 
157
            super(msg);
 
158
            if (msg == null) throw new Exception("default value");
 
159
        }
 
160
    }
 
161
 
 
162
    /**
 
163
     * Simple fault.
 
164
     */
 
165
    public String simpleFault(String value) throws Exception {
 
166
       TestFault fault = new TestFault(value);
 
167
       throw fault;
 
168
    }
 
169
 
 
170
 
 
171
}