List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:com.rackspacecloud.blueflood.io.serializers.StringSerializerTest.java
@Test(expected = SerializationException.class) public void testSerializerForStringShouldFail() throws Throwable { try {/* w ww . j av a2s . c o m*/ NumericSerializer.serializerFor(String.class); } catch (RuntimeException re) { throw re.getCause(); } }
From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.StringSerializerTest.java
@Test(expected = UnexpectedStringSerializationException.class) public void testDeserializeStringDoesNotFail() throws Throwable { // this is what a string looked like previously. try {//from w w w .j av a2 s . co m String serialized = "AHMWVGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=="; ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(serialized.getBytes())); Serializers.serializerFor(SimpleNumber.class).fromByteBuffer(bb); } catch (RuntimeException ex) { throw ex.getCause(); } }
From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.StringSerializerTest.java
@Test(expected = SerializationException.class) public void testCannotRoundtripStringWithNullType() throws Throwable { try {//from ww w . j a v a 2s . c om String expected = "this is a string"; ByteBuffer bb = Serializers.serializerFor((Class) null).toByteBuffer(expected); String actual = (String) Serializers.serializerFor((Class) null).fromByteBuffer(bb); Assert.assertEquals(expected, actual); } catch (RuntimeException ex) { throw ex.getCause(); } }
From source file:com.rackspacecloud.blueflood.io.serializers.StringSerializerTest.java
@Test(expected = UnexpectedStringSerializationException.class) public void testStringFullSerializationShouldFail() throws Throwable { ByteArrayOutputStream baos = serializeString(TEST_STRING); ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray()); try {/*from w ww. j a v a 2 s. c o m*/ NumericSerializer.serializerFor(Object.class).fromByteBuffer(byteBuffer); } catch (RuntimeException re) { throw re.getCause(); } }
From source file:com.frank.search.solr.core.SolrExceptionTranslator.java
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex.getCause() instanceof SolrServerException) { SolrServerException solrServerException = (SolrServerException) ex.getCause(); if (solrServerException.getCause() instanceof SolrException) { SolrException solrException = (SolrException) solrServerException.getCause(); // solr 4.x moved ParseExecption from org.apache.lucene.queryParser to org.apache.lucene.queryparser.classic // therefore compare ShortClassName instead of using instanceof expression if (solrException.getCause() != null && ClassUtils.getShortName(solrException.getCause().getClass()) .equalsIgnoreCase("ParseException")) { return new InvalidDataAccessApiUsageException((solrException.getCause()).getMessage(), solrException.getCause()); } else { ErrorCode errorCode = ErrorCode.getErrorCode(solrException.code()); switch (errorCode) { case NOT_FOUND: case SERVICE_UNAVAILABLE: case SERVER_ERROR: return new DataAccessResourceFailureException(solrException.getMessage(), solrException); case FORBIDDEN: case UNAUTHORIZED: return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException); case BAD_REQUEST: return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException); case UNKNOWN: return new UncategorizedSolrException(solrException.getMessage(), solrException); default: break; }//from w w w . j a va2 s . c o m } } else if (solrServerException.getCause() instanceof ConnectException) { return new DataAccessResourceFailureException(solrServerException.getCause().getMessage(), solrServerException.getCause()); } } return null; }
From source file:org.obm.sync.push.client.SSLContextFactoryTest.java
@Test(expected = EOFException.class) public void testKeyStoreFailsIfNotPKCS12() throws Throwable { InputStream pkcs12Stream = IOUtils.toInputStream("I'm not a pkcs12 key store"); char[] pkcs12Password = "toto".toCharArray(); try {/*w w w . j a v a 2 s . c o m*/ SSLContextFactory.create(pkcs12Stream, pkcs12Password); } catch (RuntimeException e) { assertThat(e.getCause()).isNotNull(); throw e.getCause(); } }
From source file:org.zalando.jpa.validation.RollbackExceptionTranslator.java
@Override public DataAccessException translateExceptionIfPossible(final RuntimeException ex) { if (ex instanceof RollbackException) { final Throwable cause = ex.getCause(); if (cause instanceof ConstraintViolationException) { return new ReportingConstraintViolationException((ConstraintViolationException) cause); }/*from www . ja v a 2 s . c o m*/ } return null; }
From source file:com.example.app.url.shortener.service.URLShortenerService.java
String tryURLShortenOperation(Function<Urlshortener, String> operation, double rate) throws IOException { final Stopwatch stopwatch = Stopwatch.createStarted(); final Urlshortener shortener = createURLShortener(); final RateLimiter rateLimiter = RateLimiter.create(rate); IOException lastException = null; int retries = 0; while (retries++ < 5) { try {/*from ww w. ja v a2 s . c o m*/ return operation.apply(shortener); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) lastException = (IOException) e.getCause(); if (e.getCause() instanceof InterruptedIOException) { if (_logger.isDebugEnabled()) { _logger.debug("Could not shorten URL due to connection error. Retry#" + retries + ". Time spent: " + stopwatch, e); } rateLimiter.acquire(); } else throw e; } } if (lastException != null) throw lastException; else throw new IOException("Unable to shorten URL. Retried " + retries + " times for " + stopwatch); }
From source file:org.wildfly.security.tool.CredentialStoreCommandInputTest.java
@Test public void testNullValue() throws Exception { String storageLocation = getStoragePathForNewFile(); String storagePassword = "cspassword"; String[] aliasNames = { null, "testalias1", null }; String[] aliasValues = { "secretValue", null, null }; for (int i = 0; i < aliasNames.length; i++) { try {// w w w . jav a 2 s . com createStoreAndAddAliasAndCheck(storageLocation, storagePassword, aliasNames[i], aliasValues[i]); } catch (RuntimeException e) { if (!(e.getCause() instanceof NullPointerException)) { Assert.fail("It must fail with NullPointerException."); } } } }
From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcherTest.java
private void checkCause(RuntimeException e) { if (e.getCause() instanceof java.net.ConnectException) { PubMedXMLFetcherTest.log.warn("Test skipped due to connection exception"); } else if (e.getCause() instanceof java.net.UnknownHostException) { PubMedXMLFetcherTest.log.warn("Test skipped due to unknown host exception"); } else if (e.getCause() instanceof IOException && e.getMessage().contains("503")) { PubMedXMLFetcherTest.log.warn("Test skipped due to a 503 error from NCBI"); } else if (e.getCause() instanceof IOException && e.getMessage().contains("502")) { PubMedXMLFetcherTest.log.warn("Test skipped due to a 502 error from NCBI"); } else {//from w w w .j av a2 s .co m throw (e); } }