List of usage examples for java.net ProxySelector setDefault
public static void setDefault(ProxySelector ps)
From source file:com.google.api.ads.adwords.awreporting.server.AwReportingServer.java
/** * Main method.//from w w w. j a v a 2 s . c o m * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = DAFAULT_PROPERTIES_LOCATION; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); // Print full help and quit if (cmdLine.hasOption("help")) { printHelpMessage(options); System.exit(0); } setLogLevel(cmdLine); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } System.out.println("Using properties from: " + propertiesPath); RestServer restServer = new RestServer(); restServer.initApplicationContextAndProperties(propertiesPath); String mccAccountId = RestServer.getProperties().getProperty("mccAccountId").replaceAll("-", ""); System.out.println("Updating DB indexes... (may take long the first time)"); RestServer.getStorageHelper().createReportIndexes(); System.out.println("DB indexes Updated."); if (cmdLine.hasOption("startServer")) { // Start the Rest Server System.out.println("Starting Rest Server at Port: " + DEFAULT_SERVER_PORT); restServer.startServer(); } else { if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { if (cmdLine.hasOption("processKratus")) { // Process Kratus, this process runs for the whole MCC in the properties file // within the given dates and creates a daily Kratu per account. System.out.println("Starting Process Kratus..."); // Process only the accounts at accountIdsFile Set<Long> accountIdsSet = Sets.newHashSet(); if (cmdLine.hasOption("accountIdsFile")) { String accountsFileName = cmdLine.getOptionValue("accountIdsFile"); System.out.println("Using accounts file: " + accountsFileName); addAccountsFromFile(accountIdsSet, accountsFileName); } KratuProcessor kratuProcessor = RestServer.getApplicationContext() .getBean(KratuProcessor.class); kratuProcessor.processKratus(Long.valueOf(mccAccountId), accountIdsSet, cmdLine.getOptionValue("startDate"), cmdLine.getOptionValue("endDate")); System.exit(0); } else { // Download Reports, // this porcess downloads 7 report types for each account under the MCC System.out.println("Starting Download Reports porcess..."); AwReporting.main(args); System.exit(0); } } else { errors = true; System.out.println("Configuration incomplete. Missing options for command line."); } } if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); System.out.println("Using properties from: " + propertiesPath); } else { errors = true; System.out.println("Configuration incomplete. Missing options for command line."); } } catch (ParseException e) { errors = true; System.out.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; System.out.println("Unexpected error: " + e.getMessage()); } if (errors) { printHelpMessage(options); System.exit(1); } }
From source file:com.google.api.ads.adwords.awalerting.AwAlerting.java
/** * Main method.// ww w . ja v a 2s. c om * * @param args the command line arguments */ public static void main(String args[]) { // Set up proxy. JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); // Print full help and quit if (cmdLine.hasOption("help")) { printHelpMessage(options); printSamplePropertiesFile(); System.exit(0); } if (!cmdLine.hasOption("file")) { LOGGER.error("Missing required option: 'file'"); System.exit(1); } processAlerts(cmdLine); } catch (ParseException e) { LOGGER.error("Error parsing the values for the command line options.", e); System.exit(1); } catch (AlertConfigLoadException e) { LOGGER.error("Error laoding alerts configuration.", e); System.exit(1); } catch (AlertProcessingException e) { LOGGER.error("Error processing alerts.", e); System.exit(1); } }
From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java
/** * Main method.//from w w w. j a v a 2 s . c om * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = CLASSPATH_AW_REPORT_MODEL_PROPERTIES_LOCATION; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } System.out.println("Using properties from: " + propertiesPath); if (cmdLine.hasOption("startServer")) { // Start the Rest Server System.out.println("Starting Rest Server..."); initApplicationContextAndProperties(propertiesPath); updateAccounts(); RestServer.createRestServer(appCtx, propertiesPath); } else { if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { if (cmdLine.hasOption("processKratus")) { // Process Kratus, this process runs for the whole MCC // within the given dates and creates a daily Kratu per account. System.out.println("Starting Process Kratus..."); initApplicationContextAndProperties(propertiesPath); updateAccounts(); KratuProcessor kratuProcessor = appCtx.getBean(KratuProcessor.class); kratuProcessor.processKratus(cmdLine.getOptionValue("startDate"), cmdLine.getOptionValue("endDate")); System.exit(0); } else { // Download Reports, // this porcess downloads 7 report types for each account under the MCC System.out.println("Starting Download Reports porcess..."); AwReporting.main(args); System.exit(0); } } else { errors = true; System.out.println("Configuration incomplete. Missing options for command line."); } } } catch (IOException e) { errors = true; System.out.println("Properties file (" + propertiesPath + ") not found: " + e.getMessage()); } catch (ParseException e) { errors = true; System.out.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; System.out.println("Unexpected error: " + e.getMessage()); } if (errors) { printHelpMessage(options); System.exit(1); } }
From source file:com.google.api.ads.adwords.awreporting.AwReporting.java
/** * Main method.// ww w .j a v a 2 s .c o m * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = null; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); // Print full help and quit if (cmdLine.hasOption("help")) { printHelpMessage(options); printSamplePropertiesFile(); System.exit(0); } setLogLevel(cmdLine); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } else { LOGGER.error("Missing required option: 'file'"); System.exit(0); } LOGGER.info("Using properties file: " + propertiesPath); Set<Long> accountIdsSet = Sets.newHashSet(); if (cmdLine.hasOption("accountIdsFile")) { String accountsFileName = cmdLine.getOptionValue("accountIdsFile"); addAccountsFromFile(accountIdsSet, accountsFileName); } boolean forceOnFileProcessor = false; if (cmdLine.hasOption("onFileReport")) { if (!cmdLine.hasOption("csvReportFile") || !cmdLine.hasOption("startDate") || !cmdLine.hasOption("endDate")) { LOGGER.error("Missing one or more of the required options: " + "'csvReportFile', 'startDate' or 'endDate'"); System.exit(0); } forceOnFileProcessor = true; } Properties properties = initApplicationContextAndProperties(propertiesPath, forceOnFileProcessor); LOGGER.debug("Creating ReportProcessor bean..."); ReportProcessor processor = createReportProcessor(); LOGGER.debug("... success."); String mccAccountId = properties.getProperty("mccAccountId").replaceAll("-", ""); if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { // Generate Reports String dateStart = cmdLine.getOptionValue("startDate"); String dateEnd = cmdLine.getOptionValue("endDate"); if (cmdLine.hasOption("onFileReport")) { String reportTypeName = cmdLine.getOptionValue("onFileReport"); String csvReportFile = cmdLine.getOptionValue("csvReportFile"); File csvFile = new File(csvReportFile); if (!csvFile.exists()) { LOGGER.error("Could not find CSV file: " + csvReportFile); System.exit(0); } ReportProcessorOnFile onFileProcessor = (ReportProcessorOnFile) processor; List<File> localFiles = new ArrayList<File>(); localFiles.add(csvFile); LOGGER.info( "Starting report processing for dateStart: " + dateStart + " and dateEnd: " + dateEnd); onFileProcessor.processInputFiles(mccAccountId, reportTypeName, localFiles, dateStart, dateEnd, ReportDefinitionDateRangeType.CUSTOM_DATE); } else { LOGGER.info( "Starting report download for dateStart: " + dateStart + " and dateEnd: " + dateEnd); processor.generateReportsForMCC(mccAccountId, ReportDefinitionDateRangeType.CUSTOM_DATE, dateStart, dateEnd, accountIdsSet, properties, null, null); } } else if (cmdLine.hasOption("dateRange")) { ReportDefinitionDateRangeType dateRangeType = ReportDefinitionDateRangeType .fromValue(cmdLine.getOptionValue("dateRange")); LOGGER.info("Starting report download for dateRange: " + dateRangeType.name()); processor.generateReportsForMCC(mccAccountId, dateRangeType, null, null, accountIdsSet, properties, null, null); } else { errors = true; LOGGER.error("Configuration incomplete. Missing options for command line."); } } catch (IOException e) { errors = true; if (e.getMessage().contains("Insufficient Permission")) { LOGGER.error("Insufficient Permission error accessing the API" + e.getMessage()); } else { LOGGER.error("File not found: " + e.getMessage()); } } catch (ParseException e) { errors = true; System.err.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; LOGGER.error("Unexpected error accessing the API: " + e.getMessage()); e.printStackTrace(); } if (errors) { System.exit(1); } else { System.exit(0); } }
From source file:com.google.api.ads.adwords.jaxws.extensions.AwReporting.java
/** * Main method.//from w ww. j av a 2 s . c om * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = null; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); // Print full help and quit if (cmdLine.hasOption("help")) { printHelpMessage(options); printSamplePropertiesFile(); System.exit(0); } setLogLevel(cmdLine); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } else { LOGGER.error("Missing required option: 'file'"); System.exit(0); } LOGGER.info("Using properties file: " + propertiesPath); Set<Long> accountIdsSet = Sets.newHashSet(); if (cmdLine.hasOption("accountIdsFile")) { String accountsFileName = cmdLine.getOptionValue("accountIdsFile"); addAccountsFromFile(accountIdsSet, accountsFileName); } Properties properties = initApplicationContextAndProperties(propertiesPath); ReportModeService.setReportMode(properties.getProperty("reportMode")); //TODO Any other approach? LOGGER.debug("Creating ReportProcessor bean..."); ReportProcessor processor = createReportProcessor(); LOGGER.debug("... success."); if (cmdLine.hasOption("generatePdf")) { LOGGER.debug("GeneratePDF option detected."); // Get HTML template and output directoy String[] pdfFiles = cmdLine.getOptionValues("generatePdf"); File htmlTemplateFile = new File(pdfFiles[0]); File outputDirectory = new File(pdfFiles[1]); LOGGER.debug("Html template file to be used: " + htmlTemplateFile); LOGGER.debug("Output directory for PDF: " + outputDirectory); // Generate PDFs generatePdf(processor, cmdLine.getOptionValue("startDate"), cmdLine.getOptionValue("endDate"), properties, htmlTemplateFile, outputDirectory); } else if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { // Generate Reports String dateStart = cmdLine.getOptionValue("startDate"); String dateEnd = cmdLine.getOptionValue("endDate"); LOGGER.info("Starting report download for dateStart: " + dateStart + " and dateEnd: " + dateEnd); processor.generateReportsForMCC(ReportDefinitionDateRangeType.CUSTOM_DATE, dateStart, dateEnd, accountIdsSet, properties); } else if (cmdLine.hasOption("dateRange")) { ReportDefinitionDateRangeType dateRangeType = ReportDefinitionDateRangeType .fromValue(cmdLine.getOptionValue("dateRange")); LOGGER.info("Starting report download for dateRange: " + dateRangeType.name()); processor.generateReportsForMCC(dateRangeType, null, null, accountIdsSet, properties); } else { errors = true; LOGGER.error("Configuration incomplete. Missing options for command line."); } } catch (IOException e) { errors = true; LOGGER.error("File not found: " + e.getMessage()); } catch (ParseException e) { errors = true; System.err.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; LOGGER.error("Unexpected error accessing the API: " + e.getMessage()); e.printStackTrace(); } if (errors) { System.exit(1); } else { System.exit(0); } }
From source file:Utils.java
private static void installProxySelector(final String hostName, final int portNum) { ProxySelector.setDefault(new ProxySelector() { public List select(URI uri) { List list = new ArrayList(); list.add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(hostName, portNum))); return list; }//from ww w. j a v a2 s. c om public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { } }); }
From source file:jfs.sync.util.WindowsProxySelector.java
private WindowsProxySelector() { root = ProxySelector.getDefault(); ProxySelector.setDefault(null); if (LOG.isDebugEnabled()) { LOG.debug("select() root " + root); } // if// ww w . j a v a2 s . c om }
From source file:com.zimbra.common.net.SocketFactories.java
private synchronized static void register(X509TrustManager tm) { if (registered) return;/*w ww.j av a2 s .co m*/ // Set default TrustManager TrustManagers.setDefaultTrustManager(tm); // Register Apache Commons HTTP/HTTPS protocol socket factories ProtocolSocketFactory psf = defaultProtocolSocketFactory(); Protocol.registerProtocol(HTTP, new Protocol(HTTP, psf, 80)); ProtocolSocketFactory spsf = defaultSecureProtocolSocketFactory(); Protocol.registerProtocol(HTTPS, new Protocol(HTTPS, spsf, 443)); // HttpURLConnection already uses system ProxySelector by default // Set HttpsURLConnection SSL socket factory and optional hostname verifier HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory(false)); if (tm instanceof CustomTrustManager) { HttpsURLConnection.setDefaultHostnameVerifier(new CustomHostnameVerifier()); } // Set the system-wide default ProxySelector ProxySelector.setDefault(ProxySelectors.defaultProxySelector()); registered = true; }
From source file:com.ericsson.eiffel.remrem.semantics.clone.PrepareLocalEiffelSchemas.java
/** * This method is used to get set the proxy to clone the repositories under this proxy * /*from ww w. j a v a 2 s . c o m*/ * @param proxy proxy instance created by using proxy details provided by user */ private void setProxy(final Proxy proxy) { ProxySelector.setDefault(new ProxySelector() { @Override public List<Proxy> select(URI uri) { return Arrays.asList(proxy); } @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { if (uri == null || sa == null || ioe == null) { throw new IllegalArgumentException("Arguments can not be null."); } } }); }