List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.cloudbees.eclipse.core.CBAPIService.java
private CloudBeesException cbthrow(String errMsg, Exception e) { String extra = ""; if (e.getCause() != null) { extra = e.getCause().getMessage(); }/*www . ja v a2s . c om*/ return new CloudBeesException("Failed to get account services info." + (errMsg.length() > 0 ? "\n" + errMsg + "; " + extra : "\n" + extra), e); }
From source file:com.ehdev.chronos.lib.Chronos.java
static public boolean getDataOnSDCard(Context context, boolean oldFormat) { if (getCardReadStatus() == false) { CharSequence text = "Could not read to SD Card!."; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();//w w w . ja v a2 s. co m return false; } //Create 1 Job DateTime jobMidnight = DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime() .withZone(DateTimeZone.getDefault()); Job currentJob = new Job("", 10, jobMidnight, PayPeriodDuration.TWO_WEEKS); currentJob.setDoubletimeThreshold(60); currentJob.setOvertimeThreshold(40); currentJob.setOvertimeOptions(OvertimeOptions.WEEK); List<Punch> punches = new LinkedList<Punch>(); List<Task> tasks = new LinkedList<Task>(); List<Note> notes = new LinkedList<Note>(); Task newTask; //Basic element newTask = new Task(currentJob, 0, "Regular"); tasks.add(newTask); newTask = new Task(currentJob, 1, "Lunch Break"); newTask.setEnablePayOverride(true); newTask.setPayOverride(0.0f); tasks.add(newTask); newTask = new Task(currentJob, 2, "Other Break"); newTask.setEnablePayOverride(true); newTask.setPayOverride(0.0f); tasks.add(newTask); newTask = new Task(currentJob, 3, "Travel"); tasks.add(newTask); newTask = new Task(currentJob, 4, "Admin"); tasks.add(newTask); newTask = new Task(currentJob, 5, "Sick Leave"); tasks.add(newTask); newTask = new Task(currentJob, 6, "Personal Time"); tasks.add(newTask); newTask = new Task(currentJob, 7, "Other"); tasks.add(newTask); newTask = new Task(currentJob, 8, "Holiday Pay"); tasks.add(newTask); try { File directory = Environment.getExternalStorageDirectory(); File backup; if (!oldFormat) backup = new File(directory, "Chronos_Backup.csv"); else backup = new File(directory, "Chronos_Backup.cvs"); if (!backup.exists()) { return false; } BufferedReader br = new BufferedReader(new FileReader(backup)); String strLine = br.readLine(); //id,date,name,task name, date in ms, job num, task num //1,Sun Mar 11 2012 15:46,null,Regular,1331498803269,1,1 while (strLine != null) { //Log.d(TAG, strLine); String[] parcedString = strLine.split(","); long time; int task; if (!oldFormat) { time = Long.parseLong(parcedString[4]); task = Integer.parseInt(parcedString[6]); } else { time = Long.parseLong(parcedString[1]); task = Integer.parseInt(parcedString[2]); //System.out.println(parcedString.length); if (parcedString.length > 4 && StringUtils.isNotBlank(parcedString[4])) { String noteContent = parcedString[4]; Note note = new Note(Chronos.getDateFromStartOfPayPeriod(currentJob, new DateTime(time)), currentJob, noteContent); notes.add(note); } } //Job iJob, Task iPunchTask, DateTime iTime punches.add(new Punch(currentJob, tasks.get(task - 1), new DateTime(time))); strLine = br.readLine(); } } catch (Exception e) { e.printStackTrace(); if (e != null && e.getCause() != null) { Log.e(TAG, e.getCause().toString()); } return false; } //Log.d(TAG, "Number of punches: " + punches.size()); try { Chronos chronos = new Chronos(context); TableUtils.dropTable(chronos.getConnectionSource(), Punch.class, true); //Punch - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Task.class, true); //Task - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Job.class, true); //Job - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Note.class, true); //Note - Drop all //Recreate DB TableUtils.createTable(chronos.getConnectionSource(), Punch.class); //Punch - Create Table TableUtils.createTable(chronos.getConnectionSource(), Task.class); //Task - Create Table TableUtils.createTable(chronos.getConnectionSource(), Job.class); //Job - Create Table TableUtils.createTable(chronos.getConnectionSource(), Note.class); //Task - Create Table //recreate entries Dao<Task, String> taskDAO = chronos.getTaskDao(); Dao<Job, String> jobDAO = chronos.getJobDao(); Dao<Punch, String> punchDOA = chronos.getPunchDao(); Dao<Note, String> noteDOA = chronos.getNoteDao(); jobDAO.create(currentJob); for (Task t : tasks) { taskDAO.create(t); } for (Punch p : punches) { punchDOA.create(p); } HashMap<DateTime, Note> merger = new HashMap<DateTime, Note>(); for (Note n : notes) { merger.put(n.getTime(), n); } for (DateTime dt : merger.keySet()) { noteDOA.create(merger.get(dt)); } chronos.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); return false; } return true; }
From source file:com.ai.bss.webui.party.controller.PartyController.java
@RequestMapping(value = "/rename/renameDepartment", method = RequestMethod.POST) public String renameDepartment(@ModelAttribute("department") @Valid Department department, BindingResult bindingResult, Model model) { if (!bindingResult.hasErrors()) { PartyId partyId = new PartyId(department.getPartyId()); PartyEntry partyEntry = client.getForObject("http://party-query-service/party/" + partyId, PartyEntry.class); if (null != partyEntry && (partyEntry instanceof DepartmentEntry)) { RenameDepartmentCommand command = new RenameDepartmentCommand(partyId, department.getDepartmentName()); command.setOldDepartmentName(partyEntry.getName()); command.setTenantId(TenantContext.getCurrentTenant()); try { command = client.postForObject("http://party-service/party/RenameDepartmentCommand", command, RenameDepartmentCommand.class); return "redirect:/party"; } catch (Exception e) { bindingResult.rejectValue("departmentName", "error.renameDepartment.notChanged", e.getCause().getMessage()); }//from w ww .j av a 2 s . com } } return "party/renameDepartment"; }
From source file:com.streamsets.pipeline.stage.origin.multikafka.MultiKafkaSource.java
@Override public void produce(Map<String, String> lastOffsets, int maxBatchSize) throws StageException { shutdownCalled.set(false);//from w w w . j a v a 2 s . co m batchSize = Math.min(maxBatchSize, conf.maxBatchSize); int numThreads = getNumberOfThreads(); List<Future<Long>> futures = new ArrayList<>(numThreads); CountDownLatch startProcessingGate = new CountDownLatch(numThreads); // Run all the threads Stage.Context context = getContext(); for (int i = 0; i < numThreads; i++) { try { futures.add(executor.submit(new MultiTopicCallable(i, conf.topicList, KafkaConsumerLoader.createConsumer(getKafkaProperties(context), context, conf.kafkaAutoOffsetReset, conf.timestampToSearchOffsets, conf.topicList), startProcessingGate))); } catch (Exception e) { LOG.error("Error while initializing Kafka consumer: {}", e.toString(), e); Throwables.propagateIfPossible(e.getCause(), StageException.class); Throwables.propagate(e); } startProcessingGate.countDown(); } // Wait for proper execution completion long totalMessagesProcessed = 0; for (Future<Long> future : futures) { try { totalMessagesProcessed += future.get(); } catch (InterruptedException e) { // all threads should stop if the main thread is interrupted shutdown(); Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOG.info("Multi kafka thread halted unexpectedly: {}", future, e.getCause().getMessage(), e); shutdown(); Throwables.propagateIfPossible(e.getCause(), StageException.class); Throwables.propagate(e.getCause()); } } LOG.info("Total messages consumed by all threads: {}", totalMessagesProcessed); executor.shutdown(); }
From source file:org.cnbi.web.system.listener.WebApplicationInitializer.java
/** * ??//from w w w.j ava 2 s. c o m * * @Author * @Time 2014321?6:12:09 */ private void initDimData() { String dimSql = sqlMap.get(Constants.INIT + Constants.DIM), dimFieldSql = sqlMap.get(Constants.INIT + Constants.DIM + Constants.FIELD); String raplaceStr = "DW_Dim"; try { @SuppressWarnings("unchecked") List<UtilDim> dimDatas = (List<UtilDim>) handleService.query(dimSql, new UtilDim()); for (int i = 0, len = dimDatas.size(); i < len; i++) {// factTable UtilDim mapBean = dimDatas.get(i); String factTable = mapBean.getScode(), sql = sqlMap.get(Constants.INIT + Constants.ITEM); String fieldKey = factTable.replace(raplaceStr, ""); sql = sql.replace(":factTable", factTable); if (factTable.equals("DW_DimBranch")) { sql = "SELECT scode, sname, sregion as spcode FROM DW_DimBranch"; } @SuppressWarnings("unchecked") List<UtilDim> dimList = (List<UtilDim>) handleService.query(sql, new UtilDim()); dimMap.put(fieldKey, dimList); } servletContext.setAttribute(Constants.DIM + Constants.MAP, dimMap); @SuppressWarnings("unchecked") List<UtilDim> dimFieldDatas = (List<UtilDim>) handleService.query(dimFieldSql, new UtilDim()); Map<String, String> dimFieldMap = new HashMap<String, String>(); for (int i = 0, len = dimFieldDatas.size(); i < len; i++) {// factTable UtilDim mapBean = dimFieldDatas.get(i); dimFieldMap.put(mapBean.getScode(), mapBean.getSname()); } servletContext.setAttribute(Constants.DIM + Constants.FIELD + Constants.MAP, dimFieldMap); } catch (Exception e) { logger.error("?initDimData??\n" + e); throw new RuntimeException(e.getMessage(), e.getCause()); } }
From source file:epsi.i5.datamining.JsonBuilder.java
/** * This method return un DataEntity with all attributes filled from the json * file// ww w.jav a2s . com * * @param file * @return */ public List<DataEntity> getFullCommentaires(File file) { List<DataEntity> listeCommentaires = new ArrayList(); try { Object objFile = parser.parse(new FileReader(file.getAbsolutePath())); JSONArray jsonArray = (JSONArray) objFile; for (Object obj : jsonArray) { JSONObject jsonObject = (JSONObject) obj; DataEntity commentaire = new DataEntity(); commentaire.setId(jsonObject.get("id").toString()); commentaire.setCommentaires((String) jsonObject.get("commentaires")); commentaire.setPolarite((String) jsonObject.get("polarit")); try { commentaire.setListeCategorie((List) jsonObject.get("catgorie")); } catch (Exception e) { System.out.println("Message : " + e.getMessage()); commentaire.setListeCategorie(null); } listeCommentaires.add(commentaire); } } catch (FileNotFoundException e) { System.out.println("Une erreur est survenue lors de lecture du fichier JSON"); System.out.println("Cause : " + e.getCause()); System.out.println("Message : " + e.getMessage()); } catch (IOException | ParseException ex) { Logger.getLogger(JsonBuilder.class.getName()).log(Level.SEVERE, null, ex); } return listeCommentaires; }
From source file:de.grobox.blitzmail.SendActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // before doing anything show notification about sending process mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait)) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); // Sets an activity indicator for an operation of indeterminate length mBuilder.setProgress(0, 0, true);//ww w.j a v a2 s .c om // Create Pending Intent notifyIntent = new Intent(this, NotificationHandlerActivity.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); // Issues the notification mNotifyManager.notify(0, mBuilder.build()); Properties prefs; try { prefs = getPrefs(); } catch (Exception e) { String msg = e.getMessage(); Log.i("SendActivity", "ERROR: " + msg, e); if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) { msg = getString(R.string.error_decrypt); } showError(msg); return; } // get and handle Intent Intent intent = getIntent(); String action = intent.getAction(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); //String email = intent.getStringExtra(Intent.EXTRA_EMAIL); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); String cc = intent.getStringExtra(Intent.EXTRA_CC); String bcc = intent.getStringExtra(Intent.EXTRA_BCC); // Check for empty content if (subject == null && text != null) { // cut all characters from subject after the 128th subject = text.substring(0, (text.length() < 128) ? text.length() : 128); // remove line breaks from subject subject = subject.replace("\n", " ").replace("\r", " "); } else if (subject != null && text == null) { text = subject; } else if (subject == null && text == null) { Log.e("Instant Mail", "Did not send mail, because subject and body empty."); showError(getString(R.string.error_no_body_no_subject)); return; } // create JSON object with mail information mMail = new JSONObject(); try { mMail.put("id", String.valueOf(new Date().getTime())); mMail.put("body", text); mMail.put("subject", subject); mMail.put("cc", cc); mMail.put("bcc", bcc); } catch (JSONException e) { e.printStackTrace(); } // remember mail for later MailStorage.saveMail(this, mMail); // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } else if (action.equals("BlitzMailReSend")) { try { mMail = new JSONObject(intent.getStringExtra("mail")); } catch (JSONException e) { e.printStackTrace(); } // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } finish(); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
private void testLoginShouldThrowError(final MobileServiceAuthenticationProvider provider) throws Throwable { final ResultsContainer result = new ResultsContainer(); final String errorMessage = "fake error"; final String errorJson = "{error:'" + errorMessage + "'}"; // Create client MobileServiceClient client = null;/*from w ww . j av a 2 s. c om*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { } // Add a new filter to the client client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { result.setRequestUrl(request.getUrl()); ServiceFilterResponseMock response = new ServiceFilterResponseMock(); response.setContent(errorJson); response.setStatus(new StatusLine() { @Override public int getStatusCode() { return 400; } @Override public String getReasonPhrase() { return errorMessage; } @Override public ProtocolVersion getProtocolVersion() { return null; } }); final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create(); resultFuture.set(response); return resultFuture; } }); try { client.login(provider, "{myToken:123}").get(); Assert.fail(); } catch (Exception exception) { assertTrue(exception.getCause() instanceof MobileServiceException); MobileServiceException cause = (MobileServiceException) exception.getCause().getCause(); assertEquals(errorMessage, cause.getMessage()); } }
From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java
public DOIEZIdServiceBean() { ezidService = new EZIDService(baseURLString); USERNAME = System.getProperty("doi.username"); PASSWORD = System.getProperty("doi.password"); try {/*ww w . j a va 2 s.com*/ ezidService.login(USERNAME, PASSWORD); } catch (Exception e) { System.out.print("login failed "); System.out.print("String " + e.toString()); System.out.print("localized message " + e.getLocalizedMessage()); System.out.print("cause " + e.getCause()); System.out.print("message " + e.getMessage()); } }
From source file:org.cnbi.web.system.listener.WebApplicationInitializer.java
/** * ??//from w ww . jav a 2 s .com */ private void initSubjectData() { String subKey = Constants.INIT + Constants.SUBJECT + Constants.LIST, comKey = Constants.INIT + Constants.COMPOSE + Constants.LIST, subSql = sqlMap.get(subKey), comSql = sqlMap.get(comKey);// ,dimItemDatasSql // = // sqlMap.get(Constants.INIT+Constants.ITEM); Map<String, SubjectSqlBean> subjectMap = new HashMap<String, SubjectSqlBean>(); // String filePath = realPath // +"resources"+File.separator+"json"+File.separator; try {// @SuppressWarnings("unchecked") List<Subject> subjectList = (List<Subject>) handleService.query(subSql, new Subject("0001", "", "0")); for (int i = 0, len = subjectList.size(); i < len; i++) { Subject subject = subjectList.get(i); @SuppressWarnings("unchecked") List<Compose> composeList = (List<Compose>) handleService.query(comSql, new Compose(subject.getScode())); Map<String, String> measureMap = null;// Map<String, Compose> compseMap = null; for (int j = 0, lj = composeList.size(); j < lj; j++) { Compose compose = composeList.get(j); String type = compose.getType();// if (type.equalsIgnoreCase(Constants.MEASURE)) {// ? if (null == measureMap) {// ? ??new??new measureMap = new TreeMap<String, String>(new Comparator<String>() {// // // ???obj2.compareTo(obj1); public int compare(String obj1, String obj2) { return obj1.compareTo(obj2); } }); } measureMap.put(compose.getField(), compose.getSname()); } else if (type.equalsIgnoreCase(Constants.SUB)) {// SUBJECT // } else {// if (null == compseMap) {// ?? compseMap = new HashMap<String, Compose>(); } compose.setDimDatas(dimMap.get(compose.getField())); compseMap.put(compose.getField(), compose); } } if (null != compseMap && null != measureMap) { SubjectSqlBean subjectBean = new SubjectSqlBean(subject, compseMap, measureMap); subjectMap.put(subject.getScode(), subjectBean); // logger.info(subject.getSname() + "?" + subject.getScode() // + "SQL====\n" + subjectBean.getSql()); // if (subject.getScode().equals("1010")) { // System.out.println(subjectBean.getSql(new // DisplayBean(true,true))); // querySubjectData(subjectBean,filePath+subject.getScode()+"22.json"); // } } } servletContext.setAttribute(Constants.SUBJECT + Constants.MAP, subjectMap); } catch (Exception e) { logger.error("????\n" + e); throw new RuntimeException(e.getMessage(), e.getCause()); } }