 package ibgroup.web.core.clientportal.gw;
 
 import ibgroup.utils.OptionUtils;
 import io.vertx.core.Verticle;
 import io.vertx.core.Vertx;
 import io.vertx.core.logging.Logger;
 import io.vertx.core.logging.LoggerFactory;
 import java.io.InputStream;
 import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.UnrecognizedOptionException;
 import org.yaml.snakeyaml.Yaml;
 
 
 
 public class GatewayStart
 {
   private static Config config = new Config();
   private static final int EXIT_FAILED = 1;
   private static final Logger logger = LoggerFactory.getLogger(GatewayStart.class);
   private static final Options options = new Options();
   
   public static void main(String[] args) {
     initCmdLineOptions();
     
     BasicParser basicParser = new BasicParser();
     CommandLine cmd = null;
     try {
       cmd = basicParser.parse(options, args);
     } catch (UnrecognizedOptionException e) {
       logger.error("unrecognized option: {}", new Object[] { e.getMessage() });
       printHelp();
     } catch (Exception e) {
       printHelp();
     } 
     
     if (cmd == null || cmd.hasOption("h")) {
       printHelp();
       
       return;
     } 
     String file = cmd.getOptionValue("conf", "conf.yaml");
     if (!file.isEmpty()) {
       try (InputStream in = ClassLoader.getSystemResourceAsStream(file)) {
         Yaml yaml = new Yaml();
         config = (Config)yaml.loadAs(in, Config.class);
       } catch (Exception e) {
         System.err.println(e.getMessage());
         failed("loading configuration file error:" + e.getMessage(), new Object[0]);
       } 
     }
     
     String host = cmd.getOptionValue("host", "");
     if (!host.isEmpty()) {
       config.setProxyRemoteHost(host);
     }
     
     if (cmd.hasOption("port")) {
       try {
         int port = ((Number)cmd.getParsedOptionValue("port")).intValue();
         config.setListenPort(port);
       } catch (ParseException e) {
         System.err.println("failed to parse port value");
       } 
     }
     
     if (cmd.hasOption("nossl")) {
       config.setListenSsl(false);
     }
     Vertx vertx = Vertx.vertx(config.getVertxOptions());
     OptionUtils.setSharedGlobalConfig(vertx, config);
     logger.info("config {} {}", new Object[] { file, (new Yaml()).dump(config) });
     vertx.deployVerticle((Verticle)new GatewayVerticle());
   }
   
   private static void failed(String err, Object... args) {
     logger.error(err, args);
     System.exit(1);
   }
 
   
   private static void initCmdLineOptions() {
     options.addOption("h", "help", false, "print this message");
     OptionBuilder.withLongOpt("nossl");
     OptionBuilder.hasArg(false);
     OptionBuilder.withDescription("Disable SSL (not recommended)"); options.addOption(OptionBuilder.create());
     options.addOption("c", "conf", true, "Specify a YAML file to load configuration options from");
     OptionBuilder.withLongOpt("port");
     OptionBuilder.hasArg();
     OptionBuilder.withType(Number.class);
     OptionBuilder.withDescription("Listen on port"); options.addOption(OptionBuilder.create());
     options.addOption(null, "remoteProxyHost", true, "remote host, e.g www.interactivebrokers.com");
   }
   
   private static void printHelp() {
     HelpFormatter help = new HelpFormatter();
     help.printHelp("java -jar gw.jar " + GatewayStart.class.getSimpleName(), options);
     System.exit(1);
   }
 }


/* Location:              C:\Users\iuzeri\AppData\Local\Temp\ibrk_cpwa_gateway\dist\ibgroup.web.core.iblink.router.clientportal.gw.jar!\ibgroup\web\core\clientportal\gw\GatewayStart.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */