Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

In this page you can find the example usage for java.lang Throwable toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.example.android.cardreader.MainActivity.java

public static void register(User u) {
    usr = u;//from  ww w .j  a va2s .  co  m
    usr.checkinTime = new Date();
    new MultiThread(new Runnable() {
        @Override
        public void run() {
            SyncHttpClient client = new SyncHttpClient();
            RequestParams params = new RequestParams();
            params.put("andrewid", usr.andrewID);
            System.out.println("Posting " + usr.andrewID + " " + usr.rfid);
            params.setUseJsonStreamer(true);
            client.post(Globals.start + "/user/getid", params, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    new MultiThread(new Runnable() {
                        @Override
                        public void run() {
                            SyncHttpClient client = new SyncHttpClient();
                            RequestParams params = new RequestParams();
                            params.put("event_id", 1);
                            params.put("nfctag", usr.rfid);
                            params.setUseJsonStreamer(true);
                            client.post(Globals.start + "/event/register", params,
                                    new AsyncHttpResponseHandler() {
                                        @Override
                                        public void onSuccess(int statusCode, Header[] headers,
                                                byte[] responseBody) {
                                            String result = new String(responseBody);
                                            System.out.println("Posted res: " + result);
                                            new MultiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    SyncHttpClient client = new SyncHttpClient();
                                                    RequestParams params = new RequestParams();
                                                    params.put("nfctag", usr.rfid);
                                                    params.put("event_id", "1");
                                                    params.setUseJsonStreamer(true);
                                                    System.out.println("rfid = " + usr.rfid);
                                                    client.post(Globals.start + "/event/checkin", params,
                                                            new AsyncHttpResponseHandler() {
                                                                @Override
                                                                public void onSuccess(int statusCode,
                                                                        Header[] headers, byte[] responseBody) {
                                                                    String result = new String(responseBody);
                                                                    System.out.println("Posted res: " + result);
                                                                }

                                                                @Override
                                                                public void onFailure(int statusCode,
                                                                        Header[] headers, byte[] responseBody,
                                                                        Throwable error) {
                                                                    System.out.println("Posted failed: "
                                                                            + error.toString());
                                                                }
                                                            });
                                                }
                                            }).executeOnExecutor(Executors.newSingleThreadExecutor());
                                        }

                                        @Override
                                        public void onFailure(int statusCode, Header[] headers,
                                                byte[] responseBody, Throwable error) {
                                            System.out.println("Posted failed: " + error.toString());
                                        }
                                    });
                        }
                    }).executeOnExecutor(Executors.newSingleThreadExecutor());
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                    new MultiThread(new Runnable() {
                        @Override
                        public void run() {
                            SyncHttpClient client = new SyncHttpClient();
                            RequestParams params = new RequestParams();
                            params.put("password", "asbjdbajhscbjabshd");
                            params.put("andrewid", usr.andrewID);
                            params.put("nfctag", usr.rfid);
                            System.out.println("Posted " + usr.andrewID + " " + usr.rfid);
                            params.setUseJsonStreamer(true);
                            client.post(Globals.start + "/user/signup", params, new AsyncHttpResponseHandler() {
                                @Override
                                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                                    String result = new String(responseBody);
                                    System.out.println("Posted res1: " + result);

                                    new MultiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            SyncHttpClient client = new SyncHttpClient();
                                            RequestParams params = new RequestParams();
                                            params.put("event_id", 1);
                                            params.put("nfctag", usr.rfid);
                                            params.setUseJsonStreamer(true);
                                            client.post(Globals.start + "/event/register", params,
                                                    new AsyncHttpResponseHandler() {
                                                        @Override
                                                        public void onSuccess(int statusCode, Header[] headers,
                                                                byte[] responseBody) {
                                                            String result = new String(responseBody);
                                                            System.out.println("Posted res: " + result);
                                                            new MultiThread(new Runnable() {
                                                                @Override
                                                                public void run() {
                                                                    SyncHttpClient client = new SyncHttpClient();
                                                                    RequestParams params = new RequestParams();
                                                                    params.put("nfctag", usr.rfid);
                                                                    params.put("event_id", "1");
                                                                    params.setUseJsonStreamer(true);
                                                                    System.out.println("rfid = " + usr.rfid);
                                                                    client.post(
                                                                            Globals.start + "/event/checkin",
                                                                            params,
                                                                            new AsyncHttpResponseHandler() {
                                                                                @Override
                                                                                public void onSuccess(
                                                                                        int statusCode,
                                                                                        Header[] headers,
                                                                                        byte[] responseBody) {
                                                                                    String result = new String(
                                                                                            responseBody);
                                                                                    System.out.println(
                                                                                            "Posted res: "
                                                                                                    + result);
                                                                                }

                                                                                @Override
                                                                                public void onFailure(
                                                                                        int statusCode,
                                                                                        Header[] headers,
                                                                                        byte[] responseBody,
                                                                                        Throwable error) {
                                                                                    System.out.println(
                                                                                            "Posted failed: "
                                                                                                    + error.toString());
                                                                                }
                                                                            });
                                                                }
                                                            }).executeOnExecutor(
                                                                    Executors.newSingleThreadExecutor());
                                                        }

                                                        @Override
                                                        public void onFailure(int statusCode, Header[] headers,
                                                                byte[] responseBody, Throwable error) {
                                                            System.out.println(
                                                                    "Posted failed: " + error.toString());
                                                        }
                                                    });
                                        }
                                    }).executeOnExecutor(Executors.newSingleThreadExecutor());
                                }

                                @Override
                                public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
                                        Throwable error) {
                                    System.out.println("Posted failed1: " + error.toString());
                                    System.out.println("Posted code = " + statusCode);
                                    System.out.println("Posted 1 headers = " + headers[0] + " " + headers[1]
                                            + " " + headers[2]);
                                }
                            });
                        }
                    }).executeOnExecutor(Executors.newSingleThreadExecutor());
                }
            });
        }
    }).executeOnExecutor(Executors.newSingleThreadExecutor());
}

