redstone.xmlrpc
Class XmlRpcProxy

java.lang.Object
  extended by redstone.xmlrpc.XmlRpcProxy
All Implemented Interfaces:
java.lang.reflect.InvocationHandler

public class XmlRpcProxy
extends java.lang.Object
implements java.lang.reflect.InvocationHandler

An XmlRpcProxy lets you use the services of an XML-RPC server through Java interfaces. It uses the Dynamic Proxy API introduced in JDK 1.3 to dynamically convert calls through Java interfaces to XML-RPC messages. This may be an improvement over the XmlRpcClient since using a server through Java interfaces allows compilation-time type checking, IDE code completion, and prevents typos and other errors.

Author:
Greger Olsson

Method Summary
static java.lang.Object createProxy(java.net.URL url, java.lang.Class[] interfaces, boolean streamMessages)
          Creates a new dynamic proxy object that implements all the supplied interfaces.
static java.lang.Object createProxy(java.net.URL url, java.lang.String objectName, java.lang.Class[] interfaces, boolean streamMessages)
          Creates a new dynamic proxy object that implements all supplied interfaces.
 java.util.Map getResponseHeaderFields()
          Returns the HTTP header fields from the latest server invocation.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          Handles method calls invoked on the proxy object.
 void setRequestProperties(java.util.Map requestProperties)
          Sets the HTTP request properties that the proxy will use for the next invocation, and any invocations that follow until setRequestProperties() is invoked again.
 void setRequestProperty(java.lang.String name, java.lang.String value)
          Sets a single HTTP request property to be used in future invocations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createProxy

public static java.lang.Object createProxy(java.net.URL url,
                                           java.lang.Class[] interfaces,
                                           boolean streamMessages)
Creates a new dynamic proxy object that implements all the supplied interfaces. This object may be type cast to any of the interface supplied in the call. Method calls through the interfaces will be translated to XML-RPC calls to the server in the supplied url.

Parameters:
url - The XML-RPC server that will receive calls through the interfaces.
interfaces - The list of interfaces the proxy should implement.
Returns:
An object implementing the supplied interfaces with XML-RPC support.

createProxy

public static java.lang.Object createProxy(java.net.URL url,
                                           java.lang.String objectName,
                                           java.lang.Class[] interfaces,
                                           boolean streamMessages)
Creates a new dynamic proxy object that implements all supplied interfaces. This object may be type cast to any of the interface supplied in the call. Method calls through the interfaces will be translated to XML-RPC calls to the server in the supplied url.

Parameters:
url - The XML-RPC server that will receive calls through the interfaces
interfaces - The list of interfaces the proxy should implement
objectName - The name under which the handler is reachable
Returns:
An object implementing the supplied interfaces with XML-RPC support

setRequestProperties

public void setRequestProperties(java.util.Map requestProperties)
Sets the HTTP request properties that the proxy will use for the next invocation, and any invocations that follow until setRequestProperties() is invoked again. Null is accepted and means that no special HTTP request properties will be used in any future XML-RPC invocations using this XmlRpcProxy instance.

Parameters:
requestProperties - The HTTP request properties to use for future invocations made using this XmlRpcProxy instance. These will replace any previous properties set using this method or the setRequestProperty() method.

setRequestProperty

public void setRequestProperty(java.lang.String name,
                               java.lang.String value)
Sets a single HTTP request property to be used in future invocations.

Parameters:
name - Name of the property to set
value - The value of the property
See Also:
setRequestProperties(Map)

getResponseHeaderFields

public java.util.Map getResponseHeaderFields()
Returns the HTTP header fields from the latest server invocation. These are the fields set by the HTTP server hosting the XML-RPC service.

Returns:
The HTTP header fields from the latest server invocation. Note that the XmlRpcClient instance retains ownership of this map and the map contents is replaced on the next request. If there is a need to keep the fields between requests the map returned should be cloned.

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws XmlRpcException,
                               XmlRpcFault
Handles method calls invoked on the proxy object. This is not used by the application but has to be public so that the dynamic proxy has access to it. It just hands the call over to the performCall method.

Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Returns:
Any of the values returned by an XmlRpcClient.
Throws:
XmlRpcException
XmlRpcFault
See Also:
"The Dynamic Proxy API in JDK 1.3"