bridge (now with a script to start it, too)
authorNiki Roo <niki@nikiroo.be>
Fri, 22 Jun 2018 04:58:05 +0000 (04:58 +0000)
committerNiki Roo <niki@nikiroo.be>
Fri, 22 Jun 2018 04:58:05 +0000 (04:58 +0000)
bridge [new file with mode: 0755]
src/be/nikiroo/utils/main/bridge.java [new file with mode: 0644]
src/be/nikiroo/utils/serial/server/ServerBridge.java

diff --git a/bridge b/bridge
new file mode 100755 (executable)
index 0000000..a937348
--- /dev/null
+++ b/bridge
@@ -0,0 +1,19 @@
+#!/bin/sh
+NAME=nikiroo-utils.jar
+
+jar="$NAME"
+if [ ! -e "$jar" ]; then
+       jar="`dirname "$0"`/$NAME"
+fi
+
+if [ ! -e "$jar" ]; then
+       jar="`whereis "$NAME" | sed 's: :\n:g' | grep "$NAME" | head -n1`"
+fi
+
+if [ ! -e "$jar" ]; then
+       echo "$NAME not found." >&2
+       exit 1
+fi
+
+exec java -cp "$jar" be.nikiroo.utils.main.bridge "$@"
+
diff --git a/src/be/nikiroo/utils/main/bridge.java b/src/be/nikiroo/utils/main/bridge.java
new file mode 100644 (file)
index 0000000..8aaa93f
--- /dev/null
@@ -0,0 +1,72 @@
+package be.nikiroo.utils.main;
+
+import be.nikiroo.utils.TraceHandler;
+import be.nikiroo.utils.serial.server.ServerBridge;
+
+/**
+ * Serialiser bridge (starts a {@link ServerBridge} and can thus intercept
+ * communication between a client and a server).
+ * 
+ * @author niki
+ */
+public class bridge {
+       /**
+        * Start a bridge between 2 servers.
+        * 
+        * @param args
+        *            an array containing:
+        *            <ul>
+        *            <li>The bridge name</li>
+        *            <li>The bridge port</li>
+        *            <li>TRUE for an SSL bridge, FALSE for plain text</li>
+        *            <li>The forward server host</li>
+        *            <li>The forward server port</li>
+        *            <li>TRUE for an SSL forward server, FALSE for plain text</li>
+        *            <li>(optional) a trace level</li>
+        *            <li>(optional) a truncate size for data</li>
+        *            </ul>
+        */
+       public static void main(String[] args) {
+               final TraceHandler tracer = new TraceHandler(true, false, 0);
+               try {
+                       if (args.length < 6) {
+                               tracer.error("Invalid syntax.\n"
+                                               + "Syntax: [name] [port] [ssl] [fhost] [fport] [fssl] ([trace level]) ([max])\n"
+                                               + "\tname: the bridge name\n"
+                                               + "\tport: the bridge port\n"
+                                               + "\tssl: TRUE for an SSL bridge, FALSE for plain text\n"
+                                               + "\tfhost: the forward server host\n"
+                                               + "\tfport: the forward server port\n"
+                                               + "\tfssl: TRUE for an SSL forward server, FALSE for plain text\n"
+                                               + "\ttrace level: the optional trace level (default is 1)\n"
+                                               + "\tmax: the maximum size after which to truncate data\n");
+                               return;
+                       }
+
+                       int i = 0;
+                       String name = args[i++];
+                       int port = Integer.parseInt(args[i++]);
+                       boolean ssl = Boolean.parseBoolean(args[i++]);
+                       String fhost = args[i++];
+                       int fport = Integer.parseInt(args[i++]);
+                       boolean fssl = Boolean.parseBoolean(args[i++]);
+
+                       int traceLevel = 1;
+                       if (args.length > 6) {
+                               traceLevel = Integer.parseInt(args[i++]);
+                       }
+                       int maxPrintSize = 0;
+                       if (args.length > 7) {
+                               maxPrintSize = Integer.parseInt(args[i++]);
+                       }
+
+                       ServerBridge bridge = new ServerBridge(name, port, ssl, fhost,
+                                       fport, fssl);
+                       bridge.setTraceHandler(new TraceHandler(true, true, traceLevel,
+                                       maxPrintSize));
+                       bridge.run();
+               } catch (Exception e) {
+                       tracer.error(e);
+               }
+       }
+}
index 9ccae1c498cd04611ccb4d6016da4255efdae68f..157b27ee9cc0df8c620a6163e5d0ae524d4b4e57 100644 (file)
@@ -283,64 +283,4 @@ public class ServerBridge extends Server {
                        getTraceHandler().trace("", 2);
                }
        }
-
-       /**
-        * Start a bridge between 2 servers.
-        * 
-        * @param args
-        *            an array containing:
-        *            <ul>
-        *            <li>The bridge name</li>
-        *            <li>The bridge port</li>
-        *            <li>TRUE for an SSL bridge, FALSE for plain text</li>
-        *            <li>The forward server host</li>
-        *            <li>The forward server port</li>
-        *            <li>TRUE for an SSL forward server, FALSE for plain text</li>
-        *            <li>(optional) a trace level</li>
-        *            <li>(optional) a truncate size for data</li>
-        *            </ul>
-        */
-       public static void main(String[] args) {
-               final TraceHandler tracer = new TraceHandler(true, false, 0);
-               try {
-                       if (args.length < 6) {
-                               tracer.error("Invalid syntax.\n"
-                                               + "Syntax: [name] [port] [ssl] [fhost] [fport] [fssl] ([trace level]) ([max])\n"
-                                               + "\tname: the bridge name\n"
-                                               + "\tport: the bridge port\n"
-                                               + "\tssl: TRUE for an SSL bridge, FALSE for plain text\n"
-                                               + "\tfhost: the forward server host\n"
-                                               + "\tfport: the forward server port\n"
-                                               + "\tfssl: TRUE for an SSL forward server, FALSE for plain text\n"
-                                               + "\ttrace level: the optional trace level (default is 1)\n"
-                                               + "\tmax: the maximum size after which to truncate data\n");
-                               return;
-                       }
-
-                       int i = 0;
-                       String name = args[i++];
-                       int port = Integer.parseInt(args[i++]);
-                       boolean ssl = Boolean.parseBoolean(args[i++]);
-                       String fhost = args[i++];
-                       int fport = Integer.parseInt(args[i++]);
-                       boolean fssl = Boolean.parseBoolean(args[i++]);
-
-                       int traceLevel = 1;
-                       if (args.length > 6) {
-                               traceLevel = Integer.parseInt(args[i++]);
-                       }
-                       int maxPrintSize = 0;
-                       if (args.length > 7) {
-                               maxPrintSize = Integer.parseInt(args[i++]);
-                       }
-
-                       ServerBridge bridge = new ServerBridge(name, port, ssl, fhost,
-                                       fport, fssl);
-                       bridge.setTraceHandler(new TraceHandler(true, true, traceLevel,
-                                       maxPrintSize));
-                       bridge.run();
-               } catch (Exception e) {
-                       tracer.error(e);
-               }
-       }
 }