diff --git a/docker/example-server/resources/server/CHANGELOG.md b/docker/example-server/resources/server/CHANGELOG.md
new file mode 100644
index 0000000..c7ffed1
--- /dev/null
+++ b/docker/example-server/resources/server/CHANGELOG.md
@@ -0,0 +1,19 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+
+## v4.1.0 - Nov 12, 2023
+
+### Added
+
+* Add an additional RemoteObject using a custom socket factory class
+
+
+## v4.0.0 and before
+
+Changelog entries can be found within the global [CHANGELOG.md](/CHANGELOG.md) file
+of remote-method-guesser.
diff --git a/docker/example-server/resources/server/pom.xml b/docker/example-server/resources/server/pom.xml
index c3694b5..3e4a730 100644
--- a/docker/example-server/resources/server/pom.xml
+++ b/docker/example-server/resources/server/pom.xml
@@ -3,7 +3,7 @@
4.0.0
de.qtc.rmg.server.ExampleServer
rmg-example-server
- 3.3.0
+ 4.1.0
rmg-example-server
RMG Example Server
@@ -49,6 +49,11 @@
de.qtc.rmg.server.ExampleServer
+
+
+ Tobias Neitzel (@qtc_de)
+
+
jar-with-dependencies
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/ExampleServer.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/ExampleServer.java
index 39dc38f..261ebd9 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/ExampleServer.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/ExampleServer.java
@@ -12,6 +12,7 @@
import javax.rmi.ssl.SslRMIServerSocketFactory;
import de.qtc.rmg.server.activation.ActivationServer;
+import de.qtc.rmg.server.factory.CustomSocketFactoryServer;
import de.qtc.rmg.server.interfaces.IPlainServer;
import de.qtc.rmg.server.interfaces.ISecureServer;
import de.qtc.rmg.server.interfaces.ISslServer;
@@ -22,28 +23,40 @@
import de.qtc.rmg.server.utils.Logger;
import de.qtc.rmg.server.utils.Utils;
-public class ExampleServer {
+public class ExampleServer
+{
+ private static final int registryPort = 1090;
+ private static final int activatorPort = 1098;
+ private static final int plainRegistryPort = 9010;
- private static int registryPort = 1090;
- private static Remote remoteObject1 = null;
- private static Remote remoteObject2 = null;
- private static Remote remoteObject3 = null;
+ private static Remote remoteObjectOne;
+ private static Remote remoteObjectTwo;
+ private static Remote remoteObjectThree;
+
+ private static final String boundNameOne = "plain-server";
+ private static final String boundNameTwo = "ssl-server";
+ private static final String boundNameThree = "secure-server";
public static void main(String[] argv)
{
String disableColor = System.getProperty("de.qtc.rmg.server.disableColor");
+
if (disableColor != null && disableColor.equalsIgnoreCase("true"))
+ {
Logger.disableColor();
+ }
Logger.println("Initializing Java RMI Server:");
Logger.println("");
Logger.increaseIndent();
- if (System.getSecurityManager() == null) {
+ if (System.getSecurityManager() == null)
+ {
System.setSecurityManager(new SecurityManager());
}
- try {
+ try
+ {
SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory();
@@ -53,30 +66,47 @@ public static void main(String[] argv)
Logger.println("");
Logger.printlnMixedBlue("Creating", "PlainServer", "object.");
- remoteObject1 = new PlainServer();
- IPlainServer stub = (IPlainServer)UnicastRemoteObject.exportObject(remoteObject1, 0);
- Utils.bindToRegistry(stub, registry, "plain-server");
+ remoteObjectOne = new PlainServer();
+ IPlainServer stub = (IPlainServer)UnicastRemoteObject.exportObject(remoteObjectOne, 0);
+ Utils.bindToRegistry(stub, registry, boundNameOne);
Logger.printlnMixedBlue("Creating", "SSLServer", "object.");
- remoteObject2 = new SslServer();
- ISslServer stub2 = (ISslServer)UnicastRemoteObject.exportObject(remoteObject2, 0, csf, ssf);
- Utils.bindToRegistry(stub2, registry, "ssl-server");
+ remoteObjectTwo = new SslServer();
+ ISslServer stub2 = (ISslServer)UnicastRemoteObject.exportObject(remoteObjectTwo, 0, csf, ssf);
+ Utils.bindToRegistry(stub2, registry, boundNameTwo);
Logger.printlnMixedBlue("Creating", "SecureServer", "object.");
- remoteObject3 = new SecureServer();
- ISecureServer stub3 = (ISecureServer)UnicastRemoteObject.exportObject(remoteObject3, 0);
- Utils.bindToRegistry(stub3, registry, "secure-server");
+ remoteObjectThree = new SecureServer();
+ ISecureServer stub3 = (ISecureServer)UnicastRemoteObject.exportObject(remoteObjectThree, 0);
+ Utils.bindToRegistry(stub3, registry, boundNameThree);
Logger.decreaseIndent();
Logger.println("");
Logger.println("Server setup finished.");
- Logger.println("Initializing legacy server.");
+ Logger.println("Initializing LegacyServer.");
+ Logger.println("");
+
+ LegacyServer.init(plainRegistryPort);
+
+ Logger.println("LegacyServer setup finished.");
+ Logger.println("Initializing ActivationServer.");
Logger.println("");
- LegacyServer.init();
- ActivationServer.init();
+ ActivationServer.init(activatorPort);
+
+ Logger.println("ActivationServer setup finished.");
+ Logger.println("Initializing CustomSocketFactoryServer.");
+ Logger.println("");
+
+ CustomSocketFactoryServer.startServer(plainRegistryPort);
+
+ Logger.println("Setup finished.");
+ Logger.println("Waiting for incoming connections.");
+ Logger.println("");
+ }
- } catch (RemoteException | AlreadyBoundException | NotBoundException e) {
+ catch (RemoteException | AlreadyBoundException | NotBoundException e)
+ {
Logger.eprintln("Unexpected RMI Error:");
e.printStackTrace();
}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationServer.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationServer.java
index ee1abab..02c777d 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationServer.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationServer.java
@@ -30,10 +30,13 @@
@SuppressWarnings("unused")
public class ActivationServer
{
- private static int activationSystemPort = 1098;
- private static Remote remoteObject1 = null;
- private static Remote remoteObject2 = null;
- private static Remote remoteObject3 = null;
+ private static Remote remoteObjectOne;
+ private static Remote remoteObjectTwo;
+ private static Remote remoteObjectThree;
+
+ private static final String boundNameOne = "activation-test";
+ private static final String boundNameTwo = "activation-test2";
+ private static final String boundNameThree = "plain-server";
private final static String codebase = "file:///opt/example-server.jar";
@@ -42,11 +45,12 @@ public class ActivationServer
* group is created and two activatable RMI services are bound to the registry. Additionally, we bind one
* non activatable service.
*/
- public static void init()
+ public static void init(int activationSystemPort)
{
Logger.increaseIndent();
- try {
+ try
+ {
Logger.printMixedBlue("Creating", "ActivationSystem", "on port ");
Logger.printlnPlainYellow(String.valueOf(activationSystemPort));
Utils.startActivation(activationSystemPort, null, "/tmp/activation-log", null);
@@ -90,28 +94,25 @@ public static void init()
Utils.toogleOutput();
ActivationDesc desc = new ActivationDesc(groupID, ActivationService.class.getName(), codebase, null);
- remoteObject1 = Activatable.register(desc);
+ remoteObjectOne = Activatable.register(desc);
ActivationDesc desc2 = new ActivationDesc(groupID, ActivationService2.class.getName(), codebase, null);
- remoteObject2 = Activatable.register(desc2);
-
- remoteObject3 = new PlainServer();
- IPlainServer stub = (IPlainServer)UnicastRemoteObject.exportObject(remoteObject3, 0);
-
- Utils.bindToRegistry(remoteObject1, LocateRegistry.getRegistry(activationSystemPort), "activation-test");
- Utils.bindToRegistry(remoteObject2, LocateRegistry.getRegistry(activationSystemPort), "activation-test2");
- Utils.bindToRegistry(stub, LocateRegistry.getRegistry(activationSystemPort), "plain-server");
+ remoteObjectTwo = Activatable.register(desc2);
- Logger.println("");
- Logger.decreaseIndent();
+ remoteObjectThree = new PlainServer();
+ IPlainServer stub = (IPlainServer)UnicastRemoteObject.exportObject(remoteObjectThree, 0);
- Logger.println("Server setup finished.");
- Logger.println("Waiting for incoming connections.");
- Logger.println("");
+ Utils.bindToRegistry(remoteObjectOne, LocateRegistry.getRegistry(activationSystemPort), boundNameOne);
+ Utils.bindToRegistry(remoteObjectTwo, LocateRegistry.getRegistry(activationSystemPort), boundNameTwo);
+ Utils.bindToRegistry(stub, LocateRegistry.getRegistry(activationSystemPort), boundNameThree);
+ }
- } catch (Exception e) {
+ catch (Exception e)
+ {
Logger.eprintln("Unexpected RMI Error:");
e.printStackTrace();
}
- }
+
+ Logger.println("");
+ Logger.decreaseIndent(); }
}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService.java
index cb0a6cd..011c182 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService.java
@@ -54,4 +54,4 @@ public String system(String command, String[] args)
return result;
}
-}
\ No newline at end of file
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService2.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService2.java
index 0db0a0a..f2c5673 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService2.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/ActivationService2.java
@@ -55,4 +55,4 @@ public void updatePreferences(ArrayList preferences) throws RemoteExcept
Logger.printlnMixedBlueYellow("[SecureServer]:", "Processing call for", "void updatePreferences(ArrayList preferences)");
this.preferences = preferences;
}
-}
\ No newline at end of file
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService.java
index e74260c..40ed5cf 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService.java
@@ -7,4 +7,4 @@ public interface IActivationService extends Remote
{
String execute(String cmd) throws RemoteException;
String system(String cmd, String[] args) throws RemoteException;
-}
\ No newline at end of file
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService2.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService2.java
index adde23e..1bf8094 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService2.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/activation/IActivationService2.java
@@ -10,4 +10,4 @@ public interface IActivationService2 extends Remote
String login(HashMap credentials) throws RemoteException;
void logMessage(int logLevel, Object message) throws RemoteException;
void updatePreferences(ArrayList preferences) throws RemoteException;
-}
\ No newline at end of file
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactory.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactory.java
new file mode 100644
index 0000000..202ced7
--- /dev/null
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactory.java
@@ -0,0 +1,28 @@
+package de.qtc.rmg.server.factory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.RMISocketFactory;
+
+public class CustomSocketFactory extends RMISocketFactory implements Serializable
+{
+ private static final long serialVersionUID = -1168901302380021730L;
+ private final transient RMISocketFactory defaultFax;
+
+ public CustomSocketFactory()
+ {
+ defaultFax = RMISocketFactory.getDefaultSocketFactory();
+ }
+
+ public ServerSocket createServerSocket(int arg0) throws IOException
+ {
+ return defaultFax.createServerSocket(arg0);
+ }
+
+ public Socket createSocket(String arg0, int arg1) throws IOException
+ {
+ return defaultFax.createSocket(arg0, arg1);
+ }
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactoryServer.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactoryServer.java
new file mode 100644
index 0000000..dffae55
--- /dev/null
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/factory/CustomSocketFactoryServer.java
@@ -0,0 +1,52 @@
+package de.qtc.rmg.server.factory;
+
+import java.rmi.AlreadyBoundException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.UnicastRemoteObject;
+
+import de.qtc.rmg.server.interfaces.IPlainServer;
+import de.qtc.rmg.server.operations.PlainServer;
+import de.qtc.rmg.server.utils.Logger;
+import de.qtc.rmg.server.utils.Utils;
+
+public class CustomSocketFactoryServer
+{
+ private static Remote remoteObjectOne;;
+ private static final String boundName = "custom-socks";
+
+ public static void startServer(int registryPort)
+ {
+ Logger.increaseIndent();
+
+ try
+ {
+ RMISocketFactory csf = new CustomSocketFactory();
+
+ Logger.printMixedBlue("Locating", "RMI-Registry", "on port ");
+ Logger.printlnPlainYellow(String.valueOf(registryPort));
+ Registry registry = LocateRegistry.getRegistry(registryPort);
+ Logger.println("");
+
+ Logger.printlnMixedBlue("Creating", "PlainServer", "object.");
+ remoteObjectOne = new PlainServer();
+ IPlainServer stub = (IPlainServer)UnicastRemoteObject.exportObject(remoteObjectOne, 0, csf, null);
+ Utils.bindToRegistry(stub, registry, boundName);
+
+ Logger.println("Server setup finished.");
+ }
+
+ catch (RemoteException | AlreadyBoundException | NotBoundException e)
+ {
+ Logger.eprintln("Unexpected RMI Error:");
+ e.printStackTrace();
+ }
+
+ Logger.println("");
+ Logger.decreaseIndent();
+ }
+}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/legacy/LegacyServer.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/legacy/LegacyServer.java
index 4baa313..2af8e65 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/legacy/LegacyServer.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/legacy/LegacyServer.java
@@ -16,71 +16,77 @@
import de.qtc.rmg.server.utils.Utils;
@SuppressWarnings("unused")
-public class LegacyServer {
-
- private static int registryPort = 9010;
- private static Remote remoteObject1 = null;
- private static Remote remoteObject2 = null;
- private static Remote remoteObject3 = null;
- private static Remote remoteObject4 = null;
-
-
- public static void init()
+public class LegacyServer
+{
+ private static Remote remoteObjectOne;
+ private static Remote remoteObjectTwo;
+ private static Remote remoteObjectThree;
+ private static Remote remoteObjectFour;
+
+ private static final String boundNameOne = "legacy-service";
+ private static final String boundNameTwo = "plain-server";
+ private static final String boundNameThree = "plain-server2";
+
+ public static void init(int registryPort)
{
Logger.increaseIndent();
- try {
+ try
+ {
Logger.printMixedBlue("Creating", "RMI-Registry", "on port ");
Logger.printlnPlainYellow(String.valueOf(registryPort));
Registry registry = LocateRegistry.createRegistry(registryPort);
Logger.println("");
Logger.printlnMixedBlue("Creating", "LegacyServiceImpl", "object.");
- remoteObject1 = new LegacyServiceImpl();
+ remoteObjectOne = new LegacyServiceImpl();
Logger.increaseIndent();
Logger.printMixedYellow("Binding", "LegacyServiceImpl");
Logger.printlnPlainMixedBlue(" as", "legacy-service");
- Naming.rebind("//127.0.0.1:" + registryPort + "/legacy-service", remoteObject1);
+ Naming.rebind("//127.0.0.1:" + registryPort + "/legacy-service", remoteObjectOne);
Object o = registry.lookup("legacy-service");
String className = o.getClass().getName();
- Logger.printMixedYellow("Boundname", "legacy-service");
+ Logger.printMixedYellow("Boundname", boundNameOne);
Logger.printlnPlainMixedBlue(" with class", className, "is ready.");
Logger.decreaseIndent();
Logger.printlnMixedBlue("Creating", "PlainServer", "object.");
- remoteObject2 = new PlainServer();
- IPlainServer stub1 = (IPlainServer)UnicastRemoteObject.exportObject(remoteObject2, 0);
- Utils.bindToRegistry(stub1, registry, "plain-server");
+ remoteObjectTwo = new PlainServer();
+ IPlainServer stub1 = (IPlainServer)UnicastRemoteObject.exportObject(remoteObjectTwo, 0);
+ Utils.bindToRegistry(stub1, registry, boundNameTwo);
Logger.printlnMixedBlue("Creating another", "PlainServer", "object.");
- remoteObject3 = new PlainServer();
- IPlainServer stub2 = (IPlainServer)UnicastRemoteObject.exportObject(remoteObject3, 0);
- Utils.bindToRegistry(stub2, registry, "plain-server2");
+ remoteObjectThree = new PlainServer();
+ IPlainServer stub2 = (IPlainServer)UnicastRemoteObject.exportObject(remoteObjectThree, 0);
+ Utils.bindToRegistry(stub2, registry, boundNameThree);
- try {
+ try
+ {
Logger.printlnMixedBlue("Creating", "ActivatorImp", "object.");
Logger.increaseIndent();
- remoteObject4 = Utils.getActivator(registryPort, null);
+ remoteObjectFour = Utils.getActivator(registryPort, null);
Logger.printlnMixedYellowFirst("Activator", "is ready.");
+ }
- } catch( Exception e) {
+ catch (Exception e)
+ {
Logger.printlnYellow("Activator initialization failed.");
+ }
- } finally {
+ finally
+ {
Logger.decreaseIndent();
}
Logger.println("");
Logger.decreaseIndent();
+ }
- Logger.println("Server setup finished.");
- Logger.println("Initializing activation server.");
- Logger.println("");
-
- } catch (RemoteException | MalformedURLException | AlreadyBoundException | NotBoundException e) {
+ catch (RemoteException | MalformedURLException | AlreadyBoundException | NotBoundException e)
+ {
Logger.eprintln("Unexpected RMI Error:");
e.printStackTrace();
}
diff --git a/docker/example-server/resources/server/src/de/qtc/rmg/server/utils/Utils.java b/docker/example-server/resources/server/src/de/qtc/rmg/server/utils/Utils.java
index df3d800..65463c7 100644
--- a/docker/example-server/resources/server/src/de/qtc/rmg/server/utils/Utils.java
+++ b/docker/example-server/resources/server/src/de/qtc/rmg/server/utils/Utils.java
@@ -114,4 +114,4 @@ public static void bindToRegistry(Remote object, Registry registry, String bound
Logger.printlnPlainMixedBlue(" with interface", className, "is ready.");
Logger.decreaseIndent();
}
-}
\ No newline at end of file
+}