org.apache.turbine.services.xmlrpc
Class TurbineXmlRpcService

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitable
      extended byorg.apache.turbine.services.BaseService
          extended byorg.apache.turbine.services.TurbineBaseService
              extended byorg.apache.turbine.services.xmlrpc.TurbineXmlRpcService
All Implemented Interfaces:
Initable, Service, XmlRpcService

public class TurbineXmlRpcService
extends TurbineBaseService
implements XmlRpcService

This is a service which will make an xml-rpc call to a remote server. Here's an example of how it would be done:

 XmlRpcService xs =
   (XmlRpcService)TurbineServices.getInstance()
   .getService(XmlRpcService.XMLRPC_SERVICE_NAME);
 Vector vec = new Vector();
 vec.addElement(new Integer(5));
 URL url = new URL("http://betty.userland.com/RPC2");
 String name = (String)xs.executeRpc(url, "examples.getStateName", vec);
 

TODO: Handle XmlRpc.setDebug(boolean)

Version:
$Id: TurbineXmlRpcService.java 534527 2007-05-02 16:10:59Z tv $
Author:
Josh Lucas, Magnús Þór Torfason, Rafal Krzewski, Jason van Zyl, Daniel Rall, Martin Poeschl, Quinton McCombs

Field Summary
protected  boolean isModernVersion
          Whether a version of Apache's XML-RPC library greater than 1.1 is available.
protected  int port
          The port to listen on.
protected  org.apache.xmlrpc.XmlRpcServer server
          The encapsulated xmlrpc server.
protected  org.apache.xmlrpc.WebServer webserver
          The standalone xmlrpc server.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.xmlrpc.XmlRpcService
SERVICE_NAME
 