From source file:com.ning.billing.analytics.dao.TestAnalyticsDao.java

private void setupBusinessAccount() {
    final List<String> tags = new ArrayList<String>();
    tags.add("batch1");
    tags.add("great,guy");
    account = new BusinessAccount(ACCOUNT_KEY, BigDecimal.ONE, tags, new DateTime(DateTimeZone.UTC),
            BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "FRANCE");

    final IDBI dbi = helper.getDBI();
    businessAccountDao = dbi.onDemand(BusinessAccountDao.class);

    // Healthcheck test to make sure MySQL is setup properly
    try {//from  ww  w .j  a v a  2 s.  c  o m
        businessAccountDao.test();
    } catch (Throwable t) {
        Assert.fail(t.toString());
    }
}

From source file:eionet.gdem.conversion.converters.ConvertStrategy.java

/**
 * Method transforms XML source using XSL stream.
 * @param in InputStream containing source XML.
 * @param xslStream InputStream containing XSL content.
 * @param out OutputStream for conversion result.
 * @throws GDEMException In case of unexpected XML or XSL errors.
 *///w  ww . ja  v  a  2 s.c  om
protected void runXslTransformation(InputStream in, InputStream xslStream, OutputStream out)
        throws GDEMException {
    try {
        TransformerFactory tFactory = transform.getTransformerFactoryInstance();
        TransformerErrorListener errors = new TransformerErrorListener();
        tFactory.setErrorListener(errors);

        StreamSource transformerSource = new StreamSource(xslStream);
        if (getXslPath() != null) {
            transformerSource.setSystemId(getXslPath());
        }

        Transformer transformer = tFactory.newTransformer(transformerSource);
        transformer.setErrorListener(errors);

        transformer.setParameter(DD_DOMAIN_PARAM, Properties.ddURL);
        setTransformerParameters(transformer);
        long l = System.currentTimeMillis();
        transformer.transform(new StreamSource(in), new StreamResult(out));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug((new StringBuilder()).append("generate: transformation needed ")
                    .append(System.currentTimeMillis() - l).append(" ms").toString());
        }
    } catch (TransformerConfigurationException tce) {
        throw new GDEMException("Error transforming XML - incorrect stylesheet file: " + tce.toString(), tce);
    } catch (TransformerException tfe) {
        throw new GDEMException(
                "Error transforming XML - it's not probably well-formed xml file: " + tfe.toString(), tfe);
    } catch (Throwable th) {
        LOGGER.error("Error " + th.toString(), th);
        th.printStackTrace(System.out);
        throw new GDEMException("Error transforming XML: " + th.toString());
    }
}

From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.wizards.migration.ModelMigrationWizard.java

@Override
public boolean performFinish() {
    System.out.println("ModelMigrationWizard.performFinish()");
    final GeneralProjectMigration page = (GeneralProjectMigration) getContainer().getCurrentPage();
    final String libraryId = page.getFieldValueString(GeneralProjectMigration.Fields.library.toString());
    // import library if project do not exists in workspace

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                execute(page, libraryId, monitor);
            } catch (Exception e) {

                throw new InvocationTargetException(e);
            }/*from  www. ja  v  a2 s. c om*/
        }
    };

    try {
        this.getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        Activator.getDefault().getLog()
                .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, cause.toString(), cause));
        MessageDialog.openError(getShell(), "Error", NLS.bind("Internal error {0}", cause.getMessage())); //$NON-NLS-1$
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;
}

From source file:eionet.gdem.conversion.converters.ConvertStrategy.java

/**
 * Method transforms XML source to PDF using XSL-FO stream.
 * @param in InputStream containing source XML.
 * @param xsl InputStream containing XSL-FO content.
 * @param out OutputStream for conversion result.
 * @throws GDEMException In case of unexpected XML or XSL errors.
 *///from   ww w  . ja v  a2  s  .com
protected void runFOPTransformation(InputStream in, InputStream xsl, OutputStream out) throws GDEMException {
    try {
        Driver driver = new Driver();
        driver.setRenderer(Driver.RENDER_PDF);
        driver.setOutputStream(out);
        Result res = new SAXResult(driver.getContentHandler());
        Source src = new StreamSource(in);
        TransformerFactory transformerFactory = transform.getTransformerFactoryInstance();
        TransformerErrorListener errors = new TransformerErrorListener();

        transformerFactory.setErrorListener(errors);
        StreamSource transformerSource = new StreamSource(xsl);
        if (getXslPath() != null) {
            transformerSource.setSystemId(getXslPath());
        }

        Transformer transformer = transformerFactory.newTransformer(transformerSource);
        setTransformerParameters(transformer);
        transformer.setErrorListener(errors);

        long l = System.currentTimeMillis();
        transformer.transform(src, res);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug((new StringBuilder()).append("generate: transformation needed ")
                    .append(System.currentTimeMillis() - l).append(" ms").toString());
        }

    } catch (TransformerConfigurationException tce) {
        throw new GDEMException("Error transforming XML to PDF - incorrect stylesheet file: " + tce.toString(),
                tce);
    } catch (TransformerException tfe) {
        throw new GDEMException(
                "Error transforming XML to PDF - it's not probably well-formed xml file: " + tfe.toString(),
                tfe);
    } catch (Throwable e) {
        LOGGER.error("Error " + e.toString(), e);
        throw new GDEMException("Error transforming XML to PDF " + e.toString());
    }
}

From source file:com.quinsoft.zeidon.ZeidonException.java

/**
 * This is private because we expect outside code to wrap exceptions using wrapException or addMessage.
 *
 * @param t//from w  w w  . ja  v a 2  s .c om
 * @param message
 */
private ZeidonException(Throwable t, String message) {
    super(message, t);
    this.message = t.toString();
    runHandler();
}

From source file:com.digitalpebble.stormcrawler.protocol.HttpRobotRulesParser.java

/**
 * Get the rules from robots.txt which applies for the given {@code url}.
 * Robot rules are cached for a unique combination of host, protocol, and
 * port. If no rules are found in the cache, a HTTP request is send to fetch
 * {{protocol://host:port/robots.txt}}. The robots.txt is then parsed and
 * the rules are cached to avoid re-fetching and re-parsing it again.
 * /*from  w  w  w .j a  v  a2  s  . c o  m*/
 * @param http
 *            The {@link Protocol} object
 * @param url
 *            URL robots.txt applies to
 * 
 * @return {@link BaseRobotRules} holding the rules from robots.txt
 */
@Override
public BaseRobotRules getRobotRulesSet(Protocol http, URL url) {

    String cacheKey = getCacheKey(url);

    // check in the error cache first
    BaseRobotRules robotRules = ERRORCACHE.getIfPresent(cacheKey);
    if (robotRules != null) {
        return robotRules;
    }

    // now try the proper cache
    robotRules = CACHE.getIfPresent(cacheKey);
    if (robotRules != null) {
        return robotRules;
    }

    boolean cacheRule = true;
    URL redir = null;
    LOG.debug("Cache miss {} for {}", cacheKey, url);
    try {
        ProtocolResponse response = http.getProtocolOutput(new URL(url, "/robots.txt").toString(),
                Metadata.empty);

        // try one level of redirection ?
        if (response.getStatusCode() == 301 || response.getStatusCode() == 302) {
            String redirection = response.getMetadata().getFirstValue(HttpHeaders.LOCATION);
            if (StringUtils.isNotBlank(redirection)) {
                if (!redirection.startsWith("http")) {
                    // RFC says it should be absolute, but apparently it
                    // isn't
                    redir = new URL(url, redirection);
                } else {
                    redir = new URL(redirection);
                }
                response = http.getProtocolOutput(redir.toString(), Metadata.empty);
            }
        }

        if (response.getStatusCode() == 200) // found rules: parse them
        {
            String ct = response.getMetadata().getFirstValue(HttpHeaders.CONTENT_TYPE);
            robotRules = parseRules(url.toString(), response.getContent(), ct, agentNames);
        } else if ((response.getStatusCode() == 403) && (!allowForbidden)) {
            robotRules = FORBID_ALL_RULES; // use forbid all
        } else if (response.getStatusCode() >= 500) {
            cacheRule = false;
            robotRules = EMPTY_RULES;
        } else
            robotRules = EMPTY_RULES; // use default rules
    } catch (Throwable t) {
        LOG.info("Couldn't get robots.txt for {} : {}", url, t.toString());
        cacheRule = false;
        robotRules = EMPTY_RULES;
    }

    if (cacheRule) {
        LOG.debug("Caching robots for {} under key {}", url, cacheKey);
        CACHE.put(cacheKey, robotRules); // cache rules for host
        if (redir != null && !redir.getHost().equalsIgnoreCase(url.getHost())) {
            // cache also for the redirected host
            String keyredir = getCacheKey(redir);
            LOG.debug("Caching robots for {} under key {}", redir, keyredir);
            CACHE.put(keyredir, robotRules);
        }
    } else {
        LOG.debug("Error Caching robots for {} under key {}", url, cacheKey);
        ERRORCACHE.put(cacheKey, robotRules); // cache rules for host
        if (redir != null && !redir.getHost().equalsIgnoreCase(url.getHost())) {
            // cache also for the redirected host
            String keyredir = getCacheKey(redir);
            LOG.debug("Error Caching robots for {} under key {}", redir, keyredir);
            ERRORCACHE.put(keyredir, robotRules);
        }
    }

    return robotRules;
}

From source file:com.ning.billing.analytics.dao.TestAnalyticsDao.java

private void setupBusinessSubscriptionTransition() {
    final BusinessSubscription prevSubscription = new BusinessSubscription(null, plan, phase, Currency.USD,
            new DateTime(DateTimeZone.UTC), Subscription.SubscriptionState.ACTIVE, UUID.randomUUID(),
            UUID.randomUUID());//w  w w  .  j  a va 2 s  .  c o  m
    final BusinessSubscription nextSubscription = new BusinessSubscription(null, plan, phase, Currency.USD,
            new DateTime(DateTimeZone.UTC), Subscription.SubscriptionState.CANCELLED, UUID.randomUUID(),
            UUID.randomUUID());
    final BusinessSubscriptionEvent event = BusinessSubscriptionEvent.subscriptionCancelled(plan);
    final DateTime requestedTimestamp = new DateTime(DateTimeZone.UTC);

    transition = new BusinessSubscriptionTransition(EVENT_KEY, ACCOUNT_KEY, requestedTimestamp, event,
            prevSubscription, nextSubscription);

    final IDBI dbi = helper.getDBI();
    businessSubscriptionTransitionDao = dbi.onDemand(BusinessSubscriptionTransitionDao.class);

    // Healthcheck test to make sure MySQL is setup properly
    try {
        businessSubscriptionTransitionDao.test();
    } catch (Throwable t) {
        Assert.fail(t.toString());
    }
}

From source file:furkan.app.tictactoewebsocket.TicTacToeServer.java

private void handleException(Throwable t, Game game) {
    t.printStackTrace();//from   w ww.j av  a2s  . com
    String message = t.toString();
    try {
        game.player1.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, message));
    } catch (IOException ignore) {
    }
    try {
        game.player2.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, message));
    } catch (IOException ignore) {
    }
}

From source file:org.j4me.collections.CubbyHole.java

/**
     * Tests that a consumer thread blocks waiting for a producer to add
     * something to the cubby hole.// ww w .  j av  a2s  . c  o  m
     */
    public void testBlocking() {
        final CubbyHole one = new CubbyHole();
        final CubbyHole two = new CubbyHole();

        class Consumer extends Thread {
            public void run() {
                try {
                    // Block waiting for something in the first cubby hole.
                    Object consume = one.get();

                    // The producer thread should be blocking waiting for
                    // this thread to put something into the second cubby hole.
                    two.set(consume);
                } catch (Throwable t) {
                    fail(t.toString());
                }
            }
        }

        try {
            // Create a consumer thread.
            Consumer consumer = new Consumer();
            consumer.start();

            // Give up the CPU to let the consumer start and block.
            Thread.sleep(0);

            // Put some data into the first cubby hole to unblock the consumer.
            Integer data = new Integer(13);
            one.set(data);

            // Get data from the second cubby hole.  This thread will block
            // until the consumer puts something into it.
            Integer result = (Integer) two.get();

            // Verify the consumer thread read our original data from the
            // first cubby hole and put it into the second.
            assertSame("Data integrety verified.", data, result);
        } catch (InterruptedException e) {
            fail(e.toString());
        }
    }