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:org.biopax.validator.api.AbstractAspect.java

/**
 * Registers other (external) exceptions.
 * /*from  w  ww  .j  a v  a  2 s. c  o  m*/
 * The exception class, i.e., simple name in lower case, 
 * is used as the error code, and the 'object' is to
 * find the corresponding validation result where this 
 * problem should be added.
 * 
 * This must be public method (for unclear reason, otherwise causes an AOP exception...)
 * 
 * @param t
 * @param obj model, element, or another related to the BioPAX data object
 * @param errorCode
 * @param reportedBy 
 * @param details extra message to be added at the end of the original error message if not null
 */
public void reportException(Throwable t, Object obj, String errorCode, String reportedBy, String details) {

    StringBuilder msg = new StringBuilder(t.toString());

    if (t instanceof XMLStreamException) {
        XMLStreamException ex = (XMLStreamException) t;
        msg.append("; ").append(ex.getLocation().toString());
    } else {
        if ("exception".equals(errorCode)) //catch a bug
            msg.append(" - stack:").append(getStackTrace(t)).append(" - ");
    }

    if (details != null)
        msg.append("; ").append(details);

    if (validator != null) {
        validator.report(obj, errorCode, reportedBy, false, msg.toString());
    } else {
        log.error("utils is null (not initialized?); skipping " + "an intercepted 'syntax.error': "
                + msg.toString() + " reported by: " + reportedBy);
    }
}

From source file:com.vmware.photon.controller.nsxclient.apis.DhcpServiceApiTest.java

@Test
public void testCreateDhcpRelayProfile() throws IOException, InterruptedException {
    final DhcpRelayProfile mockResponse = new DhcpRelayProfile();
    mockResponse.setId("id");
    mockResponse.setResourceType(ServiceProfileResourceType.DHCP_RELAY_PROFILE);
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_CREATED);

    DhcpServiceApi client = new DhcpServiceApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.createDhcpRelayProfile(new DhcpRelayProfileCreateSpec(),
            new com.google.common.util.concurrent.FutureCallback<DhcpRelayProfile>() {
                @Override//from w  w w.  j  a  v a 2  s.  c o  m
                public void onSuccess(DhcpRelayProfile result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();
                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.nsxclient.apis.DhcpServiceApiTest.java

@Test
public void testCreateDhcpRelayService() throws IOException, InterruptedException {
    final DhcpRelayService mockResponse = new DhcpRelayService();
    mockResponse.setId("id");
    mockResponse.setResourceType(LogicalServiceResourceType.DHCP_RELAY_SERVICE);
    setupMocks(objectMapper.writeValueAsString(mockResponse), HttpStatus.SC_CREATED);

    DhcpServiceApi client = new DhcpServiceApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);
    client.createDhcpRelayService(new DhcpRelayServiceCreateSpec(),
            new com.google.common.util.concurrent.FutureCallback<DhcpRelayService>() {
                @Override/*  ww  w  .j  a v  a  2s .  c  o  m*/
                public void onSuccess(DhcpRelayService result) {
                    assertEquals(result, mockResponse);
                    latch.countDown();
                }

                @Override
                public void onFailure(Throwable t) {
                    fail(t.toString());
                    latch.countDown();
                }
            });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:act.view.RythmTemplateException.java

@Override
public String errorMessage() {
    Throwable t = rootCauseOf(this);
    if (t instanceof RythmException) {
        return ((RythmException) t).errorDesc();
    }//from   w  ww  .  j av  a2s.  c om
    return t.toString();
}

From source file:com.knowbout.hibernate.OpenSessionInViewFilter.java

/**
 * //from   www .  j  a  v a2s  . c o  m
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HibernateUtil.openSession();
    try {
        chain.doFilter(request, response);
    } catch (ServletException se) {
        String message = se.toString();
        if (se.getRootCause() != null) {
            message = se.getRootCause().toString();
        }
        if (printFullExceptions) {
            if (se.getRootCause() != null) {
                log.error(message, se.getRootCause());
            } else {
                log.error(message, se);
            }
        } else {
            log.error(message);
        }
        throw se;
    } catch (Throwable t) {
        if (printFullExceptions) {
            log.error(t.getMessage(), t);
        } else {
            log.error(t.toString());
        }
        throw new ServletException(t);
    } finally {
        HibernateUtil.closeSession();
    }
}

From source file:com.commonsware.android.internet.WeatherDemo.java

private void updateForecast(Location loc) {
    String url = String.format(format, loc.getLatitude(), loc.getLongitude());
    HttpGet getMethod = new HttpGet(url);

    try {//from   w  w w .  j  a v a 2s  .  c o m
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(getMethod, responseHandler);

        buildForecasts(responseBody);

        String page = generatePage();

        browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8", null);
    } catch (Throwable t) {
        Toast.makeText(this, "Request failed: " + t.toString(), 4000).show();
    }
}

From source file:ThreadTester.java

public void uncaughtException(Thread t, Throwable e) {
    System.err.printf("%s: %s at line %d of %s%n", t.getName(), e.toString(),
            e.getStackTrace()[0].getLineNumber(), e.getStackTrace()[0].getFileName());
}

From source file:tasly.greathealth.erp.order.services.impl.DefaultOrderDeliveryStatusUpdateService.java

/**
 * @author vincent.yin/* www . ja va  2  s.c o m*/
 *         TS-396 :hybris/OMS??ERP?
 * @param replication_status
 */
@Override
@Transactional
public void updateOmsOrderReplicationStatus(final String orderId, final String replication_status) {

    try {

        @SuppressWarnings("deprecation")
        final List<TaslyOrderData> taslyDatas = super.getPersistenceManager()
                .search(super.getPersistenceManager().createCriteriaQuery(TaslyOrderData.class)
                        .where(Restrictions.eq(TaslyOrderData.ORDERID, orderId)));

        for (final TaslyOrderData taslyOrderData : taslyDatas) {
            taslyOrderData.setReplication_status(replication_status);
        }
    } catch (final Throwable e) {
        LOG.error(e.toString());
        throw new EntityNotFoundException("Order Id is not correct, " + orderId, e);
    }
}

From source file:com.digitalpebble.storm.crawler.protocol.http.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 va2s.  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);
    BaseRobotRules robotRules = CACHE.get(cacheKey);

    boolean cacheRule = true;

    if (robotRules == null) { // cache miss
        URL redir = null;
        LOG.trace("cache miss {}", 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) {
            CACHE.put(cacheKey, robotRules); // cache rules for host
            if (redir != null && !redir.getHost().equalsIgnoreCase(url.getHost())) {
                // cache also for the redirected host
                CACHE.put(getCacheKey(redir), robotRules);
            }
        }
    }
    return robotRules;
}

From source file:com.vmware.photon.controller.api.client.resource.ResourceTicketApiTest.java

@Test
public void testGetResourceTicketAsync() throws IOException, InterruptedException {
    final ResourceTicket resourceTicket1 = new ResourceTicket();
    resourceTicket1.setId("resourceTicket1");

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(resourceTicket1);

    setupMocks(serializedTask, HttpStatus.SC_OK);

    ResourceTicketApi resourceTicketApi = new ResourceTicketApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    resourceTicketApi.getResourceTicketAsync("foo", new FutureCallback<ResourceTicket>() {
        @Override/*from   w  w  w  .j  av a  2  s . c o m*/
        public void onSuccess(@Nullable ResourceTicket result) {
            assertEquals(result, resourceTicket1);
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
    ;
}