CRISPY = Communication per Remote Invocation for different kinds of Services via ProxYs.
The intention for this project is a very simple API to call different kinds of services (provider/technology). Crispy's aims is to provide a single point of entry for remote invocation for a wide number of transports: eg. RMI, EJB, JAX-RPC or XML-RPC. It works by using properties to configure a service manager, which is then used to invoke the remote API. Crispy is a simple Java codebase with an API that sits between your client code and the services your code must access. It provides a layer of abstraction to decouple client code from access to a service, as well as its location and underlying implementation. The special on this idea is, that these calls are simple Java object calls (remote or local calls are transparent).
From Crispy supported transport provider are:
=> All calls can execute synchronous or asynchronous (see the user guide).
What must I do, when I want to invoke a remote method/service. In this section you can get a comparsion from the native remote API (e.g. WebService and XML-RPC) and a Crispy call.
Service service = (Service) ServiceFactory.newInstance().createService(null); Call call = service.createCall(); call.setTargetEndpointAddress("http://localhost:9080/axis/services/Calculator"); call.setOperationName(new QName("add")); QName paramXmlType = new QName(int.class.getName()); call.addParameter("arg0", paramXmlType, int.class, ParameterMode.IN); call.addParameter("arg1", paramXmlType, int.class, ParameterMode.IN); call.setReturnType(new QName(int.class.getName())); Integer result = (Integer) call.invoke(new Integer[] {new Integer(1), new Integer(2)}); System.out.println("1 + 2 = " + result);
XmlRpcClient client = new XmlRpcClient("http://localhost:9090"); Vector param = new Vector(); param.add(new Integer(1)); param.add(new Integer(2)); Integer result = (Integer) client.execute("test.crispy.example.service.Calculator.add", param); System.out.println("1 + 2 = " + result);
Two steps to success:
Properties prop = new Properties(); prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9080/axis/services"); prop.put(Property.EXECUTOR_CLASS, JaxRpcExecutor.class.getName()); ServiceManager manager = new ServiceManager(prop); Calculator calc = (Calculator) manager.createService(Calculator.class); System.out.println("1 + 2 = " + calc.add(1, 2));
Properties prop = new Properties(); prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090"); prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName()); ServiceManager manager = new ServiceManager(prop); Calculator calc = (Calculator) manager.createService(Calculator.class); System.out.println("1 + 2 = " + calc.add(1, 2));
=> Properties can loaded with a implemetation from the net.sf.crispy.PropertiesLoader.
If two or more communication partner exist:
This little story describe the problems and the solution by finding the right solution for a service invocation:
Developer | Crispy |
---|---|
I want to communicate with a remote service! What I have to do? | You have to find the right remote technology for your plans. |
What is the right technology? I don't know! | I know this problem. A decision for a concrete technology is not easy, but important for a successful project (performance, security, interoperability and so on). |
What must I do after the decision? | If you don't know the technology, you must learn, how the remote technology work. |
I decided for a technology and I have implemented some services. Now, I find the remote invocations are to slow. | Change the remote technology! |
The remote invocations are on many different places in my source code! The changes are very expensive! | You need a transparent remote invocation on a central place in your source code. Than you can easy change the service technology (how Crispy). |