1 package org.apache.turbine.services.xmlrpc;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import helma.xmlrpc.XmlRpcException;
58 import java.io.IOException;
59 import java.io.InputStream;
60 import java.net.URL;
61 import java.util.Vector;
62 import org.apache.turbine.services.TurbineServices;
63 import org.apache.turbine.util.TurbineException;
64
65 /***
66 * This is a static accesor class for {@link XmlRpcService}.
67 *
68 * @author <a href="mailto:magnus@handtolvur.is">Magnús Þór Torfason</a>
69 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
70 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
71 */
72 public abstract class TurbineXmlRpc
73 {
74 /***
75 * Returns system's configured implementation of {@link XmlRpcService}.
76 *
77 * @return an implementaion of <code>XmlRpcService</code>
78 */
79 public static XmlRpcService getService()
80 {
81 return (XmlRpcService)TurbineServices.getInstance()
82 .getService(XmlRpcService.SERVICE_NAME);
83 }
84
85
86 /***
87 * Execute a remote procedure call.
88 *
89 * @param url A URL.
90 * @param methodName A String with the method name.
91 * @param params A Vector with the parameters.
92 * @return An Object.
93 * @exception XmlRpcException.
94 * @exception IOException.
95 */
96 public static Object executeRpc(URL url, String methodName, Vector params)
97 throws TurbineException
98 {
99 return getService().executeRpc(url, methodName, params);
100 }
101
102 /***
103 * Execute a remote procedure call taht requires authentication
104 *
105 * @param url A URL.
106 * @param username The username to try and authenticate with
107 * @param password The password to try and authenticate with
108 * @param methodName A String with the method name.
109 * @param params A Vector with the parameters.
110 * @return An Object.
111 * @exception XmlRpcException.
112 * @exception IOException.
113 */
114 public static Object executeAuthenticatedRpc(URL url, String username,
115 String password,String methodName, Vector params)
116 throws TurbineException
117 {
118 return getService().executeAuthenticatedRpc(url, username, password,
119 methodName, params);
120 }
121
122 /***
123 * Register an object as a handler for the XmlRpc Server part.
124 *
125 * @param handlerName The name under which we want
126 * to register the service
127 * @param handler The handler object
128 * @exception XmlRpcException.
129 * @exception IOException.
130 */
131 public static void registerHandler(String handlerName, Object handler)
132 throws XmlRpcException,
133 IOException
134 {
135 getService().registerHandler(handlerName, handler);
136 }
137
138 /***
139 * Register an object as a the default handler for
140 * the XmlRpc Server part.
141 *
142 * @param handler The handler object
143 * @exception XmlRpcException.
144 * @exception IOException.
145 */
146 public static void registerHandler(Object handler)
147 throws XmlRpcException,
148 IOException
149 {
150 getService().registerHandler(handler);
151 }
152
153 /***
154 * Unregister a handler.
155 *
156 * @param handlerName The name of the handler to unregister.
157 */
158 public static void unregisterHandler(String handlerName)
159 {
160 getService().unregisterHandler(handlerName);
161 }
162
163 /***
164 * Handle an XML-RPC request using the encapsulated server.
165 *
166 * You can use this method to handle a request from within
167 * a Turbine screen.
168 *
169 * @param is the stream to read request data from.
170 * @return the response body that needs to be sent to the client.
171 */
172 public static byte[] handleRequest(InputStream is)
173 {
174 return getService().handleRequest(is);
175 }
176
177 /***
178 * Handle an XML-RPC request using the encapsulated server with user
179 * authentication.
180 *
181 * You can use this method to handle a request from within
182 * a Turbine screen.
183 *
184 * <p> Note that the handlers need to implement AuthenticatedXmlRpcHandler
185 * interface to access the authentication infomration.
186 *
187 * @param is the stream to read request data from.
188 * @param user the user that is making the request.
189 * @param password the password given by user.
190 * @return the response body that needs to be sent to the client.
191 */
192 public static byte[] handleRequest(InputStream is, String user, String password)
193 {
194 return getService().handleRequest(is, user, password);
195 }
196
197 /***
198 * Method to allow a client to send a file to a server.
199 *
200 * @param serverURL
201 * @param sourceLocationProperty
202 * @param sourceFileName
203 * @param destinationLocationProperty
204 * @param destinationFileName
205 */
206 public static void send(String serverURL,
207 String sourceLocationProperty,
208 String sourceFileName,
209 String destinationLocationProperty,
210 String destinationFileName)
211 throws Exception
212 {
213 getService().send(serverURL,
214 sourceLocationProperty,
215 sourceFileName,
216 destinationLocationProperty,
217 destinationFileName);
218 }
219
220 /***
221 * Method to allow a client to send a file to a server that
222 * requires authentication
223 *
224 * @param serverURL
225 * @param username
226 * @param password
227 * @param sourceLocationProperty
228 * @param sourceFileName
229 * @param destinationLocationProperty
230 * @param destinationFileName
231 */
232 public static void send(String serverURL,
233 String username,
234 String password,
235 String sourceLocationProperty,
236 String sourceFileName,
237 String destinationLocationProperty,
238 String destinationFileName)
239 throws Exception
240 {
241 getService().send(serverURL,
242 username,
243 password,
244 sourceLocationProperty,
245 sourceFileName,
246 destinationLocationProperty,
247 destinationFileName);
248 }
249
250 /***
251 * Method to allow a client to get a file from a server.
252 *
253 * @param serverURL
254 * @param sourceLocationProperty
255 * @param sourceFileName
256 * @param destinationLocationProperty
257 * @param destinationFileName
258 */
259 public static void get(String serverURL,
260 String sourceLocationProperty,
261 String sourceFileName,
262 String destinationLocationProperty,
263 String destinationFileName)
264 throws Exception
265 {
266 getService().get(serverURL,
267 sourceLocationProperty,
268 sourceFileName,
269 destinationLocationProperty,
270 destinationFileName);
271 }
272
273 /***
274 * Method to allow a client to get a file to a server that
275 * requires authentication
276 *
277 * @param serverURL
278 * @param username
279 * @param password
280 * @param sourceLocationProperty
281 * @param sourceFileName
282 * @param destinationLocationProperty
283 * @param destinationFileName
284 */
285 public static void get(String serverURL,
286 String username,
287 String password,
288 String sourceLocationProperty,
289 String sourceFileName,
290 String destinationLocationProperty,
291 String destinationFileName)
292 throws Exception
293 {
294 getService().get(serverURL,
295 username,
296 password,
297 sourceLocationProperty,
298 sourceFileName,
299 destinationLocationProperty,
300 destinationFileName);
301 }
302
303 /***
304 * Method to allow a client to remove a file from
305 * the server
306 *
307 * @param serverURL
308 * @param sourceLocationProperty
309 * @param sourceFileName
310 */
311 public static void remove(String serverURL,
312 String sourceLocationProperty,
313 String sourceFileName)
314 throws Exception
315 {
316 getService().remove(serverURL,
317 sourceLocationProperty,
318 sourceFileName);
319 }
320
321 /***
322 * Method to allow a client to remove a file from
323 * a server that requires authentication
324 *
325 * @param serverURL
326 * @param username
327 * @param password
328 * @param sourceLocationProperty
329 * @param sourceFileName
330 */
331 public static void remove(String serverURL,
332 String username,
333 String password,
334 String sourceLocationProperty,
335 String sourceFileName)
336 throws Exception
337 {
338 getService().remove(serverURL,
339 username,
340 password,
341 sourceLocationProperty,
342 sourceFileName);
343 }
344
345 /***
346 * Switch client filtering on/off.
347 * @see #acceptClient(java.lang.String)
348 * @see #denyClient(java.lang.String)
349 */
350 public static void setParanoid(boolean state)
351 {
352 getService().setParanoid(state);
353 }
354
355 /***
356 * Add an IP address to the list of accepted clients. The parameter can
357 * contain '*' as wildcard character, e.g. "192.168.*.*". You must
358 * call setParanoid(true) in order for this to have
359 * any effect.
360 *
361 * @see #denyClient(java.lang.String)
362 * @see #setParanoid(boolean)
363 */
364 public static void acceptClient(String address)
365 {
366 getService().acceptClient(address);
367 }
368
369 /***
370 * Add an IP address to the list of denied clients. The parameter can
371 * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
372 * setParanoid(true) in order for this to have any effect.
373 *
374 * @see #acceptClient(java.lang.String)
375 * @see #setParanoid(boolean)
376 */
377 public static void denyClient(String address)
378 {
379 getService().denyClient(address);
380 }
381 }
This page was automatically generated by Maven