Constructor Summary
TurbineXmlRpcService()
           
 
Method Summary
 void acceptClient(java.lang.String address)
          Add an IP address to the list of accepted clients.
 void denyClient(java.lang.String address)
          Add an IP address to the list of denied clients.
 java.lang.Object executeAuthenticatedRpc(java.net.URL url, java.lang.String username, java.lang.String password, java.lang.String methodName, java.util.Vector params)
          Client's Authenticated interface to XML-RPC.
 java.lang.Object executeRpc(java.net.URL url, java.lang.String methodName, java.util.Vector params)
          Client's interface to XML-RPC.
 void get(java.lang.String serverURL, java.lang.String sourceLocationProperty, java.lang.String sourceFileName, java.lang.String destinationLocationProperty, java.lang.String destinationFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 void get(java.lang.String serverURL, java.lang.String username, java.lang.String password, java.lang.String sourceLocationProperty, java.lang.String sourceFileName, java.lang.String destinationLocationProperty, java.lang.String destinationFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 byte[] handleRequest(java.io.InputStream is)
          Handle an XML-RPC request using the encapsulated server.
 byte[] handleRequest(java.io.InputStream is, java.lang.String user, java.lang.String password)
          Handle an XML-RPC request using the encapsulated server with user authentication.
 void init()
          This function initializes the XmlRpcService.This is a zero parameter variant which queries the Turbine Servlet for its config.
 void init(javax.servlet.ServletConfig config)
          Deprecated. Use init() instead.
 void registerHandler(java.lang.Object handler)
          Register an Object as a default handler for the service.
 void registerHandler(java.lang.String handlerName, java.lang.Object handler)
          Register an Object as a handler for the service.
 void registerHandler(java.lang.String handlerName, java.lang.String handlerClass)
          A helper method that tries to initialize a handler and register it.
 void remove(java.lang.String serverURL, java.lang.String sourceLocationProperty, java.lang.String sourceFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 void remove(java.lang.String serverURL, java.lang.String username, java.lang.String password, java.lang.String sourceLocationProperty, java.lang.String sourceFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 void send(java.lang.String serverURL, java.lang.String sourceLocationProperty, java.lang.String sourceFileName, java.lang.String destinationLocationProperty, java.lang.String destinationFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 void send(java.lang.String serverURL, java.lang.String username, java.lang.String password, java.lang.String sourceLocationProperty, java.lang.String sourceFileName, java.lang.String destinationLocationProperty, java.lang.String destinationFileName)
          Deprecated. This is not scope of the Service itself but of an application which uses the service.
 void setParanoid(boolean state)
          Switch client filtering on/off.
 void shutdown()
          Shuts down this service, stopping running threads.
 void unregisterHandler(java.lang.String handlerName)
          Unregister a handler.
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker
 

Field Detail

isModernVersion

protected boolean isModernVersion
Whether a version of Apache's XML-RPC library greater than 1.1 is available.


webserver

protected org.apache.xmlrpc.WebServer webserver
The standalone xmlrpc server.


server

protected org.apache.xmlrpc.XmlRpcServer server
The encapsulated xmlrpc server.


port

protected int port
The port to listen on.

Constructor Detail

TurbineXmlRpcService

public TurbineXmlRpcService()
Method Detail

init

public void init()
          throws InitializationException
This function initializes the XmlRpcService.This is a zero parameter variant which queries the Turbine Servlet for its config.

Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Throws:
InitializationException - Something went wrong in the init stage

init

public void init(javax.servlet.ServletConfig config)
          throws InitializationException
Deprecated. Use init() instead.

This function initializes the XmlRpcService.

Overrides:
init in class TurbineBaseService
Parameters:
config - A ServletConfing to use for initialization activities.
Throws:
InitializationException - if initialization of this class was not successful.

registerHandler

public void registerHandler(java.lang.Object handler)
Register an Object as a default handler for the service.

Specified by:
registerHandler in interface XmlRpcService
Parameters:
handler - The handler to use.

registerHandler

public void registerHandler(java.lang.String handlerName,
                            java.lang.Object handler)
Register an Object as a handler for the service.

Specified by:
registerHandler in interface XmlRpcService
Parameters:
handlerName - The name the handler is registered under.
handler - The handler to use.

registerHandler

public void registerHandler(java.lang.String handlerName,
                            java.lang.String handlerClass)
                     throws TurbineException
A helper method that tries to initialize a handler and register it. The purpose is to check for all the exceptions that may occur in dynamic class loading and throw an InitializationException on error.

Parameters:
handlerName - The name the handler is registered under.
handlerClass - The name of the class to use as a handler.
Throws:
TurbineException - Couldn't instantiate handler.

unregisterHandler

public void unregisterHandler(java.lang.String handlerName)
Unregister a handler.

Specified by:
unregisterHandler in interface XmlRpcService
Parameters:
handlerName - The name of the handler to unregister.

handleRequest

public byte[] handleRequest(java.io.InputStream is)
Handle an XML-RPC request using the encapsulated server. You can use this method to handle a request from within a Turbine screen.

Specified by:
handleRequest in interface XmlRpcService
Parameters:
is - the stream to read request data from.
Returns:
the response body that needs to be sent to the client.

handleRequest

public byte[] handleRequest(java.io.InputStream is,
                            java.lang.String user,
                            java.lang.String password)
Handle an XML-RPC request using the encapsulated server with user authentication. You can use this method to handle a request from within a Turbine screen.

Note that the handlers need to implement AuthenticatedXmlRpcHandler interface to access the authentication infomration.

Specified by:
handleRequest in interface XmlRpcService
Parameters:
is - the stream to read request data from.
user - the user that is making the request.
password - the password given by user.
Returns:
the response body that needs to be sent to the client.

executeRpc

public java.lang.Object executeRpc(java.net.URL url,
                                   java.lang.String methodName,
                                   java.util.Vector params)
                            throws TurbineException
Client's interface to XML-RPC. The return type is Object which you'll need to cast to whatever you are expecting.

Specified by:
executeRpc in interface XmlRpcService
Parameters:
url - A URL.
methodName - A String with the method name.
params - A Vector with the parameters.
Returns:
An Object.
Throws:
TurbineException

executeAuthenticatedRpc

public java.lang.Object executeAuthenticatedRpc(java.net.URL url,
                                                java.lang.String username,
                                                java.lang.String password,
                                                java.lang.String methodName,
                                                java.util.Vector params)
                                         throws TurbineException
Client's Authenticated interface to XML-RPC. The return type is Object which you'll need to cast to whatever you are expecting.

Specified by:
executeAuthenticatedRpc in interface XmlRpcService
Parameters:
url - A URL.
username - The username to try and authenticate with
password - The password to try and authenticate with
methodName - A String with the method name.
params - A Vector with the parameters.
Returns:
An Object.
Throws:
TurbineException

send

public void send(java.lang.String serverURL,
                 java.lang.String sourceLocationProperty,
                 java.lang.String sourceFileName,
                 java.lang.String destinationLocationProperty,
                 java.lang.String destinationFileName)
          throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to send a file to a server.

Specified by:
send in interface XmlRpcService
Parameters:
serverURL -
sourceLocationProperty -
sourceFileName -
destinationLocationProperty -
destinationFileName -
Throws:
TurbineException

send

public void send(java.lang.String serverURL,
                 java.lang.String username,
                 java.lang.String password,
                 java.lang.String sourceLocationProperty,
                 java.lang.String sourceFileName,
                 java.lang.String destinationLocationProperty,
                 java.lang.String destinationFileName)
          throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to send a file to a server that requires authentication

Specified by:
send in interface XmlRpcService
Parameters:
serverURL -
username -
password -
sourceLocationProperty -
sourceFileName -
destinationLocationProperty -
destinationFileName -
Throws:
TurbineException

get

public void get(java.lang.String serverURL,
                java.lang.String sourceLocationProperty,
                java.lang.String sourceFileName,
                java.lang.String destinationLocationProperty,
                java.lang.String destinationFileName)
         throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to get a file from a server.

Specified by:
get in interface XmlRpcService
Parameters:
serverURL -
sourceLocationProperty -
sourceFileName -
destinationLocationProperty -
destinationFileName -
Throws:
TurbineException

get

public void get(java.lang.String serverURL,
                java.lang.String username,
                java.lang.String password,
                java.lang.String sourceLocationProperty,
                java.lang.String sourceFileName,
                java.lang.String destinationLocationProperty,
                java.lang.String destinationFileName)
         throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to get a file from a server that requires authentication.

Specified by:
get in interface XmlRpcService
Parameters:
serverURL -
username -
password -
sourceLocationProperty -
sourceFileName -
destinationLocationProperty -
destinationFileName -
Throws:
TurbineException

remove

public void remove(java.lang.String serverURL,
                   java.lang.String sourceLocationProperty,
                   java.lang.String sourceFileName)
            throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to remove a file from the server

Specified by:
remove in interface XmlRpcService
Parameters:
serverURL -
sourceLocationProperty -
sourceFileName -
Throws:
TurbineException

remove

public void remove(java.lang.String serverURL,
                   java.lang.String username,
                   java.lang.String password,
                   java.lang.String sourceLocationProperty,
                   java.lang.String sourceFileName)
            throws TurbineException
Deprecated. This is not scope of the Service itself but of an application which uses the service.

Method to allow a client to remove a file from a server that requires authentication.

Specified by:
remove in interface XmlRpcService
Parameters:
serverURL -
username -
password -
sourceLocationProperty -
sourceFileName -
Throws:
TurbineException

setParanoid

public void setParanoid(boolean state)
Switch client filtering on/off.

Specified by:
setParanoid in interface XmlRpcService
Parameters:
state - Whether to filter clients.
See Also:
acceptClient(java.lang.String), denyClient(java.lang.String)

acceptClient

public void acceptClient(java.lang.String address)
Add an IP address to the list of accepted clients. The parameter can contain '*' as wildcard character, e.g. "192.168.*.*". You must call setParanoid(true) in order for this to have any effect.

Specified by:
acceptClient in interface XmlRpcService
Parameters:
address - The address to add to the list.
See Also:
denyClient(java.lang.String), setParanoid(boolean)

denyClient

public void denyClient(java.lang.String address)
Add an IP address to the list of denied clients. The parameter can contain '*' as wildcard character, e.g. "192.168.*.*". You must call setParanoid(true) in order for this to have any effect.

Specified by:
denyClient in interface XmlRpcService
Parameters:
address - The address to add to the list.
See Also:
acceptClient(java.lang.String), setParanoid(boolean)

shutdown

public void shutdown()
Shuts down this service, stopping running threads.

Specified by:
shutdown in interface Initable
Overrides:
shutdown in class TurbineBaseService


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.