marquee.xmlrpc.processors
Class FilterInvocationProcessor

java.lang.Object
  extended by marquee.xmlrpc.processors.FilterInvocationProcessor
All Implemented Interfaces:
XmlRpcInvocationProcessor
Direct Known Subclasses:
AllowInvocationProcessor

public class FilterInvocationProcessor
extends java.lang.Object
implements XmlRpcInvocationProcessor

A sample processor that allows invocations to be filtered out based on the IP address of the caller and, optionally, a handler. The example may be extended to support filtering on a single method of a handler. The code is somewhat lengthy, as are all examples. This could be used in production code, but should be tested thoroughly first.

Since:
JDK 1.1
Version:
$Revision: 1.4 $
Author:
Greger Ohlson (greger.ohlson@marquee.se)

Constructor Summary
FilterInvocationProcessor()
           
 
Method Summary
 void addFilters(java.lang.String handler, java.util.List filterList)
          Adds a filter to the processor, comprising of an optional handler name and a list of IP masks.
 void addFiltersByName(java.lang.String handler, java.util.List filterList)
          Adds a filter to the processor, comprising of an optional handler name and a list of IP masks.
 void onException(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments, java.lang.Throwable exception)
          Does nothing.
 java.lang.Object postProcess(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments, java.lang.Object returnValue)
          Does nothing.
 boolean preProcess(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments)
          Examines the caller IP and the method to see if the invocation should be performed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilterInvocationProcessor

public FilterInvocationProcessor()
Method Detail

addFilters

public final void addFilters(java.lang.String handler,
                             java.util.List filterList)
Adds a filter to the processor, comprising of an optional handler name and a list of IP masks.

Note! This method takes the ownership of the supplied filter List. That is, the supplied List should not be used after calling this method.

Parameters:
handler - The handler to which the filter should apply, or null, if the filters should apply to all handlers.
filterList - A list of strings containing IP addresses with or without wildcards. For instance, 192.168.*.* is a valid filter entry.

addFiltersByName

public void addFiltersByName(java.lang.String handler,
                             java.util.List filterList)
                      throws java.lang.IllegalArgumentException,
                             java.net.UnknownHostException
Adds a filter to the processor, comprising of an optional handler name and a list of IP masks.

Note! This method takes the ownership of the supplied filter List. That is, the supplied List should not be used after calling this method.

Parameters:
filterList - A list of strings containing IP addresses with or without wildcards. For instance, 192.168.*.* is a valid filter entry.
Throws:
java.lang.IllegalArgumentException
java.net.UnknownHostException

preProcess

public boolean preProcess(int callId,
                          java.lang.String callerIp,
                          java.lang.String handler,
                          java.lang.String method,
                          java.util.List arguments)
Examines the caller IP and the method to see if the invocation should be performed.

Specified by:
preProcess in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method being called.
arguments - The arguments that will be sent to the method.
Returns:
true if the invocation should proceed, or false if not.

postProcess

public java.lang.Object postProcess(int callId,
                                    java.lang.String callerIp,
                                    java.lang.String handler,
                                    java.lang.String method,
                                    java.util.List arguments,
                                    java.lang.Object returnValue)
Does nothing.

Specified by:
postProcess in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method that just has returned.
returnValue - The objects returned by the method. If the method returned a primitive, it is wrapped in its object counterpart.
Returns:
The (possibly modified) returnValue argument.

onException

public void onException(int callId,
                        java.lang.String callerIp,
                        java.lang.String handler,
                        java.lang.String method,
                        java.util.List arguments,
                        java.lang.Throwable exception)
Does nothing.

Specified by:
onException in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method that just has returned by throwing an exception.
exception - The exception thrown by the method.