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:cz.muni.fi.mir.controllers.ExceptionHandlingController.java

@ExceptionHandler(Exception.class)
public ModelAndView handleGeneralException(Exception e) {
    logger.info("Exception caught, but general one. Consider creating separate handler for \""
            + e.getClass().getSimpleName() + "\" exception.");
    logger.info(e);/*from w w w . j a v  a 2 s . c  o m*/

    return processException(e);
}

From source file:com.nagarro.core.v2.controller.BaseController.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody//from  w  w w. j a va 2 s.  c  o  m
@ExceptionHandler({ ModelNotFoundException.class })
public ErrorListWsDTO handleModelNotFoundException(final Exception ex) {
    LOG.info("Handling Exception for this request - " + ex.getClass().getSimpleName() + " - "
            + sanitize(ex.getMessage()));
    if (LOG.isDebugEnabled()) {
        LOG.debug(ex);
    }
    final ErrorListWsDTO errorListDto = handleErrorInternal(UnknownIdentifierException.class.getSimpleName(),
            ex.getMessage());
    return errorListDto;
}

From source file:in.mtap.iincube.mongoser.codec.crypto.Psyfer.java

/**
 * Performs Base64 decode to extract RAW bytes, and does a decipher and returns UTF-8 string
 *///from  w  ww.  j  a  va  2s. c o m
public String decrypt(String data) {
    try {
        byte[] decoded = base64.decode(data);
        return new String(deCiper.doFinal(decoded), "UTF-8");
    } catch (Exception e) {
        // temporarily suppressing all exceptions under RuntimeException.
        throw new RuntimeException("[" + e.getClass().getSimpleName() + "] @ decrypt: " + e.getMessage());
    }
}

From source file:net.ben.subsonic.androidapp.util.Util.java

public static void showErrorNotification(final Context context, Handler handler, String title,
        Exception error) {
    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    StringBuilder text = new StringBuilder();
    if (error.getMessage() != null) {
        text.append(error.getMessage()).append(" (");
    }//from  w  w w .j  a v a  2 s  . c  o  m
    text.append(error.getClass().getSimpleName());
    if (error.getMessage() != null) {
        text.append(")");
    }

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(android.R.drawable.stat_sys_warning, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // The PendingIntent to launch our activity if the user selects this notification
    Intent intent = new Intent(context, ErrorActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Constants.INTENT_EXTRA_NAME_ERROR, title + ".\n\n" + text);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, text, contentIntent);

    // Send the notification.
    handler.post(new Runnable() {
        @Override
        public void run() {
            notificationManager.cancel(Constants.NOTIFICATION_ID_ERROR);
            notificationManager.notify(Constants.NOTIFICATION_ID_ERROR, notification);
        }
    });
}

From source file:com.clustercontrol.maintenance.factory.MaintenanceCollectStringData.java

/**
 * ?/*from   w  ww .jav  a 2  s.com*/
 */
