001: package org.apache.turbine.services.xmlrpc;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.io.InputStream;
023:
024: import java.net.URL;
025:
026: import java.util.Vector;
027:
028: import org.apache.turbine.services.TurbineServices;
029: import org.apache.turbine.util.TurbineException;
030:
031: /**
032: * This is a static accesor class for {@link XmlRpcService}.
033: *
034: * @author <a href="mailto:magnus@handtolvur.is">Magnús Þór Torfason</a>
035: * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
036: * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
037: * @version $Id: TurbineXmlRpc.java 534527 2007-05-02 16:10:59Z tv $
038: */
039: public abstract class TurbineXmlRpc {
040: /**
041: * Returns system's configured implementation of {@link XmlRpcService}.
042: *
043: * @return an implementaion of <code>XmlRpcService</code>
044: */
045: public static XmlRpcService getService() {
046: return (XmlRpcService) TurbineServices.getInstance()
047: .getService(XmlRpcService.SERVICE_NAME);
048: }
049:
050: /**
051: * Execute a remote procedure call.
052: *
053: * @param url A URL.
054: * @param methodName A String with the method name.
055: * @param params A Vector with the parameters.
056: * @return An Object.
057: * @exception TurbineException
058: */
059: public static Object executeRpc(URL url, String methodName,
060: Vector params) throws TurbineException {
061: return getService().executeRpc(url, methodName, params);
062: }
063:
064: /**
065: * Execute a remote procedure call taht requires authentication
066: *
067: * @param url A URL.
068: * @param username The username to try and authenticate with
069: * @param password The password to try and authenticate with
070: * @param methodName A String with the method name.
071: * @param params A Vector with the parameters.
072: * @return An Object.
073: * @exception TurbineException
074: */
075: public static Object executeAuthenticatedRpc(URL url,
076: String username, String password, String methodName,
077: Vector params) throws TurbineException {
078: return getService().executeAuthenticatedRpc(url, username,
079: password, methodName, params);
080: }
081:
082: /**
083: * Register an object as a handler for the XmlRpc Server part.
084: *
085: * @param handlerName The name under which we want
086: * to register the service
087: * @param handler The handler object
088: */
089: public static void registerHandler(String handlerName,
090: Object handler) {
091: getService().registerHandler(handlerName, handler);
092: }
093:
094: /**
095: * Register an object as a the default handler for
096: * the XmlRpc Server part.
097: *
098: * @param handler The handler object
099: */
100: public static void registerHandler(Object handler) {
101: getService().registerHandler(handler);
102: }
103:
104: /**
105: * Unregister a handler.
106: *
107: * @param handlerName The name of the handler to unregister.
108: */
109: public static void unregisterHandler(String handlerName) {
110: getService().unregisterHandler(handlerName);
111: }
112:
113: /**
114: * Handle an XML-RPC request using the encapsulated server.
115: *
116: * You can use this method to handle a request from within
117: * a Turbine screen.
118: *
119: * @param is the stream to read request data from.
120: * @return the response body that needs to be sent to the client.
121: */
122: public static byte[] handleRequest(InputStream is) {
123: return getService().handleRequest(is);
124: }
125:
126: /**
127: * Handle an XML-RPC request using the encapsulated server with user
128: * authentication.
129: *
130: * You can use this method to handle a request from within
131: * a Turbine screen.
132: *
133: * <p> Note that the handlers need to implement AuthenticatedXmlRpcHandler
134: * interface to access the authentication infomration.
135: *
136: * @param is the stream to read request data from.
137: * @param user the user that is making the request.
138: * @param password the password given by user.
139: * @return the response body that needs to be sent to the client.
140: */
141: public static byte[] handleRequest(InputStream is, String user,
142: String password) {
143: return getService().handleRequest(is, user, password);
144: }
145:
146: /**
147: * Method to allow a client to send a file to a server.
148: *
149: * @param serverURL
150: * @param sourceLocationProperty
151: * @param sourceFileName
152: * @param destinationLocationProperty
153: * @param destinationFileName
154: * @deprecated This is not scope of the Service itself but of an
155: * application which uses the service.
156: */
157: public static void send(String serverURL,
158: String sourceLocationProperty, String sourceFileName,
159: String destinationLocationProperty,
160: String destinationFileName) throws TurbineException {
161: getService().send(serverURL, sourceLocationProperty,
162: sourceFileName, destinationLocationProperty,
163: destinationFileName);
164: }
165:
166: /**
167: * Method to allow a client to send a file to a server that
168: * requires authentication
169: *
170: * @param serverURL
171: * @param username
172: * @param password
173: * @param sourceLocationProperty
174: * @param sourceFileName
175: * @param destinationLocationProperty
176: * @param destinationFileName
177: * @deprecated This is not scope of the Service itself but of an
178: * application which uses the service.
179: */
180: public static void send(String serverURL, String username,
181: String password, String sourceLocationProperty,
182: String sourceFileName, String destinationLocationProperty,
183: String destinationFileName) throws TurbineException {
184: getService().send(serverURL, username, password,
185: sourceLocationProperty, sourceFileName,
186: destinationLocationProperty, destinationFileName);
187: }
188:
189: /**
190: * Method to allow a client to get a file from a server.
191: *
192: * @param serverURL
193: * @param sourceLocationProperty
194: * @param sourceFileName
195: * @param destinationLocationProperty
196: * @param destinationFileName
197: * @deprecated This is not scope of the Service itself but of an
198: * application which uses the service.
199: */
200: public static void get(String serverURL,
201: String sourceLocationProperty, String sourceFileName,
202: String destinationLocationProperty,
203: String destinationFileName) throws TurbineException {
204: getService().get(serverURL, sourceLocationProperty,
205: sourceFileName, destinationLocationProperty,
206: destinationFileName);
207: }
208:
209: /**
210: * Method to allow a client to get a file to a server that
211: * requires authentication
212: *
213: * @param serverURL
214: * @param username
215: * @param password
216: * @param sourceLocationProperty
217: * @param sourceFileName
218: * @param destinationLocationProperty
219: * @param destinationFileName
220: * @deprecated This is not scope of the Service itself but of an
221: * application which uses the service.
222: */
223: public static void get(String serverURL, String username,
224: String password, String sourceLocationProperty,
225: String sourceFileName, String destinationLocationProperty,
226: String destinationFileName) throws TurbineException {
227: getService().get(serverURL, username, password,
228: sourceLocationProperty, sourceFileName,
229: destinationLocationProperty, destinationFileName);
230: }
231:
232: /**
233: * Method to allow a client to remove a file from
234: * the server
235: *
236: * @param serverURL
237: * @param sourceLocationProperty
238: * @param sourceFileName
239: * @deprecated This is not scope of the Service itself but of an
240: * application which uses the service.
241: */
242: public static void remove(String serverURL,
243: String sourceLocationProperty, String sourceFileName)
244: throws TurbineException {
245: getService().remove(serverURL, sourceLocationProperty,
246: sourceFileName);
247: }
248:
249: /**
250: * Method to allow a client to remove a file from
251: * a server that requires authentication
252: *
253: * @param serverURL
254: * @param username
255: * @param password
256: * @param sourceLocationProperty
257: * @param sourceFileName
258: * @deprecated This is not scope of the Service itself but of an
259: * application which uses the service.
260: */
261: public static void remove(String serverURL, String username,
262: String password, String sourceLocationProperty,
263: String sourceFileName) throws TurbineException {
264: getService().remove(serverURL, username, password,
265: sourceLocationProperty, sourceFileName);
266: }
267:
268: /**
269: * Switch client filtering on/off.
270: * @see #acceptClient(java.lang.String)
271: * @see #denyClient(java.lang.String)
272: */
273: public static void setParanoid(boolean state) {
274: getService().setParanoid(state);
275: }
276:
277: /**
278: * Add an IP address to the list of accepted clients. The parameter can
279: * contain '*' as wildcard character, e.g. "192.168.*.*". You must
280: * call setParanoid(true) in order for this to have
281: * any effect.
282: *
283: * @see #denyClient(java.lang.String)
284: * @see #setParanoid(boolean)
285: */
286: public static void acceptClient(String address) {
287: getService().acceptClient(address);
288: }
289:
290: /**
291: * Add an IP address to the list of denied clients. The parameter can
292: * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
293: * setParanoid(true) in order for this to have any effect.
294: *
295: * @see #acceptClient(java.lang.String)
296: * @see #setParanoid(boolean)
297: */
298: public static void denyClient(String address) {
299: getService().denyClient(address);
300: }
301: }
|