Remote Reflection is a Java API which make it easier to call remote methods on remote JVM in very simple way without the need for any special configurations or common contract between client and server.
Test Service
package com.app.server;
public class TestService {
public String hello(String name) {
return "Hello " + name + " from server";
}
}
Server
In the server application(the application which you want to expose its method remotely) , add the following after at the end of you main method:
package com.app.server;
import com.jk.util.reflection.server.ReflectionServer;
public class ServiceServer {
public static void main(String[] args) {
int port=7125;
ReflectionServer server = new ReflectionServer(port);
server.start();
}
}
Thats it , now you can expose any method inside this application VM to your application client.
Client
In the client application(the application which should consume the remote method):
package com.app.client;
import com.jk.util.reflection.client.ReflectionClient;
import com.jk.util.reflection.common.MethodCallInfo;
public class ServiceClient {
public static void main(String[] args) {
ReflectionClient client=new ReflectionClient("localhost", 7125);
MethodCallInfo info=new MethodCallInfo("com.app.server.TestService", "hello", "Jalal");
client.callMethod(info);
String result = (String) info.getResult();
System.out.println(result);
}
}