1 package be
.nikiroo
.utils
.main
;
3 import be
.nikiroo
.utils
.TraceHandler
;
4 import be
.nikiroo
.utils
.serial
.server
.ServerBridge
;
7 * Serialiser bridge (starts a {@link ServerBridge} and can thus intercept
8 * communication between a client and a server).
14 * The optional options that can be passed to the program.
20 * The encryption key for the input data (optional, but can also be
21 * empty <b>which is different</b> (it will then use an empty encryption
26 * The encryption key for the output data (optional, but can also be
27 * empty <b>which is different</b> (it will then use an empty encryption
31 /** The trace level (1, 2, 3.. default is 1). */
34 * The maximum length after which to truncate data to display (the whole
35 * data will still be sent).
38 /** The help message. */
42 static private String
getSyntax() {
43 return "Syntax: (--options) (--) [NAME] [PORT] [FORWARD_HOST] [FORWARD_PORT]\n"//
44 + "\tNAME : the bridge name for display/debug purposes\n"//
45 + "\tPORT : the port to listen on\n"//
46 + "\tFORWARD_HOST : the host to connect to\n"//
47 + "\tFORWARD_PORT : the port to connect to\n"//
50 + "\t-- : no more options in the rest of the parameters\n" //
51 + "\t--help : this help message\n" //
52 + "\t--key : the INCOMING encryption key\n" //
53 + "\t--forward-key : the OUTGOING encryption key\n" //
54 + "\t--trace-level : the trace level (1, 2, 3... default is 1)\n" //
55 + "\t--max-display-size : the maximum size after which to \n"//
56 + "\t truncate the messages to display (the full message will still be sent)\n" //
61 * Start a bridge between 2 servers.
64 * the parameters, which can be seen by passing "--help" or just
65 * calling the program without parameters
67 public static void main(String
[] args
) {
68 final TraceHandler tracer
= new TraceHandler(true, false, 0);
70 if (args
.length
== 0) {
71 tracer
.error(getSyntax());
81 while (args
[i
].startsWith("--")) {
85 if (arg
.equals("--")) {
89 arg
= arg
.substring(2).toUpperCase().replace("-", "_");
91 Option opt
= Enum
.valueOf(Option
.class, arg
);
94 tracer
.trace(getSyntax());
103 case MAX_DISPLAY_SIZE
:
104 maxPrintSize
= Integer
.parseInt(args
[i
++]);
107 traceLevel
= Integer
.parseInt(args
[i
++]);
110 } catch (Exception e
) {
111 tracer
.error(getSyntax());
116 if ((args
.length
- i
) != 4) {
117 tracer
.error(getSyntax());
121 String name
= args
[i
++];
122 int port
= Integer
.parseInt(args
[i
++]);
123 String fhost
= args
[i
++];
124 int fport
= Integer
.parseInt(args
[i
++]);
126 ServerBridge bridge
= new ServerBridge(name
, port
, key
, fhost
,
128 bridge
.setTraceHandler(new TraceHandler(true, true, traceLevel
,
131 } catch (Exception e
) {