Extend this framework

How can I implement additional calls of services?


The central units from this framework are:

  • ServiceManager - Is a factory to create the service
  • Properties - To configure the Service Manager
  • Service Interface - Plain java class
  • Proxy/Executor
  • - All calls from Service Interface are delegated to Proxy/Executor.

Class Diagramm

class diagramm

Proxy Pattern

The framework distinguish two kinds of Proxies:

  • static proxy and
  • dynamic proxy
The differents between this two proxies are:
  • The static proxy is used, when the technology generate stubs and skeletons for the communication (RMI for example) or when the technology is responsible to generate the proxy object (EJB for example).
  • The dynamic proxy is used, when the developer has to implement the communication and call the method from the framework (XML-RPC or Web-Service for example).

Static Proxy

If you want create your own implementation with the static proxy, you have to extend the class net.sf.crispy.StaticProxy.

The extended static proxy class, is responsible for the method newInstance. The StaticEjbProxy for example makes in this method a JNDI lookup.

Dynamic Proxy

The framework support two implementation of Dynamic Proxies:

  • The Property.VALUE_FOR_JDK_DYNAMIC_PROXY - It is a implementation from the java.lang.reflect.Proxy from jdk. This proxy can only extend interfaces.
  • The Property.VALUE_FOR_CGLIB_DYNAMIC_PROXY - It is a implementation with CGLIB. This Proxy can extend interfaces and non final classes.

The DynamicProxy class needn't to extend. If you want to create an additional implementation, you have to extend the net.sf.crispy.Executor class. You have to implement the abstract method execute and the method getDefaultUrlAndPort. The execute method make the call to the remote server.

When the DynamicProxy is not enough, than can you make your own implementation. You must implement the methods:

  • newInstance - Create the proxy for the Service Interface.
  • invokeIfExecutorIsNull (optional) - This method is for the case, that none Executor is well know.

Test the own implementation of compatibility

After the implementation from your own extension, you can test the compatibility. This is possible with the net.sf.crispy.util.compatibility.CompatibilityKit:

CompatibilityKit compatibilityKit = new CompatibilityKit();
compatibilityKit.addProperty(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
compatibilityKit.makeAllTests("XmlRpc", new MiniXmlRpcServer());

You have to add the Executor or the StaticProxy class to the properties. If the CompatibilityKit has to manage a server instance, then one parameter is an instance of the net.sf.crispy.impl.MiniServer interface. This parameter is optional. If is no server set, the server has to be started externally.

for example:

java net.sf.crispy.impl.xmlrpc.MiniXmlRpcServer

If the test is not successful, then a CompatibilityException is thrown.