Skip to content

Commit

Permalink
Added command line parameters support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Damico committed May 8, 2014
1 parent ccb473e commit 89fb07c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@

public class StartProxy {

public static boolean enableLog = false;
public static boolean enableDebugLog = false;
public static void main(String[] args) {

/*
* enableDebugLog
* listenPort
*/

enableLog = true;
int port = Constants.LISTEN_PORT;

new ProxyServerInitiator(Constants.LISTEN_PORT, Constants.PROXY_HOST, Constants.PROXY_PORT ).start();
String noParamsMsg = "Unable to parse command-line parameters, using default configuration.";

if(args.length == 2){
try {
String prePort = args[0].trim();
port = Integer.parseInt(prePort);
String preDebug = args[1].trim();
enableDebugLog = Boolean.parseBoolean(preDebug);
} catch (Exception e) {
System.out.println(noParamsMsg);
}
}else System.out.println(noParamsMsg);

new ProxyServerInitiator(port).start();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ public static DebugLog getInstance(){


public void println( String txt ) {
if( StartProxy.enableLog ) print( txt + Constants.EOL );
if( StartProxy.enableDebugLog ) print( txt + Constants.EOL );
}


public void print( String txt ) {
if( !StartProxy.enableLog ) return;
if( !StartProxy.enableDebugLog ) return;
if( txt == null ) return;
System.out.print( txt );
}

/////////////////////////////////////////////////

public void error( String txt ) {
if( StartProxy.enableLog ) println( "Error : " + txt );
if( StartProxy.enableDebugLog ) println( "Error : " + txt );
}

/////////////////////////////////////////////////

public void error( Exception e ) {
if( !StartProxy.enableLog ) return;
if( !StartProxy.enableDebugLog ) return;
println( "ERROR : " + e.toString() );
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ProxyServerInitiator implements Runnable

public int getPort() { return m_nPort; }

public ProxyServerInitiator(int listenPort, String proxyHost, int proxyPort) {
public ProxyServerInitiator(int listenPort) {

m_lock = this;
m_nPort = listenPort;
Expand Down

0 comments on commit 89fb07c

Please sign in to comment.