List of usage examples for java.lang SecurityException printStackTrace
public void printStackTrace()
From source file:org.sakaiproject.poll.logic.test.PollListManagerTest.java
@Test public void testDeletePoll() { externalLogicStubb.currentUserId = TestDataPreload.USER_UPDATE; Poll poll1 = new Poll(); poll1.setCreationDate(new Date()); poll1.setVoteOpen(new Date()); poll1.setVoteClose(new Date()); poll1.setDescription("this is some text"); poll1.setText("something"); poll1.setOwner(TestDataPreload.USER_UPDATE); poll1.setSiteId(TestDataPreload.LOCATION1_ID); //we should not be able to delete a poll that hasn't been saved try {//w ww . ja v a2 s .c o m pollListManager.deletePoll(poll1); Assert.fail(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // Successful tests should be quiet. IllegalArgumentException is actually expected on a null ID. //e.printStackTrace(); } pollListManager.savePoll(poll1); Option option1 = new Option(); option1.setPollId(poll1.getPollId()); option1.setOptionText("asdgasd"); Option option2 = new Option(); option2.setPollId(poll1.getPollId()); option2.setOptionText("zsdbsdfb"); pollListManager.saveOption(option2); pollListManager.saveOption(option1); Vote vote = new Vote(); vote.setIp("Localhost"); vote.setPollId(poll1.getPollId()); vote.setPollOption(option1.getOptionId()); pollVoteManager.saveVote(vote); Long option1Id = option1.getOptionId(); Long option2Id = option2.getOptionId(); Long voteId = vote.getId(); externalLogicStubb.currentUserId = TestDataPreload.USER_NO_ACCEESS; try { pollListManager.deletePoll(poll1); Assert.fail(); } catch (SecurityException e) { // Successful tests should be quiet. SecurityException is expected here. //e.printStackTrace(); } externalLogicStubb.currentUserId = TestDataPreload.USER_UPDATE; try { pollListManager.deletePoll(poll1); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); Assert.fail(); } //check that child options are deteled Vote v1 = pollVoteManager.getVoteById(voteId); Assert.assertNull(v1); Option o1 = pollListManager.getOptionById(option1Id); Option o2 = pollListManager.getOptionById(option2Id); Assert.assertNull(o1); Assert.assertNull(o2); }
From source file:Main.java
/** * Gets the base location of the given class. * <p>//from w ww. jav a 2s .c om * If the class is directly on the file system (e.g., * "/path/to/my/package/MyClass.class") then it will return the base directory * (e.g., "file:/path/to"). * </p> * <p> * If the class is within a JAR file (e.g., * "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the * path to the JAR (e.g., "file:/path/to/my-jar.jar"). * </p> * * @param c The class whose location is desired. * @see FileUtils#urlToFile(URL) to convert the result to a {@link File}. */ public static URL getLocation(final Class<?> c) { if (c == null) return null; // could not load the class // try the easy way first try { final URL codeSourceLocation = c.getProtectionDomain().getCodeSource().getLocation(); if (codeSourceLocation != null) return codeSourceLocation; } catch (SecurityException e) { // NB: Cannot access protection domain. } catch (NullPointerException e) { // NB: Protection domain or code source is null. } // NB: The easy way failed, so we try the hard way. We ask for the class // itself as a resource, then strip the class's path from the URL string, // leaving the base path. // get the class's raw resource path final URL classResource = c.getResource(c.getSimpleName() + ".class"); if (classResource == null) return null; // cannot find class resource final String url = classResource.toString(); final String suffix = c.getCanonicalName().replace('.', '/') + ".class"; if (!url.endsWith(suffix)) return null; // weird URL // strip the class's path from the URL string final String base = url.substring(0, url.length() - suffix.length()); String path = base; // remove the "jar:" prefix and "!/" suffix, if present if (path.startsWith("jar:")) path = path.substring(4, path.length() - 2); try { return new URL(path); } catch (MalformedURLException e) { e.printStackTrace(); return null; } }
From source file:com.pivotal.gemfire.tools.pulse.internal.log.PulseLogWriter.java
private PulseLogWriter() { PulseConfig pulseConfig = Repository.get().getPulseConfig(); // Create Logger logger = Logger.getLogger(this.getClass().getName()); // Set minimum log level to level passed logger.setLevel(pulseConfig.getLogLevel()); try {// www. jav a 2s .c om // Get file handler to log messages into log file. if (fileHandler == null) { fileHandler = new FileHandler(pulseConfig.getLogFileFullName(), pulseConfig.getLogFileSize(), pulseConfig.getLogFileCount(), pulseConfig.getLogAppend()); // Log Message Formatter messageformatter = new MessageFormatter(); fileHandler.setFormatter(messageformatter); } // Remove any existing handlers // e.g. consoleHandler logger.setUseParentHandlers(false); // Add File Handler to logger object logger.addHandler(fileHandler); } catch (SecurityException e) { logger.setUseParentHandlers(true); e.printStackTrace(); } catch (IOException e) { logger.setUseParentHandlers(true); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openmrs.module.cloneandexportomrs.api.db.hibernate.HibernateCloneAndExportOmrsDAO.java
private void prepareOpenMRSTomcatDataAndWarToExport() { // File omrsTomcatWeb = new // File(CloneAndExportOmrsUtils.TOMCAT_WEBAPPS_OPENMRS_DIR); File omrsTomcatWebWar = new File(CloneAndExportOmrsUtils.TOMCAT_WEBAPPS_OPENMRS_DIR + ".war"); // File openmrsTomcatDest = new // File(CloneAndExportOmrsUtils.OPENMRS_TOMCAT_STORAGE_DIR + // File.separator + WebConstants.WEBAPP_NAME); File openmrsWarTomcatDest = new File(CloneAndExportOmrsUtils.OPENMRS_TOMCAT_STORAGE_DIR + File.separator + WebConstants.WEBAPP_NAME + ".war"); try {/*from ww w. j a va2 s . co m*/ /* * if (omrsTomcatWeb.exists() && omrsTomcatWeb.isDirectory()) { * FileUtils.copyDirectory(omrsTomcatWeb, openmrsTomcatDest); } */ if (omrsTomcatWebWar.exists() && !omrsTomcatWebWar.isDirectory()) { FileUtils.copyFile(omrsTomcatWebWar, openmrsWarTomcatDest); Zip.zip(CloneAndExportOmrsUtils.OPENMRS_TOMCAT_STORAGE_DIR + File.separator, WebConstants.WEBAPP_NAME + ".war"); try { File f = new File(CloneAndExportOmrsUtils.OPENMRS_TOMCAT_STORAGE_DIR + File.separator + WebConstants.WEBAPP_NAME + ".war"); f.delete(); } catch (SecurityException e) { } } } catch (IOException e) { e.printStackTrace(); } }
From source file:gwap.game.quiz.PlayNRatingCommunicationResource.java
private void doWork(HttpServletRequest request, HttpServletResponse response) throws IOException { this.response = response; UserPerceptionRating userPerceptionRating = readOutJSONData(request); try {/*from ww w .j av a 2 s .c o m*/ logger.info("Create perception rating for resource #0, question #1 with pairs #2", userPerceptionRating.getResourceId(), userPerceptionRating.getQuestionNumber(), userPerceptionRating.getPairs()); // get Session HttpSession ses = SessionTracker.instance().getSession(sessionID); Transaction.instance().begin(); QuizSessionBean quizSession = (QuizSessionBean) ses.getAttribute("quizSession"); QuizQuestionBean quizQuestion = quizSession.getQuizQuestion(userPerceptionRating.getQuestionNumber()); // create PerceptionRating PerceptionRating perceptionRating = new PerceptionRating(); perceptionRating.setCreated(new Date()); perceptionRating.setResource(quizQuestion.getArtResource()); perceptionRating.setFillOutTimeMs(userPerceptionRating.getFillOutTimeMs()); userPerceptionRating.setPerceptionRating(perceptionRating); RatingEvaluator ratingEvaluator = (RatingEvaluator) Component.getInstance("ratingEvaluator"); // give Feedback and calculate Bonus int[] avgUserRating = ratingEvaluator.calcAvgUserRating(quizQuestion); int[] feedback = ratingEvaluator.calculateRecommendationForFeedbackJoker(quizQuestion, userPerceptionRating, avgUserRating); int bonus = ratingEvaluator.calculateBonus(quizQuestion, userPerceptionRating, avgUserRating); JSONObject jsonObject = createJSONForFeedback(feedback, bonus); sendJSONObject(jsonObject); // save in DB PerceptionBean perceptionBean = (PerceptionBean) Component.getInstance("perceptionBean"); perceptionBean.addUserPerceptionRating(userPerceptionRating); Transaction.instance().commit(); logger.info("Created perception ratings"); } catch (NotSupportedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicMixedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicRollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:dk.kasperbaago.JSONHandler.JSONHandler.java
private void runCallback(JSONArray result, Boolean error) { Method method;//from w ww .j a va 2s . c om try { method = this.object.getClass().getMethod(this.callbackMethod, JSONArray.class, Boolean.class); method.invoke(this.object, result, error); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.manalang.monkeygrease.MonkeygreaseFilter.java
/** * Initializes Monkeygrease. Internal servlet filter method. * /*from w ww . ja v a 2s . com*/ * @param filterConfig * @throws ServletException */ public void init(FilterConfig filterConfig) throws ServletException { try { fh = new FileHandler("monkeygrease_%u.log"); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Send logger output to our FileHandler. log.addHandler(fh); log.getHandlers()[0].setFormatter(new LogFormatter()); fc = filterConfig; confReloadCheckIntervalStr = fc.getInitParameter("confReloadCheckInterval"); String commentsOnStr = fc.getInitParameter("commentsOn"); COMMENTS_ON = commentsOnStr.toLowerCase().equals("true"); String logLevel = fc.getInitParameter("logLevel"); int logLevelInt; if (logLevel != null) logLevelInt = Integer.parseInt(logLevel); else logLevelInt = 0; remoteConfigURL = fc.getInitParameter("remoteConfigURL"); if (remoteConfigURL != "" && remoteConfigURL != null) client = new HttpClient(); switch (logLevelInt) { case SEVERE: log.setLevel(Level.SEVERE); break; case WARNING: log.setLevel(Level.WARNING); break; case INFO: log.setLevel(Level.INFO); break; case CONFIG: log.setLevel(Level.CONFIG); break; case FINE: log.setLevel(Level.FINE); break; case FINER: log.setLevel(Level.FINER); break; case FINEST: log.setLevel(Level.FINEST); break; default: log.setLevel(Level.SEVERE); break; } if (confReloadCheckIntervalStr != null && !"".equals(confReloadCheckIntervalStr)) { // convert to millis confReloadCheckInterval = 1000 * Integer.parseInt(confReloadCheckIntervalStr); confReloadCheckEnabled = true; if (confReloadCheckInterval == 0) { log.config("Reload check performed on each request"); } else { log.config("Reload check set to " + confReloadCheckInterval / 1000 + "s"); } } else { confReloadCheckEnabled = false; } sc = fc.getServletContext(); cf = new Config(sc); rules = cf.getRules(); }
From source file:org.apache.hadoop.hbase.trace.SpanReceiverHost.java
private SpanReceiver loadInstance(Class<?> implClass) throws IOException { SpanReceiver impl = null;/*from w w w . j a va 2 s . c om*/ try { Object o = implClass.newInstance(); impl = (SpanReceiver) o; impl.configure(new HBaseHTraceConfiguration(this.conf)); } catch (SecurityException e) { throw new IOException(e); } catch (IllegalArgumentException e) { throw new IOException(e); } catch (RuntimeException e) { throw new IOException(e); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return impl; }
From source file:com.google.android.gms.location.sample.backgroundlocationupdates.MainActivity.java
/** * Handles the Request Updates button and requests start of location updates. *//*w ww . j a v a 2 s. co m*/ public void requestLocationUpdates(View view) { try { Log.i(TAG, "Starting location updates"); LocationRequestHelper.setRequesting(this, true); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, getPendingIntent()); } catch (SecurityException e) { LocationRequestHelper.setRequesting(this, false); e.printStackTrace(); } }
From source file:com.example.hciproject.CameraActivity.java
@Override public void onConnected(@Nullable Bundle bundle) { Log.d("PLAY SERVICES", "Play services connected"); try {/*w ww .j ava2 s . c o m*/ LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(PRIORITY_BALANCED_POWER_ACCURACY); FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, thisActivity); Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); processLocation(location); } catch (SecurityException e) { e.printStackTrace(); } }