thorhauer 01/06/07 19:46:51 Modified: src/java/org/apache/turbine/services/xmlrpc TurbineXmlRpc.java TurbineXmlRpcService.java XmlRpcService.java src/java/org/apache/turbine/services/xmlrpc/util FileTransfer.java Log: adding ability to do authenticated xml-rpc calls Revision Changes Path 1.10 +109 -5 jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/TurbineXmlRpc.java Index: TurbineXmlRpc.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/TurbineXmlRpc.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TurbineXmlRpc.java 2001/05/05 13:36:06 1.9 +++ TurbineXmlRpc.java 2001/06/08 02:46:32 1.10 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -102,6 +102,26 @@ } /** + * Execute a remote procedure call taht requires authentication + * + * @param url A URL. + * @param username The username to try and authenticate with + * @param password The password to try and authenticate with + * @param methodName A String with the method name. + * @param params A Vector with the parameters. + * @return An Object. + * @exception XmlRpcException. + * @exception IOException. + */ + public static Object executeAuthenticatedRpc(URL url, String username, + String password,String methodName, Vector params) + throws TurbineException + { + return getService().executeAuthenticatedRpc(url, username, password, + methodName, params); + } + + /** * Register an object as a handler for the XmlRpc Server part. * * @param handlerName The name under which we want @@ -199,16 +219,74 @@ destinationFileName); } + /** + * Method to allow a client to send a file to a server that + * requires authentication + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public static void send(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + getService().send(serverURL, + username, + password, + sourceLocationProperty, + sourceFileName, + destinationLocationProperty, + destinationFileName); + } + + /** + * Method to allow a client to get a file from a server. + * + * @param serverURL + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public static void get(String serverURL, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + getService().get(serverURL, + sourceLocationProperty, + sourceFileName, + destinationLocationProperty, + destinationFileName); + } + /** - * Method to allow a client to get a file to a server. + * Method to allow a client to get a file to a server that + * requires authentication * * @param serverURL + * @param username + * @param password * @param sourceLocationProperty * @param sourceFileName * @param destinationLocationProperty * @param destinationFileName */ public static void get(String serverURL, + String username, + String password, String sourceLocationProperty, String sourceFileName, String destinationLocationProperty, @@ -216,6 +294,8 @@ throws Exception { getService().get(serverURL, + username, + password, sourceLocationProperty, sourceFileName, destinationLocationProperty, @@ -236,6 +316,30 @@ throws Exception { getService().remove(serverURL, + sourceLocationProperty, + sourceFileName); + } + + /** + * Method to allow a client to remove a file from + * a server that requires authentication + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + */ + public static void remove(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName) + throws Exception + { + getService().remove(serverURL, + username, + password, sourceLocationProperty, sourceFileName); } 1.24 +124 -6 jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/TurbineXmlRpcService.java Index: TurbineXmlRpcService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/TurbineXmlRpcService.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- TurbineXmlRpcService.java 2001/06/08 01:07:19 1.23 +++ TurbineXmlRpcService.java 2001/06/08 02:46:34 1.24 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -98,7 +98,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a> - * @version $Id: TurbineXmlRpcService.java,v 1.23 2001/06/08 01:07:19 dlr Exp $ + * @version $Id: TurbineXmlRpcService.java,v 1.24 2001/06/08 02:46:34 thorhauer Exp $ */ public class TurbineXmlRpcService extends TurbineBaseService @@ -371,6 +371,40 @@ } /** + * Client's Authenticated interface to XML-RPC. + * + * The return type is Object which you'll need to cast to + * whatever you are expecting. + * + * @param url A URL. + * @param username The username to try and authenticate with + * @param password The password to try and authenticate with + * @param methodName A String with the method name. + * @param params A Vector with the parameters. + * @return An Object. + * @exception XmlRpcException. + * @exception IOException. + */ + public Object executeAuthenticatedRpc(URL url, + String username, + String password, + String methodName, + Vector params) + throws TurbineException + { + try + { + XmlRpcClient client = new XmlRpcClient ( url ); + client.setBasicAuthentication(username, password); + return client.execute(methodName, params); + } + catch (Exception e) + { + throw new TurbineException("XML-RPC call failed", e); + } + } + + /** * Method to allow a client to send a file to a server. * * @param serverURL @@ -393,8 +427,38 @@ destinationFileName); } + /** + * Method to allow a client to send a file to a server that + * requires authentication + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public void send(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + FileTransfer.send(serverURL, + username, + password, + sourceLocationProperty, + sourceFileName, + destinationLocationProperty, + destinationFileName); + } + /** - * Method to allow a client to get a file to a server. + * Method to allow a client to get a file from a server. * * @param serverURL * @param sourceLocationProperty @@ -417,6 +481,36 @@ } /** + * Method to allow a client to get a file from a server that + * requires authentication. + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public void get(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + FileTransfer.get(serverURL, + username, + password, + sourceLocationProperty, + sourceFileName, + destinationLocationProperty, + destinationFileName); + } + + /** * Method to allow a client to remove a file from * the server * @@ -430,6 +524,30 @@ throws Exception { FileTransfer.remove(serverURL, + sourceLocationProperty, + sourceFileName); + } + + /** + * Method to allow a client to remove a file from + * a server that requires authentication. + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + */ + public void remove(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName) + throws Exception + { + FileTransfer.remove(serverURL, + username, + password, sourceLocationProperty, sourceFileName); } 1.13 +84 -6 jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/XmlRpcService.java Index: XmlRpcService.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/XmlRpcService.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- XmlRpcService.java 2001/05/05 13:36:06 1.12 +++ XmlRpcService.java 2001/06/08 02:46:36 1.13 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -69,7 +69,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Magnús Þór Torfason</a> * @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a> * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a> - * @version $Id: XmlRpcService.java,v 1.12 2001/05/05 13:36:06 jvanzyl Exp $ + * @version $Id: XmlRpcService.java,v 1.13 2001/06/08 02:46:36 thorhauer Exp $ */ public interface XmlRpcService extends Service @@ -93,6 +93,26 @@ throws TurbineException; /** + * Execute a remote procedure call taht requires + * authentication. + * + * @param url A URL. + * @param username Rhe username to authenticate with + * @param password The password to authenticate with + * @param methodName A String with the method name. + * @param params A Vector with the parameters. + * @return An Object. + * @exception XmlRpcException. + * @exception IOException. + */ + public Object executeAuthenticatedRpc(URL url, + String username, + String password, + String methodName, + Vector params) + throws TurbineException; + + /** * Register an object as a handler for the XmlRpc Server part. * * @param handlerName The name under which we want @@ -167,17 +187,58 @@ String destinationLocationProperty, String destinationFileName) throws Exception; + /** + * Method to allow a client to send a file to a server that + * requires authentication + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public void send(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception; + + /** + * Method to allow a client to send a file to a server. + * + * @param serverURL + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public void get(String serverURL, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception; /** - * Method to allow a client to get a file to a server. + * Method to allow a client to send a file to a server that + * rewuires authentication * * @param serverURL + * @param username + * @param password * @param sourceLocationProperty * @param sourceFileName * @param destinationLocationProperty * @param destinationFileName */ public void get(String serverURL, + String username, + String password, String sourceLocationProperty, String sourceFileName, String destinationLocationProperty, @@ -193,6 +254,23 @@ * @param sourceFileName */ public void remove(String serverURL, + String sourceLocationProperty, + String sourceFileName) + throws Exception; + + /** + * Method to allow a client to remove a file from + * a server that requires authentication + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + */ + public void remove(String serverURL, + String username, + String password, String sourceLocationProperty, String sourceFileName) throws Exception; 1.7 +166 -6 jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/util/FileTransfer.java Index: FileTransfer.java =================================================================== RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/util/FileTransfer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FileTransfer.java 2001/03/06 06:13:03 1.6 +++ FileTransfer.java 2001/06/08 02:46:46 1.7 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -65,7 +65,7 @@ * Test class for FileHandler. * * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> - * @version $Id: FileTransfer.java,v 1.6 2001/03/06 06:13:03 chrise Exp $ + * @version $Id: FileTransfer.java,v 1.7 2001/06/08 02:46:46 thorhauer Exp $ */ public class FileTransfer { @@ -118,6 +118,63 @@ } /** + * Method to allow a client to send a file to a server + * that requires a user name and password. + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public static void send(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + try + { + Vector params = new Vector(); + + /* + * fileContents + */ + params.add(FileHandler.readFileContents( + sourceLocationProperty, sourceFileName)); + + /* + * property in TR.props which refers to the directory + * where the fileContents should land. + */ + params.add(destinationLocationProperty); + + /* + * name to give the file contents. + */ + params.add(destinationFileName); + + Boolean b = (Boolean) TurbineXmlRpc.executeAuthenticatedRpc( + new URL (serverURL), + username, + password, + "file.send", + params); + + } + catch (Exception e) + { + Log.error("Error sending file to server:", e); + throw new Exception(e.toString()); + } + } + + /** * Method to allow a client to get a file to a server. * * @param serverURL @@ -167,6 +224,64 @@ } /** + * Method to allow a client to get a file from a server + * that requires a user name and password. + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + * @param destinationLocationProperty + * @param destinationFileName + */ + public static void get(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName, + String destinationLocationProperty, + String destinationFileName) + throws Exception + { + + try + { + Vector params = new Vector(); + + /* + * property in TR.props which refers to the directory + * where the fileContents should land. + */ + params.add(sourceLocationProperty); + + /* + * name to give the file contents. + */ + params.add(sourceFileName); + + String fileContents = (String) TurbineXmlRpc.executeAuthenticatedRpc( + new URL (serverURL), + username, + password, + "file.get", + params); + + /* + * Now we have the file contents, we can write + * them out to disk. + */ + FileHandler.writeFileContents(fileContents, + destinationLocationProperty, destinationFileName); + } + catch (Exception e) + { + Log.error("Error getting file from server:", e); + throw new Exception(e.toString()); + } + } + + /** * Method to allow a client to remove a file from * the server * @@ -201,5 +316,50 @@ Log.error("Error removing file from server:", e); throw new Exception(e.toString()); } + } + + /** + * Method to allow a client to remove a file from + * a server that requires a user name and password. + * + * @param serverURL + * @param username + * @param password + * @param sourceLocationProperty + * @param sourceFileName + */ + public static void remove(String serverURL, + String username, + String password, + String sourceLocationProperty, + String sourceFileName) + throws Exception + { + try + { + Vector params = new Vector(); + + /* + * property in TR.props which refers to the directory + * where the fileContents should land. + */ + params.add(sourceLocationProperty); + + /* + * name to give the file contents. + */ + params.add(sourceFileName); + + TurbineXmlRpc.executeAuthenticatedRpc(new URL (serverURL), + username, + password, + "file.remove", + params); + } + catch (Exception e) + { + Log.error("Error removing file from server:", e); + throw new Exception(e.toString()); + } } -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]