import java.io.IOException;
import java.lang.reflect.Array;
import java.net.Socket;
+import java.net.UnknownHostException;
import be.nikiroo.utils.StringUtils;
import be.nikiroo.utils.TraceHandler;
*
* @throws IOException
* in case of I/O error
+ * @throws UnknownHostException
+ * if the IP address of the host could not be determined
+ * @throws IllegalArgumentException
+ * if the port parameter is outside the specified range of valid
+ * port values, which is between 0 and 65535, inclusive
*/
public ServerBridge(int port, boolean ssl, String forwardToHost,
int forwardToPort, boolean forwardToSsl) throws IOException {
*
* @throws IOException
* in case of I/O error
+ * @throws UnknownHostException
+ * if the IP address of the host could not be determined
+ * @throws IllegalArgumentException
+ * if the port parameter is outside the specified range of valid
+ * port values, which is between 0 and 65535, inclusive
*/
public ServerBridge(String name, int port, boolean ssl,
String forwardToHost, int forwardToPort, boolean forwardToSsl)
onClientContact(clientVersion);
final ConnectActionServerString bridge = this;
- new ConnectActionClientString(forwardToHost, forwardToPort,
- forwardToSsl, clientVersion) {
- @Override
- public void action(final Version serverVersion)
- throws Exception {
- onServerContact(serverVersion);
+ try {
+ new ConnectActionClientString(forwardToHost, forwardToPort,
+ forwardToSsl, clientVersion) {
+ @Override
+ public void action(final Version serverVersion)
+ throws Exception {
+ onServerContact(serverVersion);
- for (String fromClient = bridge.rec(); fromClient != null; fromClient = bridge
- .rec()) {
- onRec(clientVersion, fromClient);
- String fromServer = send(fromClient);
- onSend(serverVersion, fromServer);
- bridge.send(fromServer);
- }
+ for (String fromClient = bridge.rec(); fromClient != null; fromClient = bridge
+ .rec()) {
+ onRec(clientVersion, fromClient);
+ String fromServer = send(fromClient);
+ onSend(serverVersion, fromServer);
+ bridge.send(fromServer);
+ }
- getTraceHandler().trace("=== DONE", 1);
- getTraceHandler().trace("", 1);
- }
+ getTraceHandler().trace("=== DONE", 1);
+ getTraceHandler().trace("", 1);
+ }
- @Override
- protected void onError(Exception e) {
- ServerBridge.this.onError(e);
- }
- }.connect();
+ @Override
+ protected void onError(Exception e) {
+ ServerBridge.this.onError(e);
+ }
+ }.connect();
+ } catch (Exception e) {
+ ServerBridge.this.onError(e);
+ }
}
};
}
trace("<<< SERVER (" + serverVersion + ")", data);
}
+ @Override
+ public void run() {
+ getTraceHandler().trace(
+ getName() + ": will forward to " + forwardToHost + ":"
+ + forwardToPort + " ("
+ + (forwardToSsl ? "SSL" : "plain text") + ")");
+ super.run();
+ }
+
/**
* Trace the data with the given prefix.
*
if (args.length > 6) {
traceLevel = Integer.parseInt(args[i++]);
}
- int maxPrintSize = 1;
+ int maxPrintSize = 0;
if (args.length > 7) {
maxPrintSize = Integer.parseInt(args[i++]);
}