@Override
protected int _delete(Long boundary, boolean status, String ownerRoleId) {
    int ret = 0;
    JpaTransactionManager jtm = null;

    try {
        //AdminRole???ID??????
        if (RoleIdConstant.isAdministratorRole(ownerRoleId)) {
            jtm = new JpaTransactionManager();
            jtm.begin();
            ret = delete(boundary, status);
            jtm.commit();

        } else {
            ArrayList<MonitorInfo> monitorList = new MonitorSettingControllerBean().getMonitorList();

            ArrayList<String> monitorIdList = new ArrayList<>();

            for (MonitorInfo monitorInfo : monitorList) {
                if (RoleIdConstant.isAdministratorRole(ownerRoleId)
                        || monitorInfo.getOwnerRoleId().equals(ownerRoleId)) {
                    monitorIdList.add(monitorInfo.getMonitorId());
                }
            }
            if (monitorIdList.isEmpty()) {
                return -1;
            }
            jtm = new JpaTransactionManager();
            jtm.begin();

            for (int i = 0; i < monitorIdList.size(); i++) {
                ret += delete(boundary, status, monitorIdList.get(i));
                jtm.commit();
            }
        }
    } catch (Exception e) {
        m_log.warn("deleteCollectData() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
    } finally {
        if (jtm != null)
            jtm.close();
    }
    return ret;
}

From source file:com.clustercontrol.maintenance.factory.MaintenanceSummaryHour.java

/**
 * ?/*from ww  w  . j  a v a 2 s. c  om*/
 */
@Override
protected int _delete(Long boundary, boolean status, String ownerRoleId) {
    int ret = 0;
    JpaTransactionManager jtm = null;
    try {
        //AdminRole???ID??????
        if (RoleIdConstant.isAdministratorRole(ownerRoleId)) {
            jtm = new JpaTransactionManager();
            jtm.begin();
            ret = delete(boundary, status);
            jtm.commit();

        } else {
            ArrayList<MonitorInfo> monitorList = new MonitorSettingControllerBean().getMonitorList();

            ArrayList<String> monitorIdList = new ArrayList<>();

            for (MonitorInfo monitorInfo : monitorList) {
                if (RoleIdConstant.isAdministratorRole(ownerRoleId)
                        || monitorInfo.getOwnerRoleId().equals(ownerRoleId)) {
                    monitorIdList.add(monitorInfo.getMonitorId());
                }
            }
            if (monitorIdList.isEmpty()) {
                return -1;
            }
            jtm = new JpaTransactionManager();
            jtm.begin();

            for (int i = 0; i < monitorIdList.size(); i++) {
                ret += delete(boundary, status, monitorIdList.get(i));
                jtm.commit();
            }
        }
    } catch (Exception e) {
        m_log.warn("deleteCollectData() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
    } finally {
        if (jtm != null)
            jtm.close();
    }
    return ret;
}

From source file:com.nagarro.core.resolver.OAuth2ExceptionHandlerExceptionResolver.java

@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) {
    if (!OAuth2Exception.class.isAssignableFrom(ex.getClass())) {
        return null;
    }/*w w  w. j  a  v  a  2 s .  c o m*/

    //TokenEndpoint exception handlers logic
    ResponseEntity<OAuth2Exception> responseEntity = null;
    final Exception exceptionToTranslate;
    if (ClientRegistrationException.class.isAssignableFrom(ex.getClass())) {
        exceptionToTranslate = new BadClientCredentialsException();
    } else {
        exceptionToTranslate = ex;
    }

    //Exception translation by WebResponseExceptionTranslator
    try {
        responseEntity = webResponseExceptionTranslator.translate(exceptionToTranslate);
    } catch (final Exception e) {
        logger.error("Translating of [" + exceptionToTranslate.getClass().getName() + "] resulted in Exception",
                e);
        return null;
    }

    final ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request);
    final ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

    //get translated headers
    outputMessage.getHeaders().putAll(responseEntity.getHeaders());

    //set status
    outputMessage.setStatusCode(responseEntity.getStatusCode());

    final ErrorListWsDTO errorListDto = new ErrorListWsDTO();
    errorListDto.setErrors(getWebserviceErrorFactory().createErrorList(ex));

    try {
        return writeWithMessageConverters(errorListDto, inputMessage, outputMessage);
    } catch (final Exception handlerException) {
        logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
    }
    return null;
}

From source file:com.clustercontrol.maintenance.factory.MaintenanceCollectDataRaw.java

/**
 * ?//from w  w w. j  a  v a  2s. c  o  m
 */
@Override
protected int _delete(Long boundary, boolean status, String ownerRoleId) {
    int ret = 0;
    JpaTransactionManager jtm = null;

    try {
        //AdminRole???ID??????
        if (RoleIdConstant.isAdministratorRole(ownerRoleId)) {
            jtm = new JpaTransactionManager();
            jtm.begin();
            ret = delete(boundary, status);
            jtm.commit();

        } else {
            ArrayList<MonitorInfo> monitorList = new MonitorSettingControllerBean().getMonitorList();

            ArrayList<String> monitorIdList = new ArrayList<>();

            for (MonitorInfo monitorInfo : monitorList) {
                if (RoleIdConstant.isAdministratorRole(ownerRoleId)
                        || monitorInfo.getOwnerRoleId().equals(ownerRoleId)) {
                    monitorIdList.add(monitorInfo.getMonitorId());
                }
            }

            if (monitorIdList.isEmpty()) {
                return -1;
            }
            jtm = new JpaTransactionManager();
            jtm.begin();

            for (int i = 0; i < monitorIdList.size(); i++) {
                ret += delete(boundary, status, monitorIdList.get(i));
                jtm.commit();
            }
        }
    } catch (Exception e) {
        m_log.warn("deleteCollectData() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
    } finally {
        if (jtm != null)
            jtm.close();
    }
    return ret;
}

From source file:com.epam.ta.reportportal.commons.exception.forwarding.ClientResponseForwardingExceptionHandler.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {
    /* just forward upstream */
    if (ResponseForwardingException.class.isAssignableFrom(ex.getClass())) {
        ResponseForwardingException forwardingException = ((ResponseForwardingException) ex);
        try (ByteArrayInputStream dataStream = new ByteArrayInputStream(forwardingException.getBody())) {

            //copy status
            response.setStatus(forwardingException.getStatus().value());

            //copy headers
            response.setContentType(forwardingException.getHeaders().getContentType().toString());

            //copy body
            ByteStreams.copy(dataStream, response.getOutputStream());

            // return empty model and view to short circuit the
            // iteration and to let
            // Spring know that we've rendered the view ourselves:
            return new ModelAndView();

        } catch (IOException e) {
            LOGGER.error("Cannot forward exception", e);
            return null;
        }//from   w  w w.j av  a  2 s  . c o  m
    }

    return null;
}

From source file:pl.bristleback.server.bristle.action.exception.handler.ActionExceptionHandlers.java

public ActionExceptionHandler getHandler(Exception exception, ActionExecutionStage stage) {
    return handlerGroups.get(stage).getHandler(exception.getClass());
}