List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:au.csiro.casda.sodalint.SodaLinter.java
/** * Command line handler for SodaLinter/*from ww w . j a v a2s . co m*/ * @param args The command line arguments * @throws Exception If an otherwise uncaught error occurs. */ public static void main(String[] args) throws Exception { SodaLinter linter = new SodaLinter(); String[] stages = null; final int defaultMaxRepeat = 9; final int defaultMaxLineLen = 1024; int maxRepeat = defaultMaxRepeat; int maxLineLen = defaultMaxLineLen; String sodaUrl = null; boolean error = false; for (String arg : args) { if (arg.startsWith("stages=")) { stages = arg.substring("stages=".length()).split(" "); } else if (arg.startsWith("maxrepeat=")) { String value = arg.substring("maxrepeat=".length()); if (StringUtils.isNumeric(value)) { maxRepeat = Integer.parseInt(value); } else { error = true; } } else if (arg.startsWith("truncate=")) { String value = arg.substring("truncate=".length()); if (StringUtils.isNumeric(value)) { maxLineLen = Integer.parseInt(value); } else { error = true; } } else { sodaUrl = arg.startsWith("sodaurl=") ? arg.substring("sodaurl=".length()) : arg; } } if (sodaUrl == null || error) { System.out.println( "Usage: java -jar sodalint-full.jar [stages=\"CPV|CAP|AVV|EXM|SVD|ERR|SYN|ASY[ ...]\"] " + "[maxrepeat=<int-value>] [truncate=<int-value>] [sodaurl=]<url-value>"); System.exit(1); } TextOutputReporter reporter = new TextOutputReporter(System.out, ReportType.values(), maxRepeat, false, maxLineLen); // URL serviceUrl = new URL("https://casda-dev-app.pawsey.org.au/casda_data_access/data/"); URL serviceUrl = new URL(sodaUrl); String[] defaultStages = new String[] { Stage.CAP_XML.getCode(), Stage.AVAIL_XML.getCode(), Stage.CAPABILITIES.getCode(), Stage.SYNC.getCode(), Stage.ASYNC.getCode(), Stage.SERVICE_DESC.getCode() }; Set<String> codes = new HashSet<>(Arrays.asList(stages != null ? stages : defaultStages)); Executable executable = linter.createExecutable(reporter, serviceUrl, codes, null); executable.execute(); }
From source file:org.dlut.mycloudserver.service.performancemonitor.PerformanceListener.java
public static void main(String[] args) { long t1 = System.currentTimeMillis(); String url = "http://127.0.0.1:8001"; URLConnection conn;// w ww .j av a 2 s . c o m try { conn = new URL(url).openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); InputStream is = conn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String res = br.readLine(); br.close(); is.close(); JSONObject jsonRes = JSON.parseObject(res); double loadAverage = jsonRes.getDoubleValue("loadAverage"); System.out.println(loadAverage); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } long t2 = System.currentTimeMillis(); System.out.println((t2 - t1) + "ms"); }
From source file:com.dict.crawl.NewsNationalGeographicCrawler.java
public static void main(String[] args) throws Exception { /*string,crawlPath??crawlPath, ????crawlPath/*from w w w. j a v a 2 s .c o m*/ */ NewsNationalGeographicCrawler crawler = new NewsNationalGeographicCrawler("data/NewsNationalGeographic"); crawler.setThreads(2); crawler.addSeed("http://ngm.nationalgeographic.com/"); if (BaseCrawler.isNormalTime()) { crawler.addSeed("http://ngm.nationalgeographic.com/archives"); crawler.addSeed("http://ngm.nationalgeographic.com/featurehub"); // //} String jsonUrl = "http://news.nationalgeographic.com/bin/services/news/public/query/content.json?pageSize=20&page=0&contentTypes=news/components/pagetypes/article,news/components/pagetypes/simple-article,news/components/pagetypes/photo-gallery"; URL urls = new URL(jsonUrl); HttpURLConnection urlConnection = (HttpURLConnection) urls.openConnection(); InputStream is = urlConnection.getInputStream(); Reader rd = new InputStreamReader(is, "utf-8"); JsonArray json = new JsonParser().parse(rd).getAsJsonArray(); for (JsonElement jOb : json) { String url = jOb.getAsJsonObject().get("page").getAsJsonObject().get("url").getAsString(); if (url != null && !url.equals("")) crawler.addSeed(url); } } // crawler.addSeed("http://news.nationalgeographic.com/2016/01/160118-mummies-world-bog-egypt-science/"); // List<Map<String, Object>> urls = crawler.jdbcTemplate.queryForList("SELECT id,title,url FROM parser_page where host like '%news.national%' ORDER by id desc;"); // for(int i = 0; i < urls.size(); i++) { // String url = (String) urls.get(i).get("url"); // String title = (String) urls.get(i).get("title"); //// int id = (int) urls.get(i).get("id"); // crawler.addSeed(url); // } // Config Config.WAIT_THREAD_END_TIME = 1000 * 60 * 5;//???kill // Config.TIMEOUT_CONNECT = 1000*10; // Config.TIMEOUT_READ = 1000*30; Config.requestMaxInterval = 1000 * 60 * 20;//??-?>hung //requester??http??requester?http/socks? HttpRequesterImpl requester = (HttpRequesterImpl) crawler.getHttpRequester(); AntiAntiSpiderHelper.defaultUserAgent(requester); // requester.setUserAgent("Mozilla/5.0 (X11; Linux i686; rv:33.0) Gecko/20100101 Firefox/33.0"); // requester.setCookie("CNZZDATA1950488=cnzz_eid%3D739324831-1432460954-null%26ntime%3D1432460954; wdcid=44349d3f2aa96e51; vjuids=-53d395da8.14eca7eed44.0.f17be67e; CNZZDATA3473518=cnzz_eid%3D1882396923-1437965756-%26ntime%3D1440635510; pt_37a49e8b=uid=FuI4KYEfVz5xq7L4nzPd1w&nid=1&vid=r4AhSBmxisCiyeolr3V2Ow&vn=1&pvn=1&sact=1440639037916&to_flag=0&pl=t4NrgYqSK5M357L2nGEQCw*pt*1440639015734; _ga=GA1.3.1121158748.1437970841; __auc=c00a6ac114d85945f01d9c30128; CNZZDATA1975683=cnzz_eid%3D250014133-1432460541-null%26ntime%3D1440733997; CNZZDATA1254041250=2000695407-1442220871-%7C1442306691; pt_7f0a67e8=uid=6lmgYeZ3/jSObRMeK-t27A&nid=0&vid=lEKvEtZyZdd0UC264UyZnQ&vn=2&pvn=1&sact=1442306703728&to_flag=0&pl=7GB3sYS/PJDo1mY0qeu2cA*pt*1442306703728; 7NSx_98ef_saltkey=P05gN8zn; 7NSx_98ef_lastvisit=1444281282; IframeBodyHeight=256; NTVq_98ef_saltkey=j5PydYru; NTVq_98ef_lastvisit=1444282735; NTVq_98ef_atarget=1; NTVq_98ef_lastact=1444286377%09api.php%09js; 7NSx_98ef_sid=hZyDwc; __utmt=1; __utma=155578217.1121158748.1437970841.1443159326.1444285109.23; __utmb=155578217.57.10.1444285109; __utmc=155578217; __utmz=155578217.1439345650.3.2.utmcsr=travel.chinadaily.com.cn|utmccn=(referral)|utmcmd=referral|utmcct=/; CNZZDATA3089622=cnzz_eid%3D1722311508-1437912344-%26ntime%3D1444286009; wdlast=1444287704; vjlast=1437916393.1444285111.11; 7NSx_98ef_lastact=1444287477%09api.php%09chinadaily; pt_s_3bfec6ad=vt=1444287704638&cad=; pt_3bfec6ad=uid=bo87MAT/HC3hy12HDkBg1A&nid=0&vid=erwHQyFKxvwHXYc4-r6n-w&vn=28&pvn=2&sact=1444287708079&to_flag=0&pl=kkgvLoEHXsCD2gs4VJaWQg*pt*1444287704638; pt_t_3bfec6ad=?id=3bfec6ad.bo87MAT/HC3hy12HDkBg1A.erwHQyFKxvwHXYc4-r6n-w.kkgvLoEHXsCD2gs4VJaWQg.nZJ9Aj/bgfNDIKBXI5TwRQ&stat=167.132.1050.1076.1body%20div%3Aeq%288%29%20ul%3Aeq%280%29%20a%3Aeq%282%29.0.0.1595.3441.146.118&ptif=4"); //?? Mozilla/5.0 (X11; Linux i686; rv:34.0) Gecko/20100101 Firefox/34.0 //c requester.setProxy(" /* //?? RandomProxyGenerator proxyGenerator=new RandomProxyGenerator(); proxyGenerator.addProxy("127.0.0.1",8080,Proxy.Type.SOCKS); requester.setProxyGenerator(proxyGenerator); */ /*??*/ // crawler.setResumable(true); crawler.setResumable(false); crawler.start(2); }
From source file:com.mockey.runner.JettyRunner.java
public static void main(String[] args) throws Exception { if (args == null) args = new String[0]; // Initialize the argument parser SimpleJSAP jsap = new SimpleJSAP("java -jar Mockey.jar", "Starts a Jetty server running Mockey"); jsap.registerParameter(new FlaggedOption(ARG_PORT, JSAP.INTEGER_PARSER, "8080", JSAP.NOT_REQUIRED, 'p', ARG_PORT, "port to run Jetty on")); jsap.registerParameter(new FlaggedOption(BSC.FILE, JSAP.STRING_PARSER, MockeyXmlFileManager.MOCK_SERVICE_DEFINITION, JSAP.NOT_REQUIRED, 'f', BSC.FILE, "Relative path to a mockey-definitions file to initialize Mockey, relative to where you're starting Mockey")); jsap.registerParameter(new FlaggedOption(BSC.URL, JSAP.STRING_PARSER, "", JSAP.NOT_REQUIRED, 'u', BSC.URL, "URL to a mockey-definitions file to initialize Mockey")); jsap.registerParameter(new FlaggedOption(BSC.TRANSIENT, JSAP.BOOLEAN_PARSER, "true", JSAP.NOT_REQUIRED, 't', BSC.TRANSIENT, "Read only mode if set to true, no updates are made to the file system.")); jsap.registerParameter(new FlaggedOption(BSC.FILTERTAG, JSAP.STRING_PARSER, "", JSAP.NOT_REQUIRED, 'F', BSC.FILTERTAG,//w w w .ja va2 s. c o m "Filter tag for services and scenarios, useful for 'only use information with this tag'. ")); jsap.registerParameter( new Switch(ARG_QUIET, 'q', "quiet", "Runs in quiet mode and does not loads the browser")); jsap.registerParameter(new FlaggedOption(BSC.HEADLESS, JSAP.BOOLEAN_PARSER, "false", JSAP.NOT_REQUIRED, 'H', BSC.HEADLESS, "Headless flag. Default is 'false'. Set to 'true' if you do not want Mockey to spawn a browser thread upon startup.")); // parse the command line options JSAPResult config = jsap.parse(args); // Bail out if they asked for the --help if (jsap.messagePrinted()) { System.exit(1); } // Construct the new arguments for jetty-runner int port = config.getInt(ARG_PORT); boolean transientState = true; // We can add more things to the quite mode. For now we are just not launching browser boolean isQuiteMode = false; try { transientState = config.getBoolean(BSC.TRANSIENT); isQuiteMode = config.getBoolean(ARG_QUIET); } catch (Exception e) { // } // Initialize Log4J file roller appender. StartUpServlet.getDebugFile(); InputStream log4jInputStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("WEB-INF/log4j.properties"); Properties log4JProperties = new Properties(); log4JProperties.load(log4jInputStream); PropertyConfigurator.configure(log4JProperties); Server server = new Server(port); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setConfigurations(new Configuration[] { new PreCompiledJspConfiguration() }); ClassPathResourceHandler resourceHandler = new ClassPathResourceHandler(); resourceHandler.setContextPath("/"); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.addHandler(resourceHandler); contexts.addHandler(webapp); server.setHandler(contexts); server.start(); // Construct the arguments for Mockey String file = String.valueOf(config.getString(BSC.FILE)); String url = String.valueOf(config.getString(BSC.URL)); String filterTag = config.getString(BSC.FILTERTAG); String fTagParam = ""; boolean headless = config.getBoolean(BSC.HEADLESS); if (filterTag != null) { fTagParam = "&" + BSC.FILTERTAG + "=" + URLEncoder.encode(filterTag, "UTF-8"); } // Startup displays a big message and URL redirects after x seconds. // Snazzy. String initUrl = HOMEURL; // BUT...if a file is defined, (which it *should*), // then let's initialize with it instead. if (url != null && url.trim().length() > 0) { URLEncoder.encode(initUrl, "UTF-8"); initUrl = HOMEURL + "?" + BSC.ACTION + "=" + BSC.INIT + "&" + BSC.TRANSIENT + "=" + transientState + "&" + BSC.URL + "=" + URLEncoder.encode(url, "UTF-8") + fTagParam; } else if (file != null && file.trim().length() > 0) { URLEncoder.encode(initUrl, "UTF-8"); initUrl = HOMEURL + "?" + BSC.ACTION + "=" + BSC.INIT + "&" + BSC.TRANSIENT + "=" + transientState + "&" + BSC.FILE + "=" + URLEncoder.encode(file, "UTF-8") + fTagParam; } else { initUrl = HOMEURL + "?" + BSC.ACTION + "=" + BSC.INIT + "&" + BSC.TRANSIENT + "=" + transientState + "&" + BSC.FILE + "=" + URLEncoder.encode(MockeyXmlFileManager.MOCK_SERVICE_DEFINITION, "UTF-8") + fTagParam; } if (!(headless || isQuiteMode)) { new Thread(new BrowserThread("http://127.0.0.1", String.valueOf(port), initUrl, 0)).start(); server.join(); } else { initializeMockey(new URL("http://127.0.0.1" + ":" + String.valueOf(port) + initUrl)); } }
From source file:lu.tudor.santec.dicom.gui.header.Dcm2Xml.java
public static void main(String[] args) { CommandLine cl = parse(args);/*from ww w. j a v a2 s.c o m*/ Dcm2Xml dcm2xml = new Dcm2Xml(); File ifile = new File((String) cl.getArgList().get(0)); File ofile = null; if (cl.hasOption("o")) { ofile = new File(cl.getOptionValue("o")); dcm2xml.setBaseDir(ofile.getAbsoluteFile().getParentFile()); } if (cl.hasOption("d")) { dcm2xml.setBaseDir(new File(cl.getOptionValue("d"))); } boolean x = cl.hasOption("X"); if (cl.hasOption("x")) { String[] tagStr = cl.getOptionValues("x"); int[] excludes = new int[x ? tagStr.length + 1 : tagStr.length]; for (int i = 0; i < tagStr.length; i++) { try { excludes[i] = (int) Long.parseLong(tagStr[i], 16); } catch (NumberFormatException e) { excludes[i] = Tag.forName(tagStr[i]); } } if (x) { excludes[tagStr.length] = Tag.PixelData; } dcm2xml.setExclude(excludes); } else if (x) { dcm2xml.setExclude(new int[] { Tag.PixelData }); } if (cl.hasOption("T")) { final String xslurl = cl.getOptionValue("T"); try { dcm2xml.setXslt(new URL(xslurl)); } catch (MalformedURLException e) { System.err.println("dcm2xml: invalid xsl URL: " + xslurl); System.exit(1); } dcm2xml.setXsltInc(cl.hasOption("I")); dcm2xml.setXsltParams(cl.getOptionValues("P")); } dcm2xml.setComments(cl.hasOption("C")); dcm2xml.setIndent(!cl.hasOption("c")); long t1 = System.currentTimeMillis(); try { dcm2xml.convert(ifile, ofile); } catch (TransformerConfigurationException e) { System.err.println("dcm2xml: Configuration Error: " + e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println("dcm2xml: Failed to convert " + ifile + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } long t2 = System.currentTimeMillis(); if (ofile != null) System.out.println("Finished conversion of " + ifile + "to " + ofile + " in " + (t2 - t1) + "ms"); }
From source file:com.emc.ecs.smart.SmartUploader.java
/** * Use commons-cli to parse command line arguments and start the upload. *///w ww.j av a 2 s . c om public static void main(String[] args) { Options opts = new Options(); // Optional params opts.addOption(Option.builder().longOpt(THREADS_OPT).hasArg().argName("thread-count") .desc("Sets the number of threads to upload concurrently. Default is " + DEFAULT_THREADS).build()); opts.addOption(Option.builder().longOpt(SIMPLE_OPT) .desc("For comparison purposes, do a simple single-stream upload instead of a concurrent upload.") .build()); opts.addOption(Option.builder().longOpt(SEGMENT_SIZE_OPT).hasArg().argName("bytes") .desc("Size of each upload segment in bytes. Defaults to 2MB for uploads less than 128MB and " + "128MB for objects greater than or equal to 128MB.") .build()); opts.addOption(Option.builder().longOpt(FILE_OPT).hasArg().argName("path-to-file").required() .desc("(Required) The path to the file to upload.").build()); opts.addOption(Option.builder().longOpt(URL_OPT).hasArg().argName("presigned-upload-url").required() .desc("URL used to PUT the file to create an object").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPT).hasArg().argName("mimetype") .desc("Value to use for the Content-Type header. Defaults to application/octet-stream.").build()); opts.addOption(Option.builder().longOpt(VERIFY_URL_OPT).hasArg().argName("url") .desc("If specified, read back the object from this URL and compare with the local file.").build()); opts.addOption(Option.builder().longOpt(LOG_LEVEL_OPT).hasArg().argName("level").type(Level.class) .desc("Sets the log level: DEBUG, INFO, WARN, ERROR, or FATAL. Default is ERROR.").build()); opts.addOption(Option.builder().longOpt(LOG_FILE_OPT).hasArg().argName("filename") .desc("Filename to write log messages. Setting to STDOUT or STDERR will write log messages to the " + "appropriate process stream. Default is STDERR.") .build()); opts.addOption(Option.builder().longOpt(LOG_PATTERN_OPT).hasArg().argName("log4j-pattern") .desc("Sets the " + "Log4J pattern to use when writing log messages. Defaults to " + "'%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n'") .build()); opts.addOption(Option.builder().longOpt(STANDARD_MD5) .desc("Use standard Java IO for local checksum " + "instead of NIO").build()); opts.addOption(Option.builder().longOpt(RETRY_DELAY_OPT).hasArg().argName("milliseconds") .desc("Initial retry delay in ms. Subsequent retries will continue to double this exponentially. " + "The default value is " + RETRY_DELAY) .build()); opts.addOption(Option.builder().longOpt(RETRY_COUNT_OPT).hasArg().argName("count") .desc("Number of times to " + "retry failed transactions. Set to zero to disable retries. Defaults to " + RETRY_COUNT) .build()); opts.addOption(Option.builder().longOpt(SAVE_MD5).hasArg().argName("path-to-file") .desc("Sets the file location where the local MD5 hash will be written.").build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar SmartUploader.jar", opts, true); System.exit(255); } // Required options. String url = cmd.getOptionValue(URL_OPT); String file = cmd.getOptionValue(FILE_OPT); SmartUploader uploader = null; try { uploader = new SmartUploader(new URL(url), new File(file).toPath()); } catch (MalformedURLException e) { System.err.println("Could not parse upload URL: " + e.getMessage()); System.exit(2); } if (cmd.hasOption(SEGMENT_SIZE_OPT)) { uploader.setSegmentSize(Integer.parseInt(cmd.getOptionValue(SEGMENT_SIZE_OPT))); } if (cmd.hasOption(THREADS_OPT)) { uploader.setThreadCount(Integer.parseInt(cmd.getOptionValue(THREADS_OPT))); } if (cmd.hasOption(SIMPLE_OPT)) { uploader.setSimpleMode(true); } if (cmd.hasOption(CONTENT_TYPE_OPT)) { uploader.setContentType(cmd.getOptionValue(CONTENT_TYPE_OPT)); } if (cmd.hasOption(VERIFY_URL_OPT)) { try { uploader.setVerifyUrl(new URL(cmd.getOptionValue(VERIFY_URL_OPT))); } catch (MalformedURLException e) { System.err.println("Could not parse verify URL: " + e.getMessage()); System.exit(3); } } if (cmd.hasOption(STANDARD_MD5)) { uploader.setStandardChecksum(true); } if (cmd.hasOption(RETRY_COUNT_OPT)) { uploader.setRetryCount(Integer.parseInt(cmd.getOptionValue(RETRY_COUNT_OPT))); } if (cmd.hasOption(RETRY_DELAY_OPT)) { uploader.setRetryDelay(Integer.parseInt(cmd.getOptionValue(RETRY_DELAY_OPT))); } if (cmd.hasOption(SAVE_MD5)) { uploader.setSaveMD5(cmd.getOptionValue(SAVE_MD5)); } // // Configure Logging // // Pattern String layoutString = "%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n"; if (cmd.hasOption(LOG_PATTERN_OPT)) { layoutString = cmd.getOptionValue(LOG_PATTERN_OPT); } PatternLayout layout = new PatternLayout(layoutString); // Appender String logFileName = "STDERR"; if (cmd.hasOption(LOG_FILE_OPT)) { logFileName = cmd.getOptionValue(LOG_FILE_OPT); } Appender appender = null; if (logFileName.equals("STDERR")) { appender = new ConsoleAppender(layout, "System.err"); } else if (logFileName.equals("STDOUT")) { appender = new ConsoleAppender(layout, "System.out"); } else { // Just a regular file. try { appender = new FileAppender(layout, logFileName); } catch (IOException e) { System.err.println("FATAL: Could not configure appender"); e.printStackTrace(); System.exit(8); } } LogManager.getRootLogger().addAppender(appender); // Log level String logLevel = "ERROR"; if (cmd.hasOption(LOG_LEVEL_OPT)) { logLevel = cmd.getOptionValue(LOG_LEVEL_OPT); } LogManager.getRootLogger().setLevel(Level.toLevel(logLevel)); // // Start the upload // uploader.doUpload(); System.exit(0); }
From source file:com.github.vatbub.tictactoe.view.Main.java
public static void main(String[] args) { Common.getInstance().setAppName("tictactoev2"); FOKLogger.enableLoggingOfUncaughtExceptions(); try {/* ww w . ja v a 2s. c o m*/ applicationConfiguration = new Config(new URL( "https://raw.githubusercontent.com/vatbub/tictactoe/master/remoteconfig/client.properties"), Main.class.getResource("fallbackConfig.properties"), true, "tictactoeClientConfigCache.properties", true); } catch (IOException e) { FOKLogger.log(Main.class.getName(), Level.SEVERE, "Could not read the remote config", e); } for (String arg : args) { if (arg.toLowerCase().matches("mockappversion=.*")) { // Set the mock version String version = arg.substring(arg.toLowerCase().indexOf('=') + 1); Common.getInstance().setMockAppVersion(version); } else if (arg.toLowerCase().matches("mockbuildnumber=.*")) { // Set the mock build number String buildnumber = arg.substring(arg.toLowerCase().indexOf('=') + 1); Common.getInstance().setMockBuildNumber(buildnumber); } else if (arg.toLowerCase().matches("mockpackaging=.*")) { // Set the mock packaging String packaging = arg.substring(arg.toLowerCase().indexOf('=') + 1); Common.getInstance().setMockPackaging(packaging); } else if (arg.toLowerCase().matches("locale=.*")) { // set the gui language String guiLanguageCode = arg.substring(arg.toLowerCase().indexOf('=') + 1); FOKLogger.info(Main.class.getName(), "Setting language: " + guiLanguageCode); Locale.setDefault(new Locale(guiLanguageCode)); } } launch(args); }
From source file:org.mitre.stix.STIXSchema.java
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { STIXSchema schema = STIXSchema.getInstance(); System.out.println(schema.validate( new URL("https://raw.githubusercontent.com/STIXProject/python-stix/v1.2.0.0/examples/sample.xml"))); System.out.println(schema.getVersion()); }
From source file:fr.inria.edelweiss.kgdqp.core.FedInferrencingCLI.java
public static void main(String args[]) throws ParseException, EngineException, InterruptedException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;//w w w . jav a2 s . co m boolean rulesSelection = false; File rulesDir = null; File ontDir = null; Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); Option endpointOpt = new Option("e", "endpoint", true, "a federated sparql endpoint URL"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); Option rulesOpt = new Option("r", "rulesDir", true, "directory containing the inference rules"); Option ontOpt = new Option("o", "ontologiesDir", true, "directory containing the ontologies for rules selection"); // Option selOpt = new Option("s", "rulesSelection", false, "if set to true, only the applicable rules are run"); options.addOption(queryOpt); options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(rulesOpt); options.addOption(ontOpt); // options.addOption(selOpt); String header = "Corese/KGRAM distributed rule engine command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr, olivier.corby@inria.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (!cmd.hasOption("e")) { logger.info("You must specify at least the URL of one sparql endpoint !"); System.exit(0); } else { endpoints = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("e"))); } if (cmd.hasOption("o")) { rulesSelection = true; String ontDirPath = cmd.getOptionValue("o"); ontDir = new File(ontDirPath); if (!ontDir.isDirectory()) { logger.warn(ontDirPath + " is not a valid directory path."); System.exit(0); } } if (!cmd.hasOption("r")) { logger.info("You must specify a path for inference rules directory !"); System.exit(0); } else if (rulesSelection) { } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } String rulesDirPath = cmd.getOptionValue("r"); rulesDir = new File(rulesDirPath); if (!rulesDir.isDirectory()) { logger.warn(rulesDirPath + " is not a valid directory path."); System.exit(0); } ///////////////// Graph graph = Graph.create(); QueryProcessDQP execDQP = QueryProcessDQP.create(graph); for (String url : endpoints) { try { execDQP.addRemote(new URL(url), WSImplem.REST); } catch (MalformedURLException ex) { logger.error(url + " is not a well-formed URL"); System.exit(1); } } // Local rules graph initialization Graph rulesG = Graph.create(); Load ld = Load.create(rulesG); if (rulesSelection) { // Ontology loading if (ontDir.isDirectory()) { for (File o : ontDir.listFiles()) { logger.info("Loading " + o.getAbsolutePath()); ld.load(o.getAbsolutePath()); } } } // Rules loading if (rulesDir.isDirectory()) { for (File r : rulesDir.listFiles()) { logger.info("Loading " + r.getAbsolutePath()); ld.load(r.getAbsolutePath()); } } // Rule engine initialization RuleEngine ruleEngine = RuleEngine.create(graph); ruleEngine.set(execDQP); StopWatch sw = new StopWatch(); logger.info("Federated graph size : " + graph.size()); logger.info("Rules graph size : " + rulesG.size()); // Rule selection logger.info("Rules selection"); QueryProcess localKgram = QueryProcess.create(rulesG); ArrayList<String> applicableRules = new ArrayList<String>(); sw.start(); String rulesSelQuery = ""; if (rulesSelection) { rulesSelQuery = pertinentRulesQuery; } else { rulesSelQuery = allRulesQuery; } Mappings maps = localKgram.query(rulesSelQuery); logger.info("Rules selected in " + sw.getTime() + " ms"); logger.info("Applicable rules : " + maps.size()); // Selected rule loading for (Mapping map : maps) { IDatatype dt = (IDatatype) map.getValue("?res"); String rule = dt.getLabel(); //loading rule in the rule engine // logger.info("Adding rule : " + rule); applicableRules.add(rule); ruleEngine.addRule(rule); } // Rules application on distributed sparql endpoints logger.info("Rules application (" + applicableRules.size() + " rules)"); ExecutorService threadPool = Executors.newCachedThreadPool(); RuleEngineThread ruleThread = new RuleEngineThread(ruleEngine); sw.reset(); sw.start(); // ruleEngine.process(); threadPool.execute(ruleThread); threadPool.shutdown(); //monitoring loop while (!threadPool.isTerminated()) { System.out.println("******************************"); System.out.println(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); System.out.println("Rule engine running for " + sw.getTime() + " ms"); System.out.println("Federated graph size : " + graph.size()); Thread.sleep(10000); } logger.info("Federated graph size : " + graph.size()); logger.info(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); ///////////// Query file processing // StringBuffer fileData = new StringBuffer(1000); // BufferedReader reader = null; // try { // reader = new BufferedReader(new FileReader(queryPath)); // } catch (FileNotFoundException ex) { // logger.error("Query file "+queryPath+" not found !"); // System.exit(1); // } // char[] buf = new char[1024]; // int numRead = 0; // try { // while ((numRead = reader.read(buf)) != -1) { // String readData = String.valueOf(buf, 0, numRead); // fileData.append(readData); // buf = new char[1024]; // } // reader.close(); // } catch (IOException ex) { // logger.error("Error while reading query file "+queryPath); // System.exit(1); // } // // String sparqlQuery = fileData.toString(); // // Query q = exec.compile(sparqlQuery,null); // System.out.println(q); // // StopWatch sw = new StopWatch(); // sw.start(); // Mappings map = exec.query(sparqlQuery); // int dqpSize = map.size(); // System.out.println("--------"); // long time = sw.getTime(); // System.out.println(time + " " + dqpSize); }
From source file:ed.net.lb.LB.java
public static void main(String args[]) throws Exception { int verbose = 0; for (int i = 0; i < args.length; i++) { if (args[i].matches("\\-v+")) { verbose = args[i].length() - 1; args[i] = ""; }//from www . ja va2s .co m } Options o = new Options(); o.addOption("p", "port", true, "Port to Listen On"); o.addOption("v", "verbose", false, "Verbose"); o.addOption("mapfile", "m", true, "file from which to load mappings"); CommandLine cl = (new BasicParser()).parse(o, args); final int port = Integer.parseInt(cl.getOptionValue("p", "8080")); MappingFactory mf = null; if (cl.hasOption("m")) mf = new TextMapping.Factory(cl.getOptionValue("m", null)); else mf = new GridMapping.Factory(); System.out.println("10gen load balancer"); System.out.println("\t port \t " + port); System.out.println("\t verbose \t " + verbose); int retriesLeft = 2; HttpMonitor.setApplicationType("Load Balancer"); LB lb = null; while (retriesLeft-- > 0) { try { lb = new LB(port, mf, verbose); break; } catch (BindException be) { be.printStackTrace(); System.out.println("can't bind to port. going to try to kill old one"); HttpDownload.downloadToJS(new URL("http://127.0.0.1:" + port + "/~kill")); Thread.sleep(100); } } if (lb == null) { System.err.println("couldn't ever bind"); System.exit(-1); return; } lb.start(); lb.join(); System.exit(0); }