Example usage for java.lang.reflect UndeclaredThrowableException getCause

List of usage examples for java.lang.reflect UndeclaredThrowableException getCause

Introduction

In this page you can find the example usage for java.lang.reflect UndeclaredThrowableException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.olingo.ext.proxy.commons.AbstractInvocationHandler.java

protected Object invokeSelfMethod(final Method method, final Object[] args) throws Throwable {
    //Try as per https://amitstechblog.wordpress.com/2011/07/24/java-proxies-and-undeclaredthrowableexception/
    try {//from   w w  w.  j a v a  2  s.c o m
        return getClass().getMethod(method.getName(), method.getParameterTypes()).invoke(this, args);
    } catch (UndeclaredThrowableException e) {
        throw e.getCause();
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    }
}

From source file:org.jclouds.atmosonline.saas.AtmosStorageClientLiveTest.java

@Test(timeOut = 5 * 60 * 1000)
public void testCreateDirectory() throws Exception {
    boolean created = false;
    while (!created) {
        privateDirectory = containerPrefix + new SecureRandom().nextInt();
        try {//  w  ww  .j a v  a2  s . c o m
            created = connection.createDirectory(privateDirectory) != null;
        } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
                continue;
            throw e;
        }
    }
    BoundedSortedSet<? extends DirectoryEntry> response = connection.listDirectories();
    for (DirectoryEntry id : response) {
        BoundedSortedSet<? extends DirectoryEntry> r2 = connection.listDirectory(id.getObjectName());
        assert r2 != null;
    }
}

From source file:org.jclouds.azure.storage.blob.AzureBlobClientLiveTest.java

@Test(timeOut = 5 * 60 * 1000)
public void testCreateContainer() throws Exception {
    boolean created = false;
    while (!created) {
        privateContainer = containerPrefix + new SecureRandom().nextInt();
        try {/*from   ww w  . jav a  2  s . c om*/
            created = connection.createContainer(privateContainer,
                    CreateContainerOptions.Builder.withMetadata(ImmutableMultimap.of("foo", "bar")));
        } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
                continue;
            throw e;
        }
    }
    SortedSet<ListableContainerProperties> response = connection.listContainers();
    assert null != response;
    long containerCount = response.size();
    assertTrue(containerCount >= 1);
    ListBlobsResponse list = connection.listBlobs(privateContainer);
    assertEquals(list.getUrl(),
            URI.create(String.format("https://%s.blob.core.windows.net/%s", account, privateContainer)));
    // TODO ... check to see the container actually exists
}

From source file:org.jclouds.azure.storage.blob.AzureBlobClientLiveTest.java

@Test(timeOut = 5 * 60 * 1000)
public void testCreatePublicContainer() throws Exception {
    boolean created = false;
    while (!created) {
        publicContainer = containerPrefix + new SecureRandom().nextInt();
        try {//from   w ww  .j a  v a 2s.c  o  m
            created = connection.createContainer(publicContainer,
                    CreateContainerOptions.Builder.withPublicAcl());
        } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
                continue;
            throw e;
        }
    }

    URL url = new URL(String.format("http://%s.blob.core.windows.net/%s", account, publicContainer));
    Utils.toStringAndClose(url.openStream());
}

From source file:org.lilyproject.repository.impl.RemoteTypeManager.java

private RuntimeException handleUndeclaredTypeThrowable(UndeclaredThrowableException e) throws TypeException {
    if (e.getCause() instanceof IOException) {
        throw new IOTypeException(e.getCause());
    } else {/*from  ww w.j a v  a2  s  .  com*/
        throw e;
    }
}

From source file:org.opennms.netmgt.syslogd.Nms4335Test.java

private void startSyslogdGracefully() {
    try {/*w  w w .  j a va 2 s  . c  o m*/
        m_syslogd.start();
    } catch (UndeclaredThrowableException ute) {
        if (ute.getCause() instanceof BindException) {
            // continue, this was expected
        } else {
            throw ute;
        }
    }
}

From source file:org.opennms.netmgt.syslogd.SyslogdEventdLoadTest.java

private void startSyslogdGracefully() {
    ConvertToEvent.invalidate();// w  ww  . j a va2s  . c o m
    try {
        m_syslogd = new Syslogd();
        m_syslogd.init();
        m_syslogd.start();
    } catch (UndeclaredThrowableException ute) {
        if (ute.getCause() instanceof BindException) {
            LOG.warn("received a bind exception", ute);
            // continue, this was expected
        } else {
            throw ute;
        }
    }
}

From source file:org.springframework.integration.amqp.support.BoundRabbitChannelAdvice.java

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    try {//from   w ww .j a  va  2 s .co m
        return this.operations.invoke(operations -> {
            try {
                Object result = invocation.proceed();
                if (this.waitForConfirmsTimeout != null) {
                    this.operations.waitForConfirmsOrDie(this.waitForConfirmsTimeout.toMillis());
                }
                return result;
            } catch (Throwable t) { // NOSONAR - rethrown below
                ReflectionUtils.rethrowRuntimeException(t);
                return null; // not reachable - satisfy compiler
            }
        }, this.ackCallback, this.nackCallback);
    } catch (UndeclaredThrowableException ute) {
        throw ute.getCause();
    }
}

From source file:syncleus.gremlann.SomBrainTest.java

@Test
public void testEmptySOM() throws Throwable {
    try {//from www.  ja  va 2s .  c o  m
        SOM som = new SOM(graph.addVertex(), new SomExponentialDecay(10, 0.1), 3, 4);

        assertNotNull(som);

        assertEquals(4, Iterables.size(som.getInputs()));

        assertEquals(1 /* the SOM "brain" itself */ + 4 /* inputs */, Iterators.size(graph.V()));

        som.addOutput(0, 0, 0);
        som.addOutput(1, 1, 1);

        assertEquals(1 /* the SOM "brain" itself */ + 4 /* inputs */ + 2 /* outputs */,
                Iterators.size(graph.V()));

        assertEquals(2, Iterables.size(som.getOutputs()));

        Table w = som.getOutputWeights();
        assertEquals(8, w.size());

        som.input(0.75, 0.25, 0.33, 0.10);

        assertEquals(3, som.getBestMatchingUnit(true).getDimension());

        som.addOutput(0.25, 0.25, 0.25);
        assertEquals(3, Iterables.size(som.getOutputs()));
        assertEquals(12, som.getOutputWeights().size());

        som.getBestMatchingUnit(true);

        assertEquals(2, som.getIterationsTrained());
    } catch (UndeclaredThrowableException t) {
        t.printStackTrace();
        throw t.getCause();
    }

}