List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:org.kuali.rice.krad.service.impl.PessimisticLockServiceImpl.java
/** * @see org.kuali.rice.krad.service.PessimisticLockService#releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.api.identity.Person) *//*w w w .ja va 2 s . co m*/ @Override public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user) { for (Iterator<PessimisticLock> iterator = locks.iterator(); iterator.hasNext();) { PessimisticLock lock = iterator.next(); if (lock.isOwnedByUser(user)) { try { delete(lock); } catch (RuntimeException ex) { if (ex.getCause() != null && ex.getCause().getClass() .equals(LegacyDataAdapter.OPTIMISTIC_LOCK_OJB_EXCEPTION_CLASS)) { LOG.warn( "Suppressing Optimistic Lock Exception. Document Num: " + lock.getDocumentNumber()); } else { throw ex; } } } } }
From source file:org.kuali.rice.krad.service.impl.PessimisticLockServiceImpl.java
/** * @see org.kuali.rice.krad.service.PessimisticLockService#releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.api.identity.Person, java.lang.String) *//*w ww .j a v a 2 s .c om*/ @Override public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user, String lockDescriptor) { for (Iterator<PessimisticLock> iterator = locks.iterator(); iterator.hasNext();) { PessimisticLock lock = iterator.next(); if ((lock.isOwnedByUser(user)) && (lockDescriptor.equals(lock.getLockDescriptor()))) { try { delete(lock); } catch (RuntimeException ex) { if (ex.getCause() != null && ex.getCause().getClass() .equals(LegacyDataAdapter.OPTIMISTIC_LOCK_OJB_EXCEPTION_CLASS)) { LOG.warn( "Suppressing Optimistic Lock Exception. Document Num: " + lock.getDocumentNumber()); } else { throw ex; } } } } }
From source file:lithium.classloadertest.FunctionalTestClassLoaderTest.java
@Test public void testMock() { FunctionalTestClassLoaderTest clTest = cl.getEntryClassInstance(); TestInterface itf = clTest.createMock(); try {//from w w w.java2 s . c o m itf.doSomeStuff("foo"); } catch (RuntimeException e) { // look for the easymock error Assert.assertEquals(AssertionError.class, e.getCause().getClass()); Assert.assertTrue(e.getCause().getMessage().contains("doSomeStuff(\"foo\")")); } }
From source file:br.gov.frameworkdemoiselle.behave.integration.alm.ALMIntegration.java
/** * A integrao presupe que cada Cenrio de cada histria um Caso de * Teste na ALM/*w ww. j a v a2 s . com*/ */ public void sendScenario(Hashtable<String, Object> result) { try { // Tenta obter dados de autenticacao vindo do Hashtable if (result.containsKey("user") && result.containsKey("password")) { username = (String) result.get("user"); password = (String) result.get("password"); } else { // Pega os dados de autenticao log.debug(message.getString("message-get-authenticator")); AutenticatorClient autenticator = new AutenticatorClient( BehaveConfig.getIntegration_AuthenticatorPort(), BehaveConfig.getIntegration_AuthenticatorHost()); autenticator.open(); username = autenticator.getUser(); password = autenticator.getPassword(); autenticator.close(); } // Tenta obter dados de conexao com o ALM via hash urlServer = getHash(result, "urlServer", BehaveConfig.getIntegration_UrlServices()).trim(); urlServerAuth = getHash(result, "urlServerAuth", BehaveConfig.getIntegration_UrlSecurity()).trim(); projectAreaAlias = getHash(result, "projectAreaAlias", BehaveConfig.getIntegration_ProjectArea()) .trim(); // Para evitar problemas com encodings em projetos ns sempre // fazemos o decoding e depois encoding projectAreaAlias = URLDecoder.decode(projectAreaAlias, ENCODING); // Encode do Alias do Projeto projectAreaAlias = URLEncoder.encode(projectAreaAlias, ENCODING); // ID fixo de caso de teste boolean testCaseIdMeta = false; if (result.containsKey("testCaseId")) { testCaseId = Integer.parseInt((String) result.get("testCaseId")); testCaseIdMeta = true; } else { testCaseId = null; } log.debug(message.getString("message-integration-alm-started")); long t0 = GregorianCalendar.getInstance().getTimeInMillis(); HttpClient client; String testCaseName; // Somente cria e associa o caso de teste quando ele no informado if (testCaseId == null) { String testCaseIdentification = convertToIdentificationString(result.get("name").toString()); testCaseName = "testcase" + testCaseIdentification; // --------------------------- TestCase (GET) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); // Cria um novo caso de teste Testcase testCase = new Testcase(); HttpResponse responseTestCaseGet = getRequest(client, "testcase", testCaseName); if (responseTestCaseGet.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { testCase = GenerateXMLString.getTestcaseObject(responseTestCaseGet); } // --------------------------- TestCase (PUT) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); // TestCase log.debug(message.getString("message-send-test-case")); HttpResponse responseTestCase = sendRequest(client, "testcase", testCaseName, GenerateXMLString.getTestcaseString(urlServer, projectAreaAlias, ENCODING, result.get("name").toString(), result.get("steps").toString(), testCase)); if (responseTestCase.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED && responseTestCase.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new BehaveException(message.getString("exception-create-test-case", responseTestCase.getStatusLine().toString())); } } else { testCaseName = "urn:com.ibm.rqm:testcase:" + testCaseId; } // Verifica se a auto associao esta habilitada if (BehaveConfig.getIntegration_AutoAssociateTestCaseInPlan()) { // --------------------------- Test Plan (GET) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); Testplan plan; String testPlanNameId = "urn:com.ibm.rqm:testplan:" + result.get("testPlanId").toString(); HttpResponse responseTestPlanGet = getRequest(client, "testplan", testPlanNameId); if (responseTestPlanGet.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED && responseTestPlanGet.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new BehaveException( message.getString("exception-test-plan-not-found", result.get("testPlanId").toString(), projectAreaAlias) + ". --> communication failure, status code [" + responseTestPlanGet.getStatusLine().getStatusCode() + "]"); } else { plan = GenerateXMLString.getTestPlanObject(responseTestPlanGet); } // --------------------------- Test Plan (PUT) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); // TestPlan log.debug(message.getString("message-send-test-plan")); HttpResponse responseTestPlan = sendRequest(client, "testplan", testPlanNameId, GenerateXMLString .getTestplanString(urlServer, projectAreaAlias, ENCODING, testCaseName, plan)); if (responseTestPlan.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new BehaveException(message.getString("exception-send-test-plan", responseTestPlan.getStatusLine().toString())); } } // --------------------------- Work Item (PUT) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); // WorkItem log.debug(message.getString("message-send-execution")); String workItemName = "workitemExecucaoAutomatizada-" + convertToIdentificationString(testCaseName) + "-" + result.get("testPlanId").toString(); boolean redirect = false; HttpResponse responseWorkItem = sendRequest(client, "executionworkitem", workItemName, GenerateXMLString.getExecutionworkitemString(urlServer, projectAreaAlias, ENCODING, testCaseName, result.get("testPlanId").toString())); if (responseWorkItem.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED && responseWorkItem.getStatusLine().getStatusCode() != HttpStatus.SC_OK && responseWorkItem.getStatusLine().getStatusCode() != HttpStatus.SC_SEE_OTHER) { String ms = message.getString("exception-create-execution", responseWorkItem.getStatusLine().toString()); if (testCaseIdMeta) { ms = message.getString("exception-verity-execution", testCaseId.toString(), message); } throw new BehaveException(ms); } else { Header locationHeader = responseWorkItem.getFirstHeader("Content-Location"); if (locationHeader != null) { redirect = true; workItemName = locationHeader.getValue(); } } // --------------------------- Result (PUT) // Conexo HTTPS client = HttpsClient.getNewHttpClient(ENCODING); // Login login(client); // WorkItem log.debug(message.getString("message-send-result")); String resultName = "result" + System.nanoTime(); // Tratamento da identificao do workitem String executionWorkItemUrl = urlServer + "resources/" + projectAreaAlias + "/executionworkitem/" + workItemName; if (redirect) { executionWorkItemUrl = workItemName; } HttpResponse responseResult = sendRequest(client, "executionresult", resultName, GenerateXMLString.getExecutionresultString(urlServer, projectAreaAlias, ENCODING, executionWorkItemUrl, ((ScenarioState) result.get("state")), (Date) result.get("startDate"), (Date) result.get("endDate"), (String) result.get("details"))); if (responseResult.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) { throw new BehaveException( message.getString("exception-send-result", responseResult.getStatusLine().toString())); } long t1 = GregorianCalendar.getInstance().getTimeInMillis(); DecimalFormat df = new DecimalFormat("0.0"); log.debug(message.getString("message-integration-alm-end", df.format((t1 - t0) / 1000.00))); } catch (RuntimeException e) { if (e.getCause() instanceof ConnectException) { throw new BehaveException(message.getString("exception-authenticator-inaccessible"), e); } else { throw new BehaveException(e); } } catch (Exception e) { throw new BehaveException(e); } }
From source file:ezbake.deployer.AccumuloEzDeployerStore.java
private FluentIterable<DeploymentMetadata> getApplicationMetaDataFromStoreForAllVersions(String applicationId) throws TException { try {/*from w w w . j a v a2 s . c o m*/ return getValueFromStoreIterator(new Text(applicationId), ARTIFACT_METADATA_CQ) .transform(createDeploymentMetaDataTransformer()); } catch (RuntimeException e) { if (e.getCause() instanceof DeploymentException) { throw (DeploymentException) e.getCause(); } else if (e.getCause() instanceof TException) { throw (TException) e.getCause(); } else { log.error("Error getting metadata for artifact", e); throw new DeploymentException(e.getMessage()); } } }
From source file:org.apache.bval.jsr.ApacheValidatorFactory.java
private <T> T newInstance(final Class<T> cls) { try {//from w ww.j a va 2 s . c om return Reflection.newInstance(cls); } catch (final RuntimeException e) { throw new ValidationException(e.getCause()); } }
From source file:org.broadleafcommerce.openadmin.security.CompatibleGWTSecuredRPCServiceExporter.java
/** * Wrap the original method in order to detect a Spring Security specific exception and manage it the way we want. * @param payload /* www. j a v a 2s .co m*/ * @see org.gwtwidgets.server.spring.GWTRPCServiceExporter#processCall(java.lang.String) */ @Override public String processCall(final String payload) throws SerializationException { String response = null; // reported as not working with GWT.1.6.4 : Issue 2 // final RPCRequest rpcRequest = RPC.decodeRequest(payload); final RPCRequest rpcRequest; try { rpcRequest = RPC.decodeRequest(payload, null, this); } catch (RuntimeException e) { LOGGER.error("Could not decode the request", e); throw e; } try { response = super.processCall(payload); } catch (final Throwable e) { // Security Exceptions (preciousException here) are wrapped into an UnexpectedException (cause1), which is wrapped into a RuntimeException (e)... LOGGER.error("Problem processing call", e); final Throwable cause1 = e.getCause(); if (cause1 != null && cause1 instanceof UnexpectedException) { final Throwable preciousException = cause1.getCause(); if (preciousException != null && (preciousException instanceof AccessDeniedException || preciousException instanceof AuthenticationException)) { return processException(preciousException, rpcRequest); } else if (preciousException != null && (preciousException instanceof TransactionSystemException)) { return processException( ((TransactionSystemException) preciousException).getApplicationException(), rpcRequest); } } return processException(e, rpcRequest); } if (response != null && response.startsWith("//EX")) { //BLC-604... For now lets display the raw message return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new com.gwtincubator.security.exception.AccessDeniedException(response)); } return response; }
From source file:com.cerema.cloud2.lib.common.network.AdvancedSslSocketFactory.java
/** * Verifies the identity of the server. * //from ww w . ja v a 2 s. c o m * The server certificate is verified first. * * Then, the host name is compared with the content of the server certificate using the current host name verifier, * if any. * @param socket */ private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException { try { CertificateCombinedException failInHandshake = null; /// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager /// (that should be an instance of AdvancedX509TrustManager) try { SSLSocket sock = (SSLSocket) socket; // a new SSLSession instance is created as a "side effect" sock.startHandshake(); } catch (RuntimeException e) { if (e instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) e; } else { Throwable cause = e.getCause(); Throwable previousCause = null; while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) { previousCause = cause; cause = cause.getCause(); } if (cause != null && cause instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) cause; } } if (failInHandshake == null) { throw e; } failInHandshake.setHostInUrl(host); } /// 2. VERIFY HOSTNAME SSLSession newSession = null; boolean verifiedHostname = true; if (mHostnameVerifier != null) { if (failInHandshake != null) { /// 2.1 : a new SSLSession instance was NOT created in the handshake X509Certificate serverCert = failInHandshake.getServerCertificate(); try { mHostnameVerifier.verify(host, serverCert); } catch (SSLException e) { verifiedHostname = false; } } else { /// 2.2 : a new SSLSession instance was created in the handshake newSession = ((SSLSocket) socket).getSession(); if (!mTrustManager.isKnownServer((X509Certificate) (newSession.getPeerCertificates()[0]))) { verifiedHostname = mHostnameVerifier.verify(host, newSession); } } } /// 3. Combine the exceptions to throw, if any if (!verifiedHostname) { SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException( "Names in the server certificate do not match to " + host + " in the URL"); if (failInHandshake == null) { failInHandshake = new CertificateCombinedException( (X509Certificate) newSession.getPeerCertificates()[0]); failInHandshake.setHostInUrl(host); } failInHandshake.setSslPeerUnverifiedException(pue); pue.initCause(failInHandshake); throw pue; } else if (failInHandshake != null) { SSLHandshakeException hse = new SSLHandshakeException("Server certificate could not be verified"); hse.initCause(failInHandshake); throw hse; } } catch (IOException io) { try { socket.close(); } catch (Exception x) { // NOTHING - irrelevant exception for the caller } throw io; } }
From source file:org.nuxeo.automation.scripting.test.TestScriptRunnerInfrastructure.java
@Test public void testClassFilter() throws Exception { try {//from w w w . j a v a2s .com scripting.run("classFilterScript.js", session, Void.class); } catch (RuntimeException cause) { assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); } }
From source file:org.apache.hadoop.hbase.client.crosssite.CrossSiteClientScanner.java
private Callable<ScannerIterator> createCallable( final Pair<ClusterInfo, Pair<byte[], byte[]>> clusterStartStopKeyPair, final String tableName, final boolean ignore) { return new Callable<ScannerIterator>() { @Override// w w w. j a va 2 s . c o m public ScannerIterator call() throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("Start initialization of scanner" + " for the cluster " + clusterStartStopKeyPair.getFirst()); } String clusterTableName = CrossSiteUtil.getClusterTableName(tableName, clusterStartStopKeyPair.getFirst().getName()); ScannerIterator scanIterator = null; try { try { HTableInterface table = hTableFactory.createHTableInterface( getClusterConf(configuration, clusterStartStopKeyPair.getFirst().getAddress()), Bytes.toBytes(clusterTableName)); Scan s = new Scan(scan); s.setStartRow(clusterStartStopKeyPair.getSecond().getFirst()); s.setStopRow(clusterStartStopKeyPair.getSecond().getSecond()); scanIterator = new ScannerIterator(clusterStartStopKeyPair.getFirst(), clusterStartStopKeyPair.getFirst(), table, s); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw new IOException(e); } } } catch (IOException e) { LOG.info("Fail to connect to the CSBTable " + tableName + " in cluster " + clusterStartStopKeyPair.getFirst(), e); if (failover && CrossSiteUtil.isFailoverException(e)) { LOG.warn("Start to failover to the peers for cluster " + clusterStartStopKeyPair.getFirst() + ". Please notice, the data may be stale."); // Get the peers once from the zk.. this would be helpful when a new peer is added // after a CrossSiteHTable instance has been created List<ClusterInfo> peerClusters = null; try { peerClusters = znodes.getPeerClusters(clusterStartStopKeyPair.getFirst().getName()); } catch (KeeperException ke) { LOG.warn("Fail to connect the global zookeeper", ke); } if (peerClusters != null) { for (ClusterInfo peerCluster : peerClusters) { LOG.info("Starting to failover to the peer cluster" + peerCluster + " for the cluster " + clusterStartStopKeyPair.getFirst()); Configuration conf = getClusterConf(configuration, peerCluster.getAddress()); try { String peerClusterTableName = CrossSiteUtil.getPeerClusterTableName(tableName, clusterStartStopKeyPair.getFirst().getName(), peerCluster.getName()); try { HTableInterface table = hTableFactory.createHTableInterface(conf, Bytes.toBytes(peerClusterTableName)); Scan s = new Scan(scan); s.setStartRow(clusterStartStopKeyPair.getSecond().getFirst()); s.setStopRow(clusterStartStopKeyPair.getSecond().getSecond()); scanIterator = new ScannerIterator(clusterStartStopKeyPair.getFirst(), peerCluster, table, s); } catch (RuntimeException re) { if (re.getCause() instanceof IOException) { throw (IOException) re.getCause(); } else { throw new IOException(re); } } LOG.info("Failover to the cluster " + peerCluster + ". Please notice, the data may be stale."); break; } catch (IOException ioe) { LOG.warn("Fail to connect to peer cluster '" + peerCluster + "'. Will try other peers", ioe); } } } } else { if (ignore) { LOG.warn("The scanner for the cluster " + clusterStartStopKeyPair.getFirst() + " will be ignored"); return null; } else { throw new IOException("Failed to initialize CSBTable '" + tableName + "' in cluster " + clusterStartStopKeyPair.getFirst()); } } } if (scanIterator == null) { if (!ignore) { throw new IOException( "Failed to initialize CSBTable '" + tableName + "' in main and peer clusters"); } else { LOG.warn("The scanner for the cluster " + clusterStartStopKeyPair.getFirst().getName() + " will be ignored"); return null; } } return scanIterator; } }; }