List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.newatlanta.appengine.datastore.CachingDatastoreService.java
@Override public Key put(Entity entity) { entity = completeKey(entity);//from w w w . jav a 2 s . c om Key key = entity.getKey(); MemcacheService memcache = getMemcacheService(); memcache.setErrorHandler(new StrictErrorHandler()); try { memcache.put(key, entity, expiration); if ((cacheOption == CacheOption.WRITE_BEHIND) && watchDogIsAlive()) { // queue write-behind task only if not already one queued for this key if (memcache.put(keyToString(key), null, null, ADD_ONLY_IF_NOT_PRESENT)) { queue.add(payload(serialize(key), TASK_CONTENT_TYPE)); } return key; } } catch (Exception e) { log.warning(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); memcache.delete(key); } // if WRITE_THROUGH, or failed to write memcache, or failed to queue // write-behind task, then write directly to datastore return getDatastoreService().put(entity); }
From source file:com.taobao.datax.plugins.writer.mysqlwriter.MysqlWriter.java
@Override public int post(PluginParam param) { if (StringUtils.isBlank(this.post)) return PluginStatus.SUCCESS.value(); /*//w w w . java 2s . co m * add by bazhen.csy if (null == this.connection) { throw new * DataExchangeException(String.format( * "MysqlWriter connect %s failed in post work .", this.host)); } */ Statement stmt = null; try { this.connection = DBSource.getConnection(this.sourceUniqKey); stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); for (String subSql : this.post.split(";")) { this.logger.info(String.format("Excute prepare sql %s .", subSql)); stmt.execute(subSql); } return PluginStatus.SUCCESS.value(); } catch (Exception e) { throw new DataExchangeException(e.getCause()); } finally { try { if (null != stmt) { stmt.close(); } if (null != this.connection) { this.connection.close(); this.connection = null; } } catch (Exception e2) { } } }
From source file:com.taobao.datax.plugins.writer.oraclejdbcwriter.OracleJdbcWriter.java
@Override public int post(PluginParam param) { if (StringUtils.isBlank(this.post)) return PluginStatus.SUCCESS.value(); Statement stmt = null;//from w w w . java2s . co m try { this.connection = DBSource.getConnection(this.sourceUniqKey); stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); for (String subSql : this.post.split(";")) { this.logger.info(String.format("Excute prepare sql %s .", subSql)); stmt.execute(subSql); } return PluginStatus.SUCCESS.value(); } catch (Exception e) { e.printStackTrace(); throw new DataExchangeException(e.getCause()); } finally { try { if (null != stmt) { stmt.close(); } if (null != this.connection) { this.connection.close(); this.connection = null; } } catch (Exception e2) { } } }
From source file:org.toobsframework.pres.doit.DoItRunner.java
public void runDoIt(IRequest request, DoIt doIt) throws Exception { // Run Actions Action thisAction = null;//from w w w .j a va 2 s. c o m if (doIt.getActions() != null) { Actions actionsObj = doIt.getActions(); String multipleActionsKey = "defaultAction"; String[] multipleActionsAry = new String[] { "" }; Map<String, Object> paramMap = request.getParams(); Map<String, Object> responseMap = request.getResponseParams(); try { if (actionsObj.getMultipleActionsKey() != null && !actionsObj.getMultipleActionsKey().equals("")) { multipleActionsKey = actionsObj.getMultipleActionsKey(); Object multActObj = paramMap.get(actionsObj.getMultipleActionsKey()); if (multActObj != null && multActObj.getClass().isArray()) { multipleActionsAry = (String[]) multActObj; } else if (multActObj != null) { multipleActionsAry = new String[] { (String) multActObj }; } else { multipleActionsAry = new String[] { "" }; } } for (int i = 0; i < multipleActionsAry.length; i++) { Map<String, Object> actionParams = new HashMap<String, Object>(paramMap); responseMap.clear(); actionParams.put(multipleActionsKey, multipleActionsAry[i]); actionParams.put(PlatformConstants.MULTI_ACTION_INSTANCE, new Integer(i)); Enumeration<Action> actions = doIt.getActions().enumerateAction(); while (actions.hasMoreElements()) { thisAction = actions.nextElement(); runAction(request, doIt.getName(), thisAction, actionParams, responseMap, (i == (multipleActionsAry.length - 1))); } } Iterator<String> iter = responseMap.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); paramMap.put(key, responseMap.get(key)); /* if (componentRequestManager.get().getHttpRequest() != null) { componentRequestManager.get().getHttpRequest().setAttribute((String)key, responseMap.get(key)); } */ } } // if validation errors are thrown, make sure to correctly pull // error objects.. catch (Exception e) { if (e.getCause() instanceof ValidationException) { log.warn("Caught validation exception."); this.pullErrorObjectsIntoRequest(request, doIt, paramMap, responseMap, multipleActionsKey, multipleActionsAry, (ValidationException) e.getCause()); } throw e; } } }
From source file:com.metamx.rdiclient.RdiClientImplTest.java
@Test public void testBadResponseCode() throws Exception { final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule()); final Serializer<MmxAuctionSummary> serializer = new JacksonSerializer<>(objectMapper); final RdiClientImpl<MmxAuctionSummary> rdiClient = makeRdiClient(serializer, 1); mockClient.setGoHandler(new GoHandler() { @Override//from w ww. j av a 2 s . c o m protected <Intermediate, Final> ListenableFuture<Final> go(Request<Intermediate, Final> request) throws Exception { return Futures.immediateFuture((Final) serverResponse(503, "Internal Server Error.")); } }.times(12)); final List<MmxAuctionSummary> events = Arrays.asList(sampleEventBasic, sampleEventBasic, sampleEventBasic); rdiClient.start(); for (MmxAuctionSummary event : events) { final ListenableFuture<RdiResponse> result = rdiClient.send(event); Exception e = null; try { result.get(); } catch (Exception e2) { e = e2; } Assert.assertTrue(e instanceof ExecutionException); Assert.assertTrue(e.getCause() instanceof RdiHttpResponseException); Assert.assertTrue(((RdiHttpResponseException) e.getCause()).getStatusCode() == 503); Assert.assertTrue(((RdiHttpResponseException) e.getCause()).getStatusReasonPhrase() .equals("Internal Server Error.")); } rdiClient.close(); }
From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java
public void test() { System.out.print("calling test"); try {/* w ww.j a v a 2 s . c o m*/ System.out.print("in test"); HashMap<String, String> metadata = new HashMap<String, String>(); metadata.put("datacite.creator", "testAuthor"); metadata.put("datacite.title", "test title"); metadata.put("datacite.publisher", "testProd"); metadata.put("datacite.publicationyear", "2013"); metadata.put("datacite.resourcetype", "Text"); String timestamp = generateTimeString(); String identifier = DOISHOULDER + "/" + "TEST" + "/" + timestamp; //Required metadata for DOI identifier metadata.put("timestamp", timestamp); if (ezidService == null) { ezidService = new EZIDService(); } String newId = ezidService.createIdentifier(identifier, metadata); System.out.print("createdIdentifier: " + newId); HashMap<String, String> moreMetadata = new HashMap<String, String>(); moreMetadata.put("datacite.title", "This is a test identifier"); ezidService.setMetadata(newId, moreMetadata); HashMap<String, String> getMetadata = ezidService.getMetadata(identifier); System.out.print("gotten metadata title: " + getMetadata.get("datacite.title")); } catch (Exception e) { System.out.print("test exceptions - regular exception"); 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:com.mhe.mediabanksearch.controller.LoginController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //TO HANDLE: Scenario 1. User comes directly on login page first time. // Scenario 2. User comes on login page but already logged in any other McGraw-Hill's application // Scenario 3. User fill up the login details and click on submit. //TODO: 1. Check for already logged-in user or ERIGHTS cookie // 2. If not already logged in then check if user has tries to login // 3. If user has not tried to login then send to login screen String thumbnailPath = Configuration.getSystemValue(Constants.IMAGE_THUMBNAIL_URL_PATH); String perPageRecordCount = Configuration.getSystemValue(Constants.ASSET_PER_PAGE_IN_CONNECT); String searchManagerName = Configuration.getSystemValue(Constants.SEARCH_MANAGER_NAME); HttpSession session = request.getSession(); session.setAttribute("baseUrl", thumbnailPath); session.setAttribute("perPageRecordCount", perPageRecordCount); session.setAttribute("searchManagerName", searchManagerName); String userAction = null;/*from ww w. ja v a 2s . co m*/ //Implementing Scenario 1. String sessionId = null; String logOutCondition = null; boolean validSession = false; Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { sessionId = getCookieValue(cookies, ERIGHTS, ERIGHTS); logOutCondition = getCookieValue(cookies, LOGOUT, "false"); logOutCondition = logOutCondition.split("~")[0]; if ("true".equalsIgnoreCase(logOutCondition)) { response.addCookie(new Cookie(LOGOUT, "true~refreshed")); return new ModelAndView(LOGIN_VIEW); } if (sessionId != null && !sessionId.equalsIgnoreCase(ERIGHTS)) { validSession = true; validSession = rmsManager.isValidSession(sessionId); } if (validSession) { userAction = "previouslyloggedin"; //userId1 = rmsManager.sessionListUserId(sessionId); } else { userAction = "firsttimelogin"; } } else { userAction = "firsttimelogin"; } //Implementing Scenario 2. long startTime = System.currentTimeMillis(); String userName = request.getParameter(REQ_PARAM_USER_NAME); String password = request.getParameter(REQ_PARAM_PASSWORD); if (userName != null && password != null && session.isNew()) { response.addCookie(new Cookie(LOGOUT, "true")); request.setAttribute("loginErrorMessage", "userError"); return new ModelAndView(LOGIN_VIEW); } boolean inError = false; boolean isServerDown = false; boolean wrongCredentials = false; boolean isSession = true; String role = null; LoginInfo loginInfo = (LoginInfo) session.getAttribute("userData"); if ((userName != null && password != null)) { if (loginInfo == null) { try { loginInfo = rmsManager.loginUser(userName, password); if (!("I".equalsIgnoreCase(loginInfo.getUserType()))) { request.setAttribute("loginErrorMessage", "invalidUser"); return new ModelAndView(LOGIN_VIEW); } isSession = false; } catch (Exception e) { e.printStackTrace(); inError = true; if (e.getCause() != null) { if (e.getCause() instanceof SOAPFaultException) { SOAPFaultException ex = (SOAPFaultException) e.getCause(); String faultString = ex.getFaultString(); String errorCode = faultString.substring(0, faultString.indexOf(":")); if (errorCode.equals(ERROR_CODE_WRONG_CREDENTIALS)) { wrongCredentials = true; } else { isServerDown = true; } } else { isServerDown = true; } } else { isServerDown = true; } } if (isServerDown) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_SERVERDOWN); return new ModelAndView(LOGIN_VIEW); } else if (inError) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_IN_ERROR); return new ModelAndView(LOGIN_VIEW); } else if (wrongCredentials) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_WRONG_CREDENTIALS); return new ModelAndView(LOGIN_VIEW); } } if (loginInfo != null) { if (!isSession) { String userId = loginInfo.getUserId(); role = rmsManager.getUserRole(userId); User user = rmsManager.getUserById(userId); String authenticationKey = loginInfo.getSessionId(); session.setAttribute(USER_ID, userId); session.setAttribute(ROLE, role); session.setAttribute(USER_ROLE_DESCRIPTION, AssetUtil.getUserRoleDescription(role)); session.setAttribute(AUTHENTICATION_KEY, authenticationKey); session.setAttribute(USERS_COMPLETE_NAME, user.getFirstName() + SPACE + user.getLastName()); session.setAttribute("userData", loginInfo); response.addCookie(new Cookie("ERIGHTS", authenticationKey)); } else { session.getAttribute(ROLE); } if (_logger.isDebugEnabled()) { long endTime = System.currentTimeMillis(); _logger.debug( "Total execution time for Login Controller is : " + (endTime - startTime) + " ms."); } //http://connectqastaging.mhhe.com/imagebanksearch/home.ibs?courseIsbn=0073273163&providerIsbn=0072859342 //return new ModelAndView(new RedirectView("/imagebanksearch/home.ibs")); //session.setAttribute("providerIsbn", "0073273163"); //session.setAttribute("courseIsbn", "0072859342"); //License lic = rmsManager.getAllLicenseProducts(Integer.parseInt(loginInfo.getUserId())); request.setAttribute("isStandalone", true); response.addCookie(new Cookie(LOGOUT, "false")); return new ModelAndView("initial.view"); } else { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_IN_ERROR); return new ModelAndView(REQ_FRWD_ASSET_VAULT_LOGIN); } } //Implementing Scenario 3. //sending to appropriate view if (userAction != null && "firsttimelogin".equalsIgnoreCase(userAction)) { return new ModelAndView(LOGIN_VIEW); } else if (userAction != null && "previouslyloggedin".equalsIgnoreCase(userAction)) { request.setAttribute("isStandalone", true); return new ModelAndView("initial.view"); } return new ModelAndView(LOGIN_VIEW); }
From source file:com.mhe.imagebanksearch.controller.LoginController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //TO HANDLE: Scenario 1. User comes directly on login page first time. // Scenario 2. User comes on login page but already logged in any other McGraw-Hill's application // Scenario 3. User fill up the login details and click on submit. //TODO: 1. Check for already logged-in user or ERIGHTS cookie // 2. If not already logged in then check if user has tries to login // 3. If user has not tried to login then send to login screen String thumbnailPath = AmazonServiceUtilTag.getImageThumbnailURL(); String perPageRecordCount = Configuration.getSystemValue(Constants.ASSET_PER_PAGE_IN_CONNECT); String searchManagerName = Configuration.getSystemValue(Constants.SEARCH_MANAGER_NAME); HttpSession session = request.getSession(); session.setAttribute("baseUrl", thumbnailPath); session.setAttribute("perPageRecordCount", perPageRecordCount); session.setAttribute("searchManagerName", searchManagerName); String userAction = null;/*from w ww .j av a2 s .com*/ //Implementing Scenario 1. String sessionId = null; String logOutCondition = null; boolean validSession = false; Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { sessionId = getCookieValue(cookies, ERIGHTS, ERIGHTS); logOutCondition = getCookieValue(cookies, LOGOUT, "false"); logOutCondition = logOutCondition.split("~")[0]; if ("true".equalsIgnoreCase(logOutCondition)) { response.addCookie(new Cookie(LOGOUT, "true~refreshed")); return new ModelAndView(LOGIN_VIEW); } if (sessionId != null && !sessionId.equalsIgnoreCase(ERIGHTS)) { validSession = true; validSession = rmsManager.isValidSession(sessionId); } if (validSession) { userAction = "previouslyloggedin"; //userId1 = rmsManager.sessionListUserId(sessionId); } else { userAction = "firsttimelogin"; } } else { userAction = "firsttimelogin"; } //Implementing Scenario 2. long startTime = System.currentTimeMillis(); String userName = request.getParameter(REQ_PARAM_USER_NAME); String password = request.getParameter(REQ_PARAM_PASSWORD); if (userName != null && password != null && session.isNew()) { response.addCookie(new Cookie(LOGOUT, "true")); request.setAttribute("loginErrorMessage", "userError"); return new ModelAndView(LOGIN_VIEW); } boolean inError = false; boolean isServerDown = false; boolean wrongCredentials = false; boolean isSession = true; String role = null; LoginInfo loginInfo = (LoginInfo) session.getAttribute("userData"); if ((userName != null && password != null)) { if (loginInfo == null) { try { loginInfo = rmsManager.loginUser(userName, password); if (!("I".equalsIgnoreCase(loginInfo.getUserType()))) { request.setAttribute("loginErrorMessage", "invalidUser"); return new ModelAndView(LOGIN_VIEW); } isSession = false; } catch (Exception e) { e.printStackTrace(); inError = true; if (e.getCause() != null) { if (e.getCause() instanceof SOAPFaultException) { SOAPFaultException ex = (SOAPFaultException) e.getCause(); String faultString = ex.getFaultString(); String errorCode = faultString.substring(0, faultString.indexOf(":")); if (errorCode.equals(ERROR_CODE_WRONG_CREDENTIALS)) { wrongCredentials = true; } else { isServerDown = true; } } else { isServerDown = true; } } else { isServerDown = true; } } if (isServerDown) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_SERVERDOWN); return new ModelAndView(LOGIN_VIEW); } else if (inError) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_IN_ERROR); return new ModelAndView(LOGIN_VIEW); } else if (wrongCredentials) { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_WRONG_CREDENTIALS); return new ModelAndView(LOGIN_VIEW); } } if (loginInfo != null) { if (!isSession) { String userId = loginInfo.getUserId(); role = rmsManager.getUserRole(userId, ASSETBANK_TYPE); User user = rmsManager.getUserById(userId); String authenticationKey = loginInfo.getSessionId(); session.setAttribute(USER_ID, userId); session.setAttribute(ROLE, role); session.setAttribute(USER_ROLE_DESCRIPTION, AssetUtil.getUserRoleDescription(role)); session.setAttribute(AUTHENTICATION_KEY, authenticationKey); session.setAttribute(USERS_COMPLETE_NAME, user.getFirstName() + SPACE + user.getLastName()); session.setAttribute("userData", loginInfo); response.addCookie(new Cookie("ERIGHTS", authenticationKey)); } else { session.getAttribute(ROLE); } if (_logger.isDebugEnabled()) { long endTime = System.currentTimeMillis(); _logger.debug( "Total execution time for Login Controller is : " + (endTime - startTime) + " ms."); } //http://connectqastaging.mhhe.com/imagebanksearch/home.ibs?courseIsbn=0073273163&providerIsbn=0072859342 //return new ModelAndView(new RedirectView("/imagebanksearch/home.ibs")); //session.setAttribute("providerIsbn", "0073273163"); //session.setAttribute("courseIsbn", "0072859342"); //License lic = rmsManager.getAllLicenseProducts(Integer.parseInt(loginInfo.getUserId())); request.setAttribute("isStandalone", true); response.addCookie(new Cookie(LOGOUT, "false")); return new ModelAndView("initial.view"); } else { request.setAttribute(REQ_ATTR_LOGIN_ERROR_MESSAGE, REQ_ATTR_IN_ERROR); return new ModelAndView(REQ_FRWD_ASSET_VAULT_LOGIN); } } //Implementing Scenario 3. //sending to appropriate view if (userAction != null && "firsttimelogin".equalsIgnoreCase(userAction)) { return new ModelAndView(LOGIN_VIEW); } else if (userAction != null && "previouslyloggedin".equalsIgnoreCase(userAction)) { request.setAttribute("isStandalone", true); return new ModelAndView("initial.view"); } return new ModelAndView(LOGIN_VIEW); }
From source file:com.legstar.cixs.jaxws.gen.Jaxws2CixsGeneratorTest.java
/** * Check controls on input make file.//from w ww .j av a2 s . c om */ public void testInputValidation() { Jaxws2CixsGenerator generator = new Jaxws2CixsGenerator(); try { generator.execute(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException: JaxbBinDir:" + " No directory name was specified", e.getCause().getMessage()); } try { generator.setJaxbBinDir(JAXB_BIN_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("You must provide a service name", e.getCause().getMessage()); } try { generator.getCixsJaxwsService().setName("jaxwsServiceName"); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetAntDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetAntDir(GEN_ANT_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetWDDDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetWDDDir(GEN_WDD_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetDistDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetDistDir(GEN_DIST_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetWarDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetWarDir(GEN_WAR_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("No operation was specified", e.getCause().getMessage()); } try { generator.setCixsJaxwsService(Samples.getLsfileae()); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetSrcDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetSrcDir(GEN_SRC_DIR); generator.execute(); fail(); } catch (Exception e) { assertEquals("java.lang.IllegalArgumentException:" + " TargetBinDir: No directory name was specified", e.getCause().getMessage()); } try { generator.setTargetBinDir(GEN_BIN_DIR); generator.execute(); } catch (Exception e) { fail(); } }
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
@SuppressWarnings("nls") @Override/* www.ja v a2 s.co m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(String.format(Messages.Task_Executing, windowTitle), 100); try { if (plotTab == null) { monitor.subTask("Preparing box plot..."); createGraphTab(inputTab.getParent()); } monitor.worked(increment); SimpleFeatureCollection features = MapUtils.getFeatures(inputLayer); if (chkStatistics.getSelection()) { if (outputTab == null) { createOutputTab(inputTab.getParent()); } ProgressListener subMonitor = GeoToolsAdapters .progress(SubMonitor.convert(monitor, Messages.Task_Internal, 20)); HtmlWriter writer = new HtmlWriter(inputLayer.getName()); DataStatisticsResult statistics = null; statistics = StatisticsFeaturesProcess.process(features, selectedFields, subMonitor); writer.writeDataStatistics(statistics); browser.setText(writer.getHTML()); } monitor.subTask("Updating box plot..."); // chartComposite.setLayer(inputLayer); updateChart(features, selectedFields.split(",")); plotTab.getParent().setSelection(plotTab); monitor.worked(increment); } catch (Exception e) { e.printStackTrace(); ToolboxPlugin.log(e.getMessage()); throw new InvocationTargetException(e.getCause(), e.getMessage()); } finally { ToolboxPlugin.log(String.format(Messages.Task_Completed, windowTitle)); monitor.done(); } }