Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:io.pivotal.demo.smartgrid.frontend.timeseries.AggregateCounterTimeSeriesRepository.java

private void pingXdServer() {
    try {//  w w w.ja  va2  s.c  o m
        HttpURLConnection con = (HttpURLConnection) new URL(xdServerBaseUrl).openConnection();
        con.setRequestMethod("HEAD");

        int timeout = 2000;

        con.setReadTimeout(timeout);
        con.setConnectTimeout(timeout);

        int responseCode = con.getResponseCode();

        if (responseCode != HttpURLConnection.HTTP_OK) {
            LOG.error("Bad response from server: {} Response: {}", xdServerBaseUrl, responseCode);
        }
    } catch (Exception ex) {
        LOG.error("Could not connect to server: {} Error: {}: {}", xdServerBaseUrl,
                ex.getClass().getSimpleName(), ex.getMessage());
    }
}

From source file:dk.statsbiblioteket.doms.surveillance.fedorasurveyor.FedoraStatusService.java

/**
 * Returns the current status of Fedora. On trouble communicating with
 * Fedora, a status reporting this is generated.
 *
 * This method acts as fault barrier for communication with Fedora.
 *
 * @return A realtime status of Fedora.// w  w  w  . jav a 2  s . c o  m
 */
public Status getStatus() {
    log.trace("Enter getStatus()");
    List<StatusMessage> list = new ArrayList<StatusMessage>();
    StatusMessage statusMessage;

    try {
        statusMessage = getFedoraStatus();
    } catch (Exception e) {
        statusMessage = new StatusMessage();
        statusMessage.setMessage(
                "Unable to communicate with Fedora: " + e.getClass().getName() + ": " + e.getMessage());
        statusMessage.setSeverity(Severity.RED);
        statusMessage.setTime(System.currentTimeMillis());
        statusMessage.setLogMessage(false);
    }
    list.add(statusMessage);

    Status status = new Status();
    status.setName(APPLICATION_NAME);
    status.getMessages().addAll(list);
    return status;
}

From source file:com.zuoxiaolong.niubi.job.console.exception.DefaultHandlerExceptionResolver.java

protected void handleException(HttpServletRequest httpServletRequest, Exception exception) {
    httpServletRequest.setAttribute("message",
            "<div class=\"alert alert-error alert-block\">"
                    + " <a class=\"close\" data-dismiss=\"alert\" href=\"#\"></a>"
                    + "<h4 class=\"alert-heading\">Error!</h4>" + exception.getClass().getName() + ":"
                    + exception.getMessage() + "</div>");
}

From source file:de.upb.wdqa.wdvd.processors.decorators.JsonProcessor.java

public void logRevisionException(Exception e, Revision revision) {
    String logMessage = e.getClass().getSimpleName() + ": " + e.getMessage() + "\n" + revision.toString();

    if (VERBOSE_EXCEPTION_LOGGING) {
        logMessage += " \n" + revision.getText() + "\n" + e.toString();
    }//from   w  w w.  j  a v  a2 s .com

    logger.debug(logMessage);
}

From source file:com.mirth.connect.connectors.http.HttpMessageDispatcher.java

@Override
public boolean sendPayload(QueuedMessage message) throws Exception {
    monitoringController.updateStatus(connector, connectorType, Event.BUSY);

    try {/*from   w ww  .  j a  va 2s.  c  o  m*/
        /*
         * We need to URL decode the endpoint since a MuleEndpointURI
         * escapes special characters by default. This will allow map
         * replacements.
         * 
         * See: MIRTH-1645 & MIRTH-1917
         */
        submitHttpRequest(URLDecoder.decode(message.getEndpointUri().toString(), "utf-8"),
                message.getMessageObject());
    } catch (Exception e) {
        if (e.getClass() == ConnectException.class) {
            logger.warn("Can't connect to the queued endpoint: "
                    + channelController.getDeployedChannelById(connector.getChannelId()).getName() + " - "
                    + channelController.getDeployedDestinationName(connector.getName()) + " \r\n'"
                    + e.getMessage());
            messageObjectController.setError(message.getMessageObject(), Constants.ERROR_404,
                    "Connection refused", e, null);
            throw e;
        }

        messageObjectController.setError(message.getMessageObject(), Constants.ERROR_404,
                "Error connecting to web service.", e, null);
        alertController.sendAlerts(connector.getChannelId(), Constants.ERROR_404,
                "Error connecting to web service.", e);
        connector.handleException(new Exception(e));
    } finally {
        monitoringController.updateStatus(connector, connectorType, Event.DONE);
    }

    return true;
}

From source file:it.unitn.disi.smatch.webapi.server.controllers.AbstractController.java

