Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact

Server

  1. Create Maven project with the followig POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.jalalkiswani</groupId>
	<version>4.0.4</version>
	<artifactId>smart-cloud-remote-reflection-server-example</artifactId>
	<dependencies>
		<dependency>
			<groupId>com.jalalkiswani</groupId>
			<artifactId>smart-cloud-util</artifactId>
			<version>4.0.8</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

If you are using Eclipse, be sure to refresh your project (select your project→ right click→ Maven→ Update Project)

  1. Create Service class with the following contents:

package com.app.server;

public class Service {
	public String hello(String name) {
		return "Hello " + name + " from server";
	}
}
  1. Create App class with the following contents:

package com.app.server;

import com.jk.util.reflection.server.ReflectionServer;

public class App {

	public static void main(String[] args) {
		ReflectionServer server = new ReflectionServer(7125);
		server.start();
	}
}

Now run the App main class, you should see something like this:

reflection server

Client

  1. Create Maven project with the followig POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.jalalkiswani</groupId>
	<version>4.0.4</version>
	<artifactId>smart-cloud-remote-reflection-client-example</artifactId>
	<dependencies>
		<dependency>
			<groupId>com.jalalkiswani</groupId>
			<artifactId>smart-cloud-util</artifactId>
			<version>4.0.8</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
  1. Create the client App class with the following contents:

package com.app.client;

import com.jk.util.reflection.client.ReflectionClient;
import com.jk.util.reflection.common.MethodCallInfo;

public class App {
	public static void main(String[] args) {
		ReflectionClient client=new ReflectionClient("localhost", 7125);
		MethodCallInfo info=new  MethodCallInfo("com.app.server.Service", "hello", "Jalal");
		client.callMethod(info);

		String result = (String) info.getResult();
		System.out.println(result);
	}
}

Now run the App main class, you should see something like this:

reflection client

Full example source-code can be found at https://github.com/smartapi-com/smart-cloud-remote-reflection


Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact