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