@ResponseBody
@ExceptionHandler(Exception.class)
protected JSONObject handleException(Exception e) throws JSONException {
    logger.error(e.getMessage(), e);//w w  w .j av  a  2s  .  com
    return prepareErrorResponse(e.getMessage() != null ? e.getMessage() : e.getClass().getName(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

From source file:ru.org.linux.exception.ExceptionResolver.java

/**
 *   ? ?.//from  www. j a  v  a 2s. c  o m
 *  ? ??  ? .
 *
 * @param request   ?  web-
 * @param response   web-
 * @param handler  ,    ?
 * @param ex       ?
 * @return  web-
 */
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
        Object handler, Exception ex) {
    // http://stackoverflow.com/questions/8271843/how-to-exclude-clientabortexception-from-simplemappingexceptionresolver
    if (ex != null && ex.getClass().getName().endsWith(".ClientAbortException") && response.isCommitted()) {
        return null;
    }

    ModelAndView modelAndView = super.doResolveException(request, response, handler, ex);
    if (modelAndView == null) {
        modelAndView = new ModelAndView("errors/common");
        prepareModelForCommonException(modelAndView, request, ex);
    }
    modelAndView.addObject("exception", ex);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return modelAndView;
}

From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenRoute.java

@Override
public void run() {
    try {/*  ww w . j ava 2  s.  c o m*/
        /*
         * Setup time
         */
        final Boolean isAfter = routeSearch.arrival == 0;
        long travelTime = isAfter ? routeSearch.departure : routeSearch.arrival;

        /*
         * Begin building url
         */
        StringBuffer urlString = new StringBuffer(Trafikanten.getApiUrl()
                + "/ReisRest/Travel/GetTravelsAdvanced/?walkingFactor=" + WALKINGFACTOR);
        if (travelTime > 0) {
            urlString.append("&time=" + dateFormater.format(travelTime));
        }

        boolean firstInList = true;

        /*
         * Setup from stations
         */
        for (StationData station : routeSearch.fromStation) {
            if (firstInList) {
                urlString.append("&fromStops=");
                firstInList = false;
            } else {
                urlString.append(",");
            }
            urlString.append(station.stationId);
        }

        /*
         * Setup to stations
         */
        firstInList = true;
        for (StationData station : routeSearch.toStation) {
            if (firstInList) {
                urlString.append("&toStops=");
                firstInList = false;
            } else {
                urlString.append(",");
            }
            urlString.append(station.stationId);
        }

        /*
         * Setup whether or not we're arriving before or departing after
         */
        urlString.append("&isAfter=" + isAfter.toString());

        /*
         * Disable advanced options  if they are not visible
         */
        if (!routeSearch.advancedOptionsEnabled) {
            routeSearch.resetAdvancedOptions();
        }

        /*
         * Change margin/change punish/proposals
         */
        String changePunish = new Integer(routeSearch.changePunish).toString();
        String changeMargin = new Integer(routeSearch.changeMargin).toString();
        String proposals = new Integer(routeSearch.proposals).toString();
        CharSequence transportTypes = routeSearch
                .renderTransportTypesApi(routeSearch.getAPITransportArray(context));

        urlString.append("&changeMargin=" + changeMargin + "&changePunish=" + changePunish + "&proposals="
                + proposals + "&transporttypes=" + transportTypes);

        Log.i(TAG, "Searching with url " + urlString);

        final InputStream stream = HelperFunctions.executeHttpRequest(context,
                new HttpGet(urlString.toString()), false).stream;

        /*
         * Parse json
         */
        //long perfSTART = System.currentTimeMillis();
        //Log.i(TAG,"PERF : Getting route data");
        jsonParseRouteProposal(stream);
        //Log.i(TAG,"PERF : Parsing web request took " + ((System.currentTimeMillis() - perfSTART)) + "ms");
    } catch (Exception e) {
        if (e.getClass() == InterruptedException.class) {
            ThreadHandlePostExecute(null);
            return;
        }
        e.printStackTrace();
        ThreadHandlePostExecute(e);
        return;
    }
    ThreadHandlePostExecute(null);
}

From source file:com.grinnellplans.plandroid.LoginTask.java

private String constructResponse(Exception e) {
    Log.w("LoginTask::constructResponse", "enter");
    String resp = null;//  w w  w  .j a v a  2s. co  m
    try {
        JSONObject respObject = new JSONObject();
        respObject.put("success", false);
        respObject.put("message", new StringBuilder().append(e.getClass().getName()).append(": ")
                .append(e.getMessage()).toString());

        resp = respObject.toString();
    } catch (Exception localException) {
        Log.w("LoginTask::constructResponse", "caught exception");
        resp = "{\"success\":false,\"message\":\"unknown local exception occured\"}";
    }
    Log.w("LoginTask::constructResponse", "exit");
    return resp;
}

From source file:com.springinpractice.ch14.kite.guard.CircuitBreakerTemplate.java

/**
 * <p>/*from w  ww . j a  v  a  2 s . c  o m*/
 * Executes the specified action inside the circuit breaker.
 * </p>
 * 
 * @param <T>
 *            action return type
 * @param action
 *            action to execute
 * @return result of the action
 * @throws CircuitOpenException
 *             if the breaker is in the open state
 * @throws Exception
 *             exception thrown by the action, if any
 */
public <T> T execute(GuardCallback<T> action) throws Exception {
    final State currState = getState();
    switch (currState) {

    case CLOSED:
        try {
            T value = action.doInGuard();
            this.exceptionCount.set(0);
            return value;
        } catch (Exception e) {
            if (isHandledException(e.getClass()) && exceptionCount.incrementAndGet() >= exceptionThreshold) {
                trip();
            }

            // In any event, throw the exception.
            throw e;
        }

    case OPEN:
        throw new CircuitOpenException();

    case HALF_OPEN:
        try {
            T value = action.doInGuard();
            reset();
            return value;
        } catch (Exception e) {
            if (isHandledException(e.getClass())) {
                trip();
            }
            throw e;
        }

    default:
        // This shouldn't happen...
        throw new IllegalStateException("Unknown state: " + currState);
    }
}