Example usage for java.lang Exception initCause

List of usage examples for java.lang Exception initCause

Introduction

In this page you can find the example usage for java.lang Exception initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:inflor.core.transforms.LogicleTransform.java

@Override
public void optimize(double[] rawData) {
    double newt = new Percentile().evaluate(rawData, LOGICLE_T_PERCENTILE);
    double neww = optimizeW(rawData);
    //TODO A and M.
    try {/*w ww.j a v  a 2  s.c o m*/
        this.logicle = new FastLogicle(newt, neww, logicle.M, logicle.A);
    } catch (Exception e) {
        //Ideally we catch this before hand but for now:
        Exception e2 = new RuntimeException("bad input parameters: T [1] w [2], M [3], A [4]"
                .replace("[1]", Double.toString(logicle.T)).replace("[2]", Double.toString(logicle.w))
                .replace("[3]", Double.toString(logicle.M)).replace("[4]", Double.toString(logicle.A)));
        e2.initCause(e);
    }
}

From source file:org.wso2.carbon.bpel.core.ode.integration.BPELProcessProxy.java

private void rollbackTransactionForTheResponsePath(final Exception cachedException) throws BPELFault {
    try {/*from w w w . j a v a 2s .c  om*/
        transactionManager.rollback();
    } catch (Exception e) {
        e.initCause(cachedException);
        throw new BPELFault("Rollback failed!", e);
    }
}

From source file:org.wso2.carbon.bpel.core.ode.integration.BPELProcessProxy.java

public final void releaseODEMessageExchangeAndRollbackTransaction(
        final MyRoleMessageExchange odeMessageExchange, final Exception cachedException,
        final boolean isProcessInvokeSuccess) throws BPELFault {
    try {/*from   www .  ja  va2  s.co m*/
        if (odeMessageExchange != null) {
            odeMessageExchange.release(isProcessInvokeSuccess);
        }
    } finally {
        try {
            transactionManager.rollback();
        } catch (Exception e) {
            e.initCause(cachedException);
            throw new BPELFault("Rollback failed", e);
        }
    }
}

From source file:io.takari.maven.testing.executor.junit.MavenVersionResolver.java

private void createMavenInstallation(List<Repository> repositories, String version, File localrepo,
        File targetdir) throws Exception {
    String versionDir = "org/apache/maven/apache-maven/" + version + "/";
    String filename = "apache-maven-" + version + "-bin.tar.gz";
    File archive = new File(localrepo, versionDir + filename);
    if (archive.canRead()) {
        unarchive(archive, targetdir);/*w w w.  j a v  a 2 s.c o  m*/
        return;
    }
    Exception cause = null;
    for (Repository repository : repositories) {
        setHttpCredentials(repository.credentials);
        String effectiveVersion;
        if (isSnapshot(version)) {
            try {
                effectiveVersion = getQualifiedVersion(repository.url, versionDir);
            } catch (FileNotFoundException e) {
                continue;
            } catch (IOException e) {
                cause = e;
                continue;
            }
            if (effectiveVersion == null) {
                continue;
            }
        } else {
            effectiveVersion = version;
        }
        filename = "apache-maven-" + effectiveVersion + "-bin.tar.gz";
        archive = new File(localrepo, versionDir + filename);
        if (archive.canRead()) {
            unarchive(archive, targetdir);
            return;
        }
        URL resource = new URL(repository.url, versionDir + filename);
        try (InputStream is = openStream(resource)) {
            archive.getParentFile().mkdirs();
            File tmpfile = File.createTempFile(filename, ".tmp", archive.getParentFile());
            try {
                copy(is, tmpfile);
                unarchive(tmpfile, targetdir);
                Files.move(tmpfile.toPath(), archive.toPath(), StandardCopyOption.ATOMIC_MOVE,
                        StandardCopyOption.REPLACE_EXISTING);
            } finally {
                tmpfile.delete();
            }
            return;
        } catch (FileNotFoundException e) {
            // ignore the exception. this is expected to happen quite often and not a failure by iteself
        } catch (IOException e) {
            cause = e;
        }
    }
    Exception exception = new FileNotFoundException(
            "Could not download maven version " + version + " from any configured repository");
    exception.initCause(cause);
    throw exception;
}

From source file:org.wso2.carbon.bpel.core.ode.integration.BPELProcessProxy.java

