List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:lab.home.spring.redis.test.SpringRedisTest.java
public static void main(String argv[]) { ApplicationContext ctx = new AnnotationConfigApplicationContext(RedisTestConfig.class); DictionaryDao ddao = ctx.getBean(DictionaryDao.class); try {//from ww w .j av a 2s . c o m System.out.println("ddao.setValue(\"key1\", \"value1\")"); ddao.setValue("key1", "value1"); System.out.println("ddao.setValue(\"testkey\", \"testvalue\")"); ddao.setValue("testkey", "testvalue"); System.out.println("getting value for key1 = " + ddao.getValue("key1")); System.out.println("getting value for testkey = " + ddao.getValue("testkey")); } catch (Exception e) { System.out.println(e); System.out.println(e.fillInStackTrace()); System.out.println(e.getCause()); System.out.println(e.getClass()); System.out.println(e.getStackTrace()); e.printStackTrace(); } }
From source file:demo.wssec.client.Client.java
public static void main(String args[]) throws Exception { if (args.length == 0) { System.out.println("please specify wsdl"); System.exit(1);// ww w . j a va2 s .c om } URL wsdlURL; File wsdlFile = new File(args[0]); if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } SpringBusFactory bf = new SpringBusFactory(); URL busFile = new ClassPathResource("wssec-client.xml").getURL(); Bus bus = bf.createBus(busFile.toString()); SpringBusFactory.setDefaultBus(bus); SpringBusFactory.setThreadDefaultBus(bus); Service service = Service.create(wsdlURL, SERVICE_NAME); Greeter port = service.getPort(PORT_NAME, Greeter.class); System.out.println("Invoking greetMe..."); try { String resp = port.greetMe(System.getProperty("user.name")); System.out.println("Server responded with: " + resp); System.out.println(); } catch (Exception e) { System.out.println("Invocation failed with the following: " + e.getCause()); System.out.println(); } System.exit(0); }
From source file:validation.ValidationConsumer.java
public static void main(String[] args) throws Exception { String config = ValidationConsumer.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/* ww w . jav a 2 s.c om*/ ValidationService validationService = (ValidationService) context.getBean("validationService"); // ValidationService validationService=new ValidationServiceImpl(); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(1011111); parameter.setLoginDate(new Date(System.currentTimeMillis() + 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); System.out.println("Validation Save OK"); // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); System.err.println("Validation Save ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } // Delete OK validationService.delete(2, "abc"); System.out.println("Validation Delete OK"); // Delete Error try { validationService.delete(0, "abc"); System.err.println("Validation Delete ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } }
From source file:bridge.toolkit.Controller.java
/** * @param args/*from w ww. j a v a 2s . com*/ */ public static void main(String[] args) { Controller loader = new Controller(); Catalog sampleCatalog = loader.createCatalog(); Command toolkit = sampleCatalog.getCommand("SCORM"); Context ctx = new ContextBase(); ctx.put(Keys.SCPM_FILE, args[0]); ctx.put(Keys.RESOURCE_PACKAGE, args[1]); try { if (args.length > 2) { if (args[2] != null && args[2].equalsIgnoreCase("-scormflash")) { toolkit = sampleCatalog.getCommand("SCORM"); ctx.put(Keys.OUTPUT_TYPE, null); } else if (args[2] != null && args[2].equalsIgnoreCase("-scormhtml")) { toolkit = sampleCatalog.getCommand("SCORM"); ctx.put(Keys.OUTPUT_TYPE, "SCORMHTML"); } else if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("-mobileCourse"))) { toolkit = sampleCatalog.getCommand("Mobile"); ctx.put(Keys.OUTPUT_TYPE, "mobileCourse"); } else if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("-mobilePerformanceSupport"))) { toolkit = sampleCatalog.getCommand("Mobile"); } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfinstructor")) { toolkit = sampleCatalog.getCommand("PDF"); ctx.put(Keys.PDF_OUTPUT_OPTION, "-instructor"); } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfstudent")) { toolkit = sampleCatalog.getCommand("PDF"); ctx.put(Keys.PDF_OUTPUT_OPTION, "-student"); } if (args.length > 3 && args[3] != null) { ctx.put(Keys.OUTPUT_DIRECTORY, args[3]); } } toolkit.execute(ctx); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getCause().toString()); } }
From source file:ValidateStax.java
/** * @param args/* ww w .j a v a 2s .co m*/ * the command line arguments */ public static void main(String[] args) { try { // TODO code application logic here SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); System.out.println("schema factory instance obtained is " + sf); Schema schema = sf.newSchema(new File(args[0])); System.out.println("schema obtained is = " + schema); // Get a Validator which can be used to validate instance document against // this grammar. Validator validator = schema.newValidator(); // Validate this instance document against the Instance document supplied String fileName = args[1].toString(); String fileName2 = args[2].toString(); javax.xml.transform.Result xmlResult = new javax.xml.transform.stax.StAXResult( XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(fileName2))); javax.xml.transform.Source xmlSource = new javax.xml.transform.stax.StAXSource( getXMLEventReader(fileName)); // validator.validate(new StreamSource(args[1])); validator.validate(xmlSource, xmlResult); } catch (Exception ex) { ex.printStackTrace(); System.out.println("GET CAUSE"); ex.getCause().fillInStackTrace(); } }
From source file:com.mycompany.asyncreq.MainApp.java
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException { URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("comtrade.un.org").setPath("/api/get").setParameter("max", "50000") .setParameter("type", "C").setParameter("freq", "M").setParameter("px", "HS") .setParameter("ps", "2014").setParameter("r", "804").setParameter("p", "112") .setParameter("rg", "All").setParameter("cc", "All").setParameter("fmt", "json"); URI requestURL = null;//from ww w. j ava 2 s . c om try { requestURL = builder.build(); } catch (URISyntaxException use) { } ExecutorService threadpool = Executors.newFixedThreadPool(2); Async async = Async.newInstance().use(threadpool); final Request request = Request.Get(requestURL); try { Future<Content> future = async.execute(request, new FutureCallback<Content>() { @Override public void failed(final Exception e) { System.out.println(e.getMessage() + ": " + request); } @Override public void completed(final Content content) { System.out.println("Request completed: " + request); System.out.println("Response:\n" + content.asString()); } @Override public void cancelled() { } }); } catch (Exception e) { System.out.println("Job threw exception: " + e.getCause()); } }
From source file:com.edduarte.protbox.Protbox.java
public static void main(String... args) { // activate debug / verbose mode if (args.length != 0) { List<String> argsList = Arrays.asList(args); if (argsList.contains("-v")) { Constants.verbose = true;/*ww w . j a va 2 s . c o m*/ } } // use System's look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { // If the System's look and feel is not obtainable, continue execution with JRE look and feel } // check this is a single instance try { new ServerSocket(1882); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Another instance of Protbox is already running.\n" + "Please close the other instance first.", "Protbox already running", JOptionPane.ERROR_MESSAGE); System.exit(1); } // check if System Tray is supported by this operative system if (!SystemTray.isSupported()) { JOptionPane.showMessageDialog(null, "Your operative system does not support system tray functionality.\n" + "Please try running Protbox on another operative system.", "System tray not supported", JOptionPane.ERROR_MESSAGE); System.exit(1); } // add PKCS11 providers FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(Lists.newArrayList("*.config")), HiddenFileFilter.VISIBLE); File[] providersConfigFiles = new File(Constants.PROVIDERS_DIR).listFiles(fileFilter); if (providersConfigFiles != null) { for (File f : providersConfigFiles) { try { List<String> lines = FileUtils.readLines(f); String aliasLine = lines.stream().filter(line -> line.contains("alias")).findFirst().get(); lines.remove(aliasLine); String alias = aliasLine.split("=")[1].trim(); StringBuilder sb = new StringBuilder(); for (String s : lines) { sb.append(s); sb.append("\n"); } Provider p = new SunPKCS11(new ReaderInputStream(new StringReader(sb.toString()))); Security.addProvider(p); pkcs11Providers.put(p.getName(), alias); } catch (IOException | ProviderException ex) { if (ex.getMessage().equals("Initialization failed")) { ex.printStackTrace(); String s = "The following error occurred:\n" + ex.getCause().getMessage() + "\n\nIn addition, make sure you have " + "an available smart card reader connected before opening the application."; JTextArea textArea = new JTextArea(s); textArea.setColumns(60); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setSize(textArea.getPreferredSize().width, 1); JOptionPane.showMessageDialog(null, textArea, "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); System.exit(1); } else { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Error while setting up PKCS11 provider from configuration file " + f.getName() + ".\n" + ex.getMessage(), "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); } } } } // adds a shutdown hook to save instantiated directories into files when the application is being closed Runtime.getRuntime().addShutdownHook(new Thread(Protbox::exit)); // get system tray and run tray applet tray = SystemTray.getSystemTray(); SwingUtilities.invokeLater(() -> { if (Constants.verbose) { logger.info("Starting application"); } //Start a new TrayApplet object trayApplet = TrayApplet.getInstance(); }); // prompts the user to choose which provider to use ProviderListWindow.showWindow(Protbox.pkcs11Providers.keySet(), providerName -> { // loads eID token eIDTokenLoadingWindow.showPrompt(providerName, (returnedUser, returnedCertificateData) -> { user = returnedUser; certificateData = returnedCertificateData; // gets a password to use on the saved registry files (for loading and saving) final AtomicReference<Consumer<SecretKey>> consumerHolder = new AtomicReference<>(null); consumerHolder.set(password -> { registriesPasswordKey = password; try { // if there are serialized files, load them if they can be decoded by this user's private key final List<SavedRegistry> serializedDirectories = new ArrayList<>(); if (Constants.verbose) { logger.info("Reading serialized registry files..."); } File[] registryFileList = new File(Constants.REGISTRIES_DIR).listFiles(); if (registryFileList != null) { for (File f : registryFileList) { if (f.isFile()) { byte[] data = FileUtils.readFileToByteArray(f); try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, registriesPasswordKey); byte[] registryDecryptedData = cipher.doFinal(data); serializedDirectories.add(new SavedRegistry(f, registryDecryptedData)); } catch (GeneralSecurityException ex) { if (Constants.verbose) { logger.info("Inserted Password does not correspond to " + f.getName()); } } } } } // if there were no serialized directories, show NewDirectory window to configure the first folder if (serializedDirectories.isEmpty() || registryFileList == null) { if (Constants.verbose) { logger.info("No registry files were found: running app as first time!"); } NewRegistryWindow.start(true); } else { // there were serialized directories loadRegistry(serializedDirectories); trayApplet.repaint(); showTrayApplet(); } } catch (AWTException | IOException | GeneralSecurityException | ReflectiveOperationException | ProtboxException ex) { JOptionPane.showMessageDialog(null, "The inserted password was invalid! Please try another one!", "Invalid password!", JOptionPane.ERROR_MESSAGE); insertPassword(consumerHolder.get()); } }); insertPassword(consumerHolder.get()); }); }); }
From source file:Main.java
public static String getExceptionString(Exception e) { return ".\nType: " + e.getClass().getSimpleName() + "\nCause: " + e.getCause() + "\nMessage: " + e.getMessage();/*from w w w. j a v a2s .c o m*/ }
From source file:Main.java
public static String getMessage(Exception e) { String msg = e.getLocalizedMessage(); if (msg == null && e.getCause() != null) { msg = e.getCause().getMessage(); }//from ww w. j av a2 s . co m return msg; }
From source file:com.alibaba.rocketmq.storm.topology.SimpleTopology.java
private static void submitTopology(TopologyBuilder builder) { try {// w w w . ja va 2 s . c o m if (isLocalMode) { LocalCluster cluster = new LocalCluster(); config.put(Config.STORM_CLUSTER_MODE, "local"); cluster.submitTopology(String.valueOf(config.get("topology.name")), config, builder.createTopology()); Thread.sleep(50000); cluster.shutdown(); } else { config.put(Config.STORM_CLUSTER_MODE, "distributed"); StormSubmitter.submitTopology(String.valueOf(config.get("topology.name")), config, builder.createTopology()); } } catch (Exception e) { LOG.error(e.getMessage(), e.getCause()); } }