Quick Start

Two Steps to success.

  • First step: Create properties. The properties describe the behaviour and the kind of the service.
  • Second step: Create a ServiceManager instance (this class is a factory for the services) and then create a concrete service instance. Invoke all methods on the service instance just like a call from Java objects.

The second step is always the same. Different are the properties.

A minimal example for a XML-RPC-Service with local server instance.

  1. Download the XML-RPC libraries or download crispy-bin-${version}.zip.
    • commons-codec (XML-RPC)
    • commons-httpclient (XML-RPC)
    • xmlrpc (XML-RPC)
    • commons-logging (jakarta commons logging)
    • Crispy (Crispy)
  2. Set libraries in the class path.
  3. Invoke the sample.

import java.util.Properties;

import test.crispy.example.service.Echo;

import net.sf.crispy.Property;
import net.sf.crispy.impl.MiniServer;
import net.sf.crispy.impl.ServiceManager;
import net.sf.crispy.impl.XmlRpcExecutor;
import net.sf.crispy.impl.xmlrpc.MiniXmlRpcServer;

public static void main(String[] args) {

	MiniServer miniServer = null;
	
	try {
		// Server part
		miniServer = new MiniXmlRpcServer();
		miniServer.addService(Echo.class.getName(), EchoImpl.class.getName());
		miniServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
		miniServer.start();
		

		// Client part				
		Properties prop = new Properties();
		prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
	       
		ServiceManager manager = new ServiceManager(prop);
		Echo echo = (Echo) manager.createService(Echo.class);
		System.out.println("Echo: " + echo.echo("Hello Crispy"));
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	finally {
		miniServer.stop();
	}
}

Examples

=> Details you can see on the User Guide or Developer Guide.

Create a service interface and implementation

	
public interface Calculator {

	public int add(int a, int b);
	public int subtract(int a, int b);
}
	
public class CalculatorImpl implements Calculator {

	public int add(int a, int b) { return a + b; }
	public int subtract(int a, int b) { return a - b; }

}

Create the service and work

// configuration, see step one
Properties prop = new Properties();

// the properties, dependent on the kind of call
...

// create ServiceManager (Factory) with properties from step one
ServiceManager serviceManager = new ServiceManager(prop);

// create service (interface)
Calculator calculator = (Calculator) serviceManager.createService(Calculator.class);

// simple Java object calls
int result = calculator.add(2, 3);
result = calculator.subtract(8, 2);

Concrete transport provider

Local Java call

// Map the interface Calculator to implementation CalculatorImpl
prop.put(Calculator.class.getName(),CalculatorImpl.class.getName()); 

ServiceManager lvServiceManager = new ServiceManager(prop);
Echo lvEcho = (Echo) pvServiceManager.createService(Echo.class);
System.out.println("Echo: " + lvEcho.echo("Hello Crispy!");

Alternative you can use a pseudo server:

MiniLocalObjectServer server = new MiniLocalObjectServer();
// add service interface and service implemantation    	
server.addService(Echo.class, new EchoImpl());
server.start();
    	
Properties prop = new Properties();
prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
        
ServiceManager lvServiceManager = new ServiceManager(prop);
Echo lvEcho = (Echo) pvServiceManager.createService(Echo.class);
System.out.println("Echo: " + lvEcho.echo("Hello Crispy!");

Http call with Java Serializer

Properties:

Properties prop = new Properties();
prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName());
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8111/crispy/httpserializer");

Create your own HttpServlet:

public class MyHttpServlet extends net.sf.crispy.impl.http.HttpServlet {

  public void init(ServletConfig config) throws ServletException {
    addService(Echo.class.getName(), new EchoImpl ());
  }  
}

Or test with the MiniHttpServer:

MiniServer miniServer = new MiniHttpServer();
miniServer.addService(Echo.class.getName(), EchoImpl.class.getName());
miniServer.start();			

XML-RPC call

Properties:

// load an Executor, all calls are delegated to this class (proxy pattern)
prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
// url and port of server
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8080");

Create your own XmlServlet, overwrite the init method and register the servlet in the web.xml:

public class MyXmlRpcHttpServlet extends XmlRpcHttpServlet {

  ...
  
  public void init(ServletConfig config) throws ServletException {
    addService(MyServiceInterface.class.getName(), new MyServiceImpl());  
  }  
  
  ...
}

Alternative start the mini server and deploy a service implementation:

MiniXmlRpcServer miniServer = new MiniXmlRpcServer();
miniServer.addService(Echo.class.getName(), EchoImpl.class.getName());
miniServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
miniServer.start();

RMI call

Properties dynamic RMI (a Crispy implementation):

// load an Executor, all calls are delegated to this class (proxy pattern)
prop.put(Property.EXECUTOR_CLASS, RmiExecutor.class.getName());
// url and port of server
prop.put(Property.REMOTE_URL_AND_PORT, "rmi://localhost:1099");

Properties static RMI, traditional RMI call:

// must extend java.rmi.Remote and throws java.rmi.RemoteException
prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
// url and port of server
prop.put(Property.REMOTE_URL_AND_PORT, "rmi://localhost:1099");
// register service with lookup name
prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);

Or start the MiniRmiServer:

MiniRmiServer miniServer = new MiniRmiServer();

// by RmiExecutor you can add a service implementation
server.addService (Echo.class.getName(), new EchoImpl());

// OR
// by StaticRmiProxy you can add a service implementation
serever.addService (Echo.class.getName(), new EchoImpl());

miniServer.start();

EJB call

Properties:

// Map Service to JNDI-Name and Home interface properties and create proxy for EJBs calls
prop.put(EjbService.class.getName(), EjbService.JNDI_NAME);
// map to the home-interface, with this interface can create the instance
prop.put(EjbService.class.getName() + Property.EJB_HOME_INTERFACE, EjbServiceHome.class.getName());
// delegate calls to proxy
prop.put(Property.STATIC_PROXY_CLASS, StaticEjbProxy.class.getName());

WebService (JAX-RPC) call

Properties:

// load an Executor, all calls are delegated to this class (proxy pattern)
prop.put(Property.EXECUTOR_CLASS, JaxRpcExecutor.class.getName());
// url and port from server
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8080/axis/services");

Start the server:

MiniServer miniServer = new MiniAxisServer();
miniServer.start();

Burlap and Hessian (Caucho) call

Properties:

// load Static-Proxy for Burlap implementation
props.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName());
// url and port from server
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8091/crispy/burlap");



// load Static-Proxy for Hessian implementation
props.put(Property.STATIC_PROXY_CLASS, StaticHessianProxy.class.getName());
// url and port from server
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8091/crispy/hessian");

Create your own Burlap/Hessian-Servlet, overwrite the init method and register the servlet in the web.xml:

public class MyBurlapServlet extends BurlapServlet {

  public void init(ServletConfig config) throws ServletException {
    super.addCache(Echo.class.getName(), new BurlapSkeleton(new EchoImpl()));
  }  
}

public class MyHessianServlet extends HessianServlet {

  public void init(ServletConfig config) throws ServletException {
    super.addCache(Echo.class.getName(), new HessianSkeleton(new EchoImpl(), Echo.class));
  }  
}

Or start the MiniCauchoServer:

MiniServer miniServer = new MiniCauchoServer();
miniServer.addService(Echo.class.getName(), EchoImpl.class.getName());
miniServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
miniServer.start();

Crispy REST implementation

Properties:

// url and port from server
prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8092/crispy/rest");
prop.put(Property.EXECUTOR_CLASS, RestExecutor.class.getName());

Create your own RestServlet, overwrite the init method and register the servlet in the web.xml:

public class MyRestServlet extends RestServlet {

  public void init(ServletConfig config) throws ServletException {
    addService(Echo.class.getName(), new EchoImpl ());
    addService("service.echo", new EchoImpl ());		
  }  
}

Or start the MiniRestServer:

MiniServer miniServer = new MiniRestServer();
miniServer.addService(Echo.class.getName(), EchoImpl.class.getName());
miniServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
miniServer.start();

Corba (experimental)

Properties:

// url and port from server
prop.put(Property.REMOTE_URL_AND_PORT, "127.0.0.1:1057");
prop.put(Property.STATIC_PROXY_CLASS, StaticCorbaProxy.class.getName());

MiniCorbaServer:

MiniServer miniServer = new MiniCorbaServer();
miniServer.addService("test.crispy.example.service.corba.Echo", "test.crispy.example.service.CorbaEcho");
miniServer.start();