private void commitTransactionForTheResponsePath(final Exception cachedException) throws BPELFault {
    try {//  w  w  w. j a va2 s  .co  m
        if (log.isDebugEnabled()) {
            log.debug("Comitting transaction.");
        }
        transactionManager.commit();
    } catch (Exception e) {
        String errorMessage = "Commiting Response Path Transaction Failed.";
        e.initCause(cachedException);
        log.error(errorMessage, e);
        throw new BPELFault(errorMessage, e);
    }
}

From source file:org.eclipse.mylyn.internal.commons.net.PollingSslProtocolSocketFactory.java

public synchronized SSLSocketFactory getSocketFactory() throws IOException {
    if (socketFactory == null) {
        if (keyStoreFileName != null && keyStorePassword != null) {
            KeyManager[] keymanagers = null;
            try {
                if (keyStoreType == null) {
                    try {
                        keymanagers = openKeyStore(KeyStore.getDefaultType());
                    } catch (Exception e) {
                        keymanagers = openKeyStore("pkcs12"); //$NON-NLS-1$
                    }//from www . j  av  a2 s .com
                } else {
                    keymanagers = openKeyStore(keyStoreType);
                }
            } catch (Exception cause) {
                IOException e = new SslCertificateException();
                e.initCause(cause);
                throw e;
            }

            try {
                SSLContext sslContext = SSLContext.getInstance("SSL"); //$NON-NLS-1$
                sslContext.init(keymanagers, new TrustManager[] { new TrustAllTrustManager() }, null);
                this.socketFactory = sslContext.getSocketFactory();
            } catch (Exception cause) {
                IOException e = new SslCertificateException();
                e.initCause(cause);
                throw e;
            }
        }
        throw new IOException("Could not initialize SSL context"); //$NON-NLS-1$
    }
    return socketFactory;
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

public void dispatchCommand(String interfaceName, String methodName, JSCommand command, JSONObject args,
        boolean subscribe) {
    Method method = getMethod(interfaceName, methodName);

    if (method != null) {
        try {/*from w  ww .  ja v  a2 s .  com*/
            Object returnValue = method.invoke(this, command, args);

            if (returnValue != null && returnValue instanceof ServiceSubscription) {
                command.serviceSubscription = (ServiceSubscription<?>) returnValue;
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            Exception wrappedException = new DispatcherException(
                    "Exception calling " + methodName + ": " + cause.toString());
            wrappedException.initCause(cause);

            wrappedException.printStackTrace();
            command.error(wrappedException);
        } catch (Exception e) {
            e.printStackTrace();
            command.error(e);
        }
    } else {
        Log.d("ConnectSDKCordova", "Method not implemented: " + interfaceName + "." + methodName);
        command.error("method not implemented");
    }
}

From source file:mp.platform.cyclone.webservices.payments.PaymentWebServiceImpl.java

public RequestPaymentResult requestPaymentConfirmation(final RequestPaymentParameters params) {
    Exception errorException = null;
    PaymentRequestStatus status = null;//  w  w w .  ja va 2 s .co m
    // Get the to member
    Member toMember = null;
    final Member restricted = WebServiceContext.getMember();
    if (restricted != null) {
        // When restricted to a member, he is always the to
        toMember = restricted;
    } else {
        try {
            toMember = paymentHelper.resolveToMember(params);
        } catch (final EntityNotFoundException e) {
            status = PaymentRequestStatus.TO_NOT_FOUND;
        }
        // When not restricted to a member, check the channel access of the payment receiver
        if (status == null && !memberHelper.isChannelEnabledForMember(toMember)) {
            status = PaymentRequestStatus.TO_INVALID_CHANNEL;
        }
    }
    // Get the from member
    Member fromMember = null;
    if (status == null) {
        try {
            fromMember = paymentHelper.resolveFromMember(params);
        } catch (final EntityNotFoundException e) {
            status = PaymentRequestStatus.FROM_NOT_FOUND;
        }
    }

    // Generate the ticket if no error so far
    PaymentRequestTicket ticket = null;
    if (status == null) {
        try {
            ticket = paymentHelper.toTicket(params, null);
            ticket.setFrom(fromMember);
            ticket.setTo(toMember);
            ticket = ticketService.generate(ticket);
            status = PaymentRequestStatus.REQUEST_RECEIVED;
        } catch (final InvalidChannelException e) {
            status = PaymentRequestStatus.FROM_INVALID_CHANNEL;
        } catch (final Exception e) {
            errorException = e;
            final PaymentStatus paymentStatus = paymentHelper.toStatus(e);
            try {
                // Probably it's a payment status also present on payment request status
                status = PaymentRequestStatus.valueOf(paymentStatus.name());
            } catch (final Exception e1) {
                e1.initCause(e);
                errorException = e1;
                status = PaymentRequestStatus.UNKNOWN_ERROR;
            }
        }
    }

    if (!status.isSuccessful()) {
        webServiceHelper.error(errorException != null ? errorException
                : new Exception("Request payment confirmation status: " + status));
    }

    // Build a result
    final RequestPaymentResult result = new RequestPaymentResult();
    result.setStatus(status);
    if (ticket != null) {
        result.setTicket(ticket.getTicket());
    }
    return result;
}

From source file:org.wso2.carbon.bpel.core.ode.integration.store.repository.BPELPackageRepository.java

/**
 * Handles exception and rollbacks an already started transaction. Don't use this method if
 * you haven't already started a registry transaction
 *
 * @param msg - Message to log/*from   w  w  w.  j a v  a  2 s.c o  m*/
 * @param e   - original exception
 * @throws RegistryException on registry rollback error case, we'll init the cause to the
 *                           original exception we got when accessing registry
 */
protected void handleExceptionWithRollback(String msg, Exception e) throws Exception {
    Exception cachedException = null;
    log.error(msg, e);
    try {
        configRegistry.rollbackTransaction();
    } catch (RegistryException re) {
        cachedException = re;
        log.error("Transaction rollback failed", re);
    }

    if (cachedException != null) {
        cachedException.initCause(e);
        throw cachedException;
    } else {
        throw e;
    }
}

From source file:nl.strohalm.cyclos.webservices.payments.PaymentWebServiceImpl.java

@Override
public RequestPaymentResult requestPaymentConfirmation(final RequestPaymentParameters params) {
    Exception errorException = null;
    PaymentRequestStatus status = null;/*w w w. j a  v  a2s .c o m*/
    // Get the to member
    Member toMember = null;
    final Member restricted = WebServiceContext.getMember();
    if (restricted != null) {
        // When restricted to a member, he is always the to
        toMember = restricted;
    } else {
        try {
            toMember = paymentHelper.resolveToMember(params);
        } catch (final EntityNotFoundException e) {
            status = PaymentRequestStatus.TO_NOT_FOUND;
        }
        // When not restricted to a member, check the channel access of the payment receiver
        if (status == null && !memberHelper.isChannelEnabledForMember(toMember)) {
            status = PaymentRequestStatus.TO_INVALID_CHANNEL;
        }
    }
    // Get the from member
    Member fromMember = null;
    if (status == null) {
        try {
            fromMember = paymentHelper.resolveFromMember(params);
        } catch (final EntityNotFoundException e) {
            status = PaymentRequestStatus.FROM_NOT_FOUND;
        }
    }

    // Generate the ticket if no error so far
    PaymentRequestTicket ticket = null;
    if (status == null) {
        try {
            ticket = paymentHelper.toTicket(params, null);
            ticket.setFrom(fromMember);
            ticket.setTo(toMember);
            ticket = ticketServiceLocal.generate(ticket);
            status = PaymentRequestStatus.REQUEST_RECEIVED;
        } catch (final InvalidChannelException e) {
            status = PaymentRequestStatus.FROM_INVALID_CHANNEL;
        } catch (final Exception e) {
            errorException = e;
            final PaymentStatus paymentStatus = paymentHelper.toStatus(e);
            try {
                // Probably it's a payment status also present on payment request status
                status = PaymentRequestStatus.valueOf(paymentStatus.name());
            } catch (final Exception e1) {
                e1.initCause(e);
                errorException = e1;
                status = PaymentRequestStatus.UNKNOWN_ERROR;
            }
        }
    }

    if (!status.isSuccessful()) {
        if (errorException != null) {
            webServiceHelper.error(errorException);
        } else {
            webServiceHelper.error("Request payment confirmation status: " + status);
        }
    }

    // Build a result
    final RequestPaymentResult result = new RequestPaymentResult();
    result.setStatus(status);
    if (ticket != null) {
        result.setTicket(ticket.getTicket());
    }
    return result;
}