1 package org.apache.turbine.services.xmlrpc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.InputStream;
23
24 import java.net.URL;
25
26 import java.util.Vector;
27
28 import org.apache.turbine.services.TurbineServices;
29 import org.apache.turbine.util.TurbineException;
30
31 /***
32 * This is a static accesor class for {@link XmlRpcService}.
33 *
34 * @author <a href="mailto:magnus@handtolvur.is">Magnús Þór Torfason</a>
35 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
36 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
37 * @version $Id: TurbineXmlRpc.java 534527 2007-05-02 16:10:59Z tv $
38 */
39 public abstract class TurbineXmlRpc
40 {
41 /***
42 * Returns system's configured implementation of {@link XmlRpcService}.
43 *
44 * @return an implementaion of <code>XmlRpcService</code>
45 */
46 public static XmlRpcService getService()
47 {
48 return (XmlRpcService) TurbineServices.getInstance()
49 .getService(XmlRpcService.SERVICE_NAME);
50 }
51
52 /***
53 * Execute a remote procedure call.
54 *
55 * @param url A URL.
56 * @param methodName A String with the method name.
57 * @param params A Vector with the parameters.
58 * @return An Object.
59 * @exception TurbineException
60 */
61 public static Object executeRpc(URL url, String methodName, Vector params)
62 throws TurbineException
63 {
64 return getService().executeRpc(url, methodName, params);
65 }
66
67 /***
68 * Execute a remote procedure call taht requires authentication
69 *
70 * @param url A URL.
71 * @param username The username to try and authenticate with
72 * @param password The password to try and authenticate with
73 * @param methodName A String with the method name.
74 * @param params A Vector with the parameters.
75 * @return An Object.
76 * @exception TurbineException
77 */
78 public static Object executeAuthenticatedRpc(URL url, String username,
79 String password, String methodName, Vector params)
80 throws TurbineException
81 {
82 return getService().executeAuthenticatedRpc(url, username, password,
83 methodName, params);
84 }
85
86 /***
87 * Register an object as a handler for the XmlRpc Server part.
88 *
89 * @param handlerName The name under which we want
90 * to register the service
91 * @param handler The handler object
92 */
93 public static void registerHandler(String handlerName, Object handler)
94 {
95 getService().registerHandler(handlerName, handler);
96 }
97
98 /***
99 * Register an object as a the default handler for
100 * the XmlRpc Server part.
101 *
102 * @param handler The handler object
103 */
104 public static void registerHandler(Object handler)
105 {
106 getService().registerHandler(handler);
107 }
108
109 /***
110 * Unregister a handler.
111 *
112 * @param handlerName The name of the handler to unregister.
113 */
114 public static void unregisterHandler(String handlerName)
115 {
116 getService().unregisterHandler(handlerName);
117 }
118
119 /***
120 * Handle an XML-RPC request using the encapsulated server.
121 *
122 * You can use this method to handle a request from within
123 * a Turbine screen.
124 *
125 * @param is the stream to read request data from.
126 * @return the response body that needs to be sent to the client.
127 */
128 public static byte[] handleRequest(InputStream is)
129 {
130 return getService().handleRequest(is);
131 }
132
133 /***
134 * Handle an XML-RPC request using the encapsulated server with user
135 * authentication.
136 *
137 * You can use this method to handle a request from within
138 * a Turbine screen.
139 *
140 * <p> Note that the handlers need to implement AuthenticatedXmlRpcHandler
141 * interface to access the authentication infomration.
142 *
143 * @param is the stream to read request data from.
144 * @param user the user that is making the request.
145 * @param password the password given by user.
146 * @return the response body that needs to be sent to the client.
147 */
148 public static byte[] handleRequest(InputStream is, String user, String password)
149 {
150 return getService().handleRequest(is, user, password);
151 }
152
153 /***
154 * Method to allow a client to send a file to a server.
155 *
156 * @param serverURL
157 * @param sourceLocationProperty
158 * @param sourceFileName
159 * @param destinationLocationProperty
160 * @param destinationFileName
161 * @deprecated This is not scope of the Service itself but of an
162 * application which uses the service.
163 */
164 public static void send(String serverURL,
165 String sourceLocationProperty,
166 String sourceFileName,
167 String destinationLocationProperty,
168 String destinationFileName)
169 throws TurbineException
170 {
171 getService().send(serverURL,
172 sourceLocationProperty,
173 sourceFileName,
174 destinationLocationProperty,
175 destinationFileName);
176 }
177
178 /***
179 * Method to allow a client to send a file to a server that
180 * requires authentication
181 *
182 * @param serverURL
183 * @param username
184 * @param password
185 * @param sourceLocationProperty
186 * @param sourceFileName
187 * @param destinationLocationProperty
188 * @param destinationFileName
189 * @deprecated This is not scope of the Service itself but of an
190 * application which uses the service.
191 */
192 public static void send(String serverURL,
193 String username,
194 String password,
195 String sourceLocationProperty,
196 String sourceFileName,
197 String destinationLocationProperty,
198 String destinationFileName)
199 throws TurbineException
200 {
201 getService().send(serverURL,
202 username,
203 password,
204 sourceLocationProperty,
205 sourceFileName,
206 destinationLocationProperty,
207 destinationFileName);
208 }
209
210 /***
211 * Method to allow a client to get a file from a server.
212 *
213 * @param serverURL
214 * @param sourceLocationProperty
215 * @param sourceFileName
216 * @param destinationLocationProperty
217 * @param destinationFileName
218 * @deprecated This is not scope of the Service itself but of an
219 * application which uses the service.
220 */
221 public static void get(String serverURL,
222 String sourceLocationProperty,
223 String sourceFileName,
224 String destinationLocationProperty,
225 String destinationFileName)
226 throws TurbineException
227 {
228 getService().get(serverURL,
229 sourceLocationProperty,
230 sourceFileName,
231 destinationLocationProperty,
232 destinationFileName);
233 }
234
235 /***
236 * Method to allow a client to get a file to a server that
237 * requires authentication
238 *
239 * @param serverURL
240 * @param username
241 * @param password
242 * @param sourceLocationProperty
243 * @param sourceFileName
244 * @param destinationLocationProperty
245 * @param destinationFileName
246 * @deprecated This is not scope of the Service itself but of an
247 * application which uses the service.
248 */
249 public static void get(String serverURL,
250 String username,
251 String password,
252 String sourceLocationProperty,
253 String sourceFileName,
254 String destinationLocationProperty,
255 String destinationFileName)
256 throws TurbineException
257 {
258 getService().get(serverURL,
259 username,
260 password,
261 sourceLocationProperty,
262 sourceFileName,
263 destinationLocationProperty,
264 destinationFileName);
265 }
266
267 /***
268 * Method to allow a client to remove a file from
269 * the server
270 *
271 * @param serverURL
272 * @param sourceLocationProperty
273 * @param sourceFileName
274 * @deprecated This is not scope of the Service itself but of an
275 * application which uses the service.
276 */
277 public static void remove(String serverURL,
278 String sourceLocationProperty,
279 String sourceFileName)
280 throws TurbineException
281 {
282 getService().remove(serverURL,
283 sourceLocationProperty,
284 sourceFileName);
285 }
286
287 /***
288 * Method to allow a client to remove a file from
289 * a server that requires authentication
290 *
291 * @param serverURL
292 * @param username
293 * @param password
294 * @param sourceLocationProperty
295 * @param sourceFileName
296 * @deprecated This is not scope of the Service itself but of an
297 * application which uses the service.
298 */
299 public static void remove(String serverURL,
300 String username,
301 String password,
302 String sourceLocationProperty,
303 String sourceFileName)
304 throws TurbineException
305 {
306 getService().remove(serverURL,
307 username,
308 password,
309 sourceLocationProperty,
310 sourceFileName);
311 }
312
313 /***
314 * Switch client filtering on/off.
315 * @see #acceptClient(java.lang.String)
316 * @see #denyClient(java.lang.String)
317 */
318 public static void setParanoid(boolean state)
319 {
320 getService().setParanoid(state);
321 }
322
323 /***
324 * Add an IP address to the list of accepted clients. The parameter can
325 * contain '*' as wildcard character, e.g. "192.168.*.*". You must
326 * call setParanoid(true) in order for this to have
327 * any effect.
328 *
329 * @see #denyClient(java.lang.String)
330 * @see #setParanoid(boolean)
331 */
332 public static void acceptClient(String address)
333 {
334 getService().acceptClient(address);
335 }
336
337 /***
338 * Add an IP address to the list of denied clients. The parameter can
339 * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
340 * setParanoid(true) in order for this to have any effect.
341 *
342 * @see #acceptClient(java.lang.String)
343 * @see #setParanoid(boolean)
344 */
345 public static void denyClient(String address)
346 {
347 getService().denyClient(address);
348 }
349 }