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:jflowmap.JFlowMapApplet.java

public String exportToSvg() {
    blockingGlassPane.setVisible(true);//from   w  ww  .j ava 2 s.  co m
    String svg = null;
    VisualCanvas canvas = getCanvas();
    if (canvas != null) {
        try {
            StringWriter sw = new StringWriter();
            canvas.paintToSvg(sw);

            svg = sw.getBuffer().toString();
        } catch (Exception e) {
            logger.error("SVG export failed", e);
            JMsgPane.showErrorDialog(this,
                    "SVG export failed: " + e.getClass().getSimpleName() + ": " + e.getMessage());
        }
    }
    blockingGlassPane.setVisible(false);
    return svg;
}

From source file:edu.berkeley.ground.postgres.dao.version.PostgresItemDao.java

protected T retrieve(String sql, Object field) throws GroundException {
    JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql));

    if (json.size() == 0) {
        throw new GroundException(ExceptionType.ITEM_NOT_FOUND, this.getType().getSimpleName(),
                field.toString());//from w w  w  .  j  ava2s.  c  o  m
    }

    Class<T> type = this.getType();
    JsonNode itemJson = json.get(0);
    long id = itemJson.get("itemId").asLong();
    String name = itemJson.get("name").asText();
    String sourceKey = itemJson.get("sourceKey").asText();

    Object[] args = { id, name, sourceKey, this.postgresTagDao.retrieveFromDatabaseByItemId(id) };

    Constructor<T> constructor;
    try {
        constructor = type.getConstructor(long.class, String.class, String.class, Map.class);
        return constructor.newInstance(args);
    } catch (Exception e) {
        throw new GroundException(ExceptionType.OTHER,
                String.format("Catastrophic failure: Unable to instantiate Item.\n%s: %s.",
                        e.getClass().getName(), e.getMessage()));
    }
}

From source file:ezbake.intent.query.service.QueryService.java

@Override
public Metadata getMetadata(EzSecurityToken securityToken) throws EzSecurityTokenException {
    validateSecurityToken(securityToken);
    AuditEvent event = AuditEvent.event("getMetadata", securityToken);

    try {/*from  ww w.j a va 2 s .  c  o m*/
        // operators
        List<Operator> operators = new ArrayList<>();
        for (BinaryOperator operator : BinaryOperator.values()) {
            operators.add(getOperator(operator));
        }

        // relations
        List<String> relations = new ArrayList<>();
        relations.add("AND");
        relations.add("OR");

        // intent types
        List<IntentTypeTable> intentTypes = new ArrayList<>();
        for (IntentType type : IntentType.values()) {
            intentTypes.add(getIntentType(type));
        }

        return new Metadata(operators, relations, intentTypes);
    } catch (Exception e) {
        event.failed();
        event.arg(e.getClass().getName(), e);
        throw e;
    } finally {
        auditLogger.logEvent(event);
    }
}

From source file:com.stitchgalaxy.sg_manager_web.GlobalDefaultExceptionHandler.java

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(Exception e) throws Exception {
    // If the exception is annotated with @ResponseStatus rethrow it and let
    // the framework handle it - like the OrderNotFoundException example
    // at the start of this post.
    // AnnotationUtils is a Spring Framework utility class.
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
        throw e;/*from w w w.  jav  a 2  s .  c o  m*/

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);

    ModelAndView mav = new ModelAndView("error");
    mav.addObject("stack_trace", sw.toString());

    return mav;
}

From source file:com.clustercontrol.monitor.run.factory.ModifySchedule.java

/**
 * DB???????????//w w w .  j  a  v a2  s  .c  om
 * @throws TriggerSchedulerException
 * 
 * @since 4.0.0
 */
public void updateScheduleAll() throws HinemosUnknown {
    m_log.debug("updateScheduleAll()");

    JpaTransactionManager jtm = null;
    Throwable exception = null;
    Collection<MonitorInfo> entityList = null;
    try {
        jtm = new JpaTransactionManager();
        jtm.begin();
        entityList = QueryUtil.getAllMonitorInfo();
        jtm.commit();
    } catch (Exception e) {
        String msg = "updateScheduleAll() " + e.getClass().getSimpleName() + ", " + e.getMessage();
        m_log.warn(msg, e);
        if (jtm != null)
            jtm.rollback();
        exception = e;
    } finally {
        if (jtm != null)
            jtm.close();
    }

    if (entityList != null) {
        for (MonitorInfo entity : entityList) {
            try {
                // ????????
                if (entity.getMonitorFlg() || entity.getCollectorFlg()) {
                    updateSchedule(entity, true);
                }
            } catch (Exception e) {
                m_log.info("updateScheduleAll() scheduleJob : monitorId = " + entity.getMonitorId() + ", "
                        + e.getClass().getSimpleName() + ", " + e.getMessage());
                // ??????throw????
                exception = e;
            }
        }
    }

    if (exception != null) {
        throw new HinemosUnknown("An error occurred while scheduling the trigger.", exception);
    }
}

From source file:com.ravens.filters.GlobalDefaultExceptionHandler.java

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
    // If the exception is annotated with @ResponseStatus rethrow it and let
    // the framework handle it - like the OrderNotFoundException example
    // at the start of this post.
    // AnnotationUtils is a Spring Framework utility class.
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
        throw e;// ww w  .ja v a  2  s  . co m

    // Otherwise setup and send the user to a default error-view.
    ModelAndView mav = new ModelAndView();
    mav.addObject("exception", e);
    mav.addObject("url", req.getRequestURL());
    mav.setViewName(DEFAULT_ERROR_VIEW);

    e.printStackTrace();
    return mav;
}

From source file:fr.gael.dhus.server.http.webapp.search.controller.SearchController.java

@PreAuthorize("hasRole('ROLE_SEARCH')")
@RequestMapping(value = "/")
public void search(Principal principal, @RequestParam(value = "q") String original_query,
        @RequestParam(value = "rows", defaultValue = "") String rows_str,
        @RequestParam(value = "start", defaultValue = "") String start_str,
        @RequestParam(value = "format", defaultValue = "") String format,
        @RequestParam(value = "orderby", required = false) String orderby, HttpServletResponse res)
        throws IOException, XMLStreamException, SolrServerException {
    ServerConfiguration dhusServer = configurationManager.getServerConfiguration();

    String query = convertQuery(original_query);
    LOGGER.info("Rewritten Query: {}", query);

    boolean json = "json".equalsIgnoreCase(format);

    SolrQuery solrQuery = new SolrQuery(query);
    solrQuery.setParam("wt", "xslt").setParam("tr", "opensearch_atom.xsl")
            .setParam("dhusLongName", configurationManager.getNameConfiguration().getLongName())
            .setParam("dhusServer", dhusServer.getExternalUrl())
            .setParam("type", json ? "application/json" : "application/xml")
            .setParam("originalQuery", original_query);

    if (json) {/*  w w w  .j  a va  2s.  c om*/
        solrQuery.setParam("format", "json");
    }

    if (rows_str != null && !rows_str.isEmpty()) {
        try {
            int rows = Integer.parseInt(rows_str);
            if (ROW_LIMIT != UNLIMITED_SEARCH_ROWS && rows > ROW_LIMIT) {
                String errorMessage = String
                        .format("Parameter `rows` exceeds the maximum value (%d) in search request", ROW_LIMIT);
                LOGGER.warn(errorMessage);
                res.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage);
                return;
            }
            solrQuery.setRows(rows);
        } catch (NumberFormatException nfe) {
            /* noting to do : keep the default value */
        }
    }
    if (start_str != null && !start_str.isEmpty()) {
        try {
            int start = Integer.parseInt(start_str);
            solrQuery.setStart(start);
        } catch (NumberFormatException nfe) {
            /* noting to do : keep the default value */
        }
    }
    // If `orderby` param is not defined, default to ordering by ingestiondate desc.
    // Define `orderby` to `""` (empty string) to order by the full text search score.
    if (orderby == null) {
        solrQuery.setSort("ingestiondate", SolrQuery.ORDER.desc);
    } else if (!orderby.isEmpty()) {
        solrQuery.setParam("sort", orderby.toLowerCase());
    }

    try (InputStream is = solrDao.streamSelect(solrQuery)) {
        try (ServletOutputStream os = res.getOutputStream()) {
            res.setStatus(HttpServletResponse.SC_OK);
            if ("json".equalsIgnoreCase(format)) {
                res.setContentType("application/json");
                xmlToJson(is, os);
            } else {
                res.setContentType("application/xml");
                IOUtils.copy(is, os);
            }
        }
    } catch (Exception e) {
        res.addHeader("cause-message", String.format("%s : %s", e.getClass().getSimpleName(), e.getMessage()));
        throw e;
    }
}

From source file:com.flexive.tests.embedded.persistence.TypeStateTest.java

/**
 * Test active/inactive mandators with the tree
 *
 * @throws FxApplicationException on errors
 *///from  w ww  .  j  a va2 s  . c  o  m
public void typeStateTree() throws Exception {
    EJBLookup.getTreeEngine().clear(FxTreeMode.Edit);
    type.save(CacheAdmin.getEnvironment().getType(testType).asEditable().setState(TypeState.Available));
    FxContent co_act1 = co.initialize(testType);
    FxPK pk = co.save(co_act1);
    EJBLookup.getTreeEngine().getNode(FxTreeMode.Edit, FxTreeNode.ROOT_NODE);
    long folder = EJBLookup.getTreeEngine().save(FxTreeNodeEdit.createNew("TypeStateTestFolder"));
    long node_root = EJBLookup.getTreeEngine()
            .save(FxTreeNodeEdit.createNew("TypeStateTestRoot").setReference(pk));
    EJBLookup.getTreeEngine()
            .save(FxTreeNodeEdit.createNew("TypeStateTestChild").setReference(pk).setParentNodeId(folder));
    type.save(CacheAdmin.getEnvironment().getType(testType).asEditable().setState(TypeState.Locked));
    FxTreeNode node = EJBLookup.getTreeEngine().getTree(FxTreeMode.Edit, FxTreeNode.ROOT_NODE, 100);
    //Assert.assertEquals(node.getTotalChildCount(), 3);
    Assert.assertEquals(node.getDirectChildCount(), 2);
    Assert.assertEquals(node.getChildren().size(), 2);
    Assert.assertEquals(node.getChildren().get(0).getChildren().size(), 1);
    type.save(CacheAdmin.getEnvironment().getType(testType).asEditable().setState(TypeState.Unavailable));
    node = EJBLookup.getTreeEngine().getTree(FxTreeMode.Edit, FxTreeNode.ROOT_NODE, 100);
    Assert.assertEquals(node.getChildren().size(), 1);
    Assert.assertEquals(node.getChildren().get(0).getChildren().size(), 0);
    try {
        EJBLookup.getTreeEngine().getNode(FxTreeMode.Edit, node_root);
        Assert.fail("getNode on an unavailable type should fail!");
    } catch (FxNotFoundException e) {
        //expected
    } catch (Exception ex) {
        Assert.fail("FxNotFoundException expected! Got: " + ex.getClass().getCanonicalName());
    }
    type.save(CacheAdmin.getEnvironment().getType(testType).asEditable().setState(TypeState.Available));
    node = EJBLookup.getTreeEngine().getTree(FxTreeMode.Edit, FxTreeNode.ROOT_NODE, 100);
    Assert.assertEquals(node.getChildren().size(), 2);
    Assert.assertEquals(node.getChildren().get(0).getChildren().size(), 1);
    EJBLookup.getTreeEngine().getNode(FxTreeMode.Edit, node_root);
    EJBLookup.getTreeEngine().clear(FxTreeMode.Edit);
}

From source file:com.amalto.core.server.DefaultDataCluster.java

/**
 * Remove a Data Cluster The physical remove is performed on a separate Thred
 *///from w  w w.  j av a2  s .com
@Override
public DataClusterPOJOPK removeDataCluster(DataClusterPOJOPK pk) throws XtentisException {
    // remove the actual physical cluster - do it asynchronously
    try {
        String dataClusterName = pk.getUniqueId();
        // get the xml server wrapper
        XmlServer server = Util.getXmlServerCtrlLocal();
        server.deleteCluster(dataClusterName);
    } catch (Exception e) {
        String err = "Unable to physically delete the data cluster " + pk.getUniqueId() + ": "
                + e.getClass().getName() + ": " + e.getLocalizedMessage();
        try {
            ObjectPOJO.remove(DataClusterPOJO.class, new ObjectPOJOPK(pk.getUniqueId()));
        } catch (Exception x) {
            LOGGER.error("Could not remove data cluster object.", x);
        }
        LOGGER.error(err);
        throw new XtentisException(err, e);
    }
    ObjectPOJOPK objectPOJOPK = ObjectPOJO.remove(DataClusterPOJO.class, pk);

    MDMEhCacheUtil.clearCache(DATA_CLUSTER_CACHE_NAME);

    return new DataClusterPOJOPK(objectPOJOPK);
}

From source file:fm.audiobox.tests.unit.models.UserTests.java

/**
 * Test all user keys are well parsed./*from   www  .j a v  a  2  s. co m*/
 *
 * @throws AudioBoxException the audio box exception
 * @throws ParseException    the parse exception
 */
@Test
public void testAllUserKeysAreWellParsed() throws IOException, ParseException {
    User user = c.getUser();
    assertNotNull(user);

    assertEquals(3, user.getId());

    assertEquals("2013-08-29T18:25:52.079Z", user.getCreatedAt());
    long millisCreated = ModelUtil.toUnixTime(new SimpleDateFormat(ModelUtil.AUDIOBOX_DATE_FORMAT),
            user.getCreatedAt());
    assertEquals(1377800752079L, millisCreated);

    assertEquals("2014-01-21T21:48:58.850Z", user.getUpdatedAt());
    long millisUpdated = ModelUtil.toUnixTime(new SimpleDateFormat(ModelUtil.AUDIOBOX_DATE_FORMAT),
            user.getUpdatedAt());
    assertEquals(1390340938850L, millisUpdated);

    assertEquals("Real Name", user.getRealName());
    assertEquals("test@test.com", user.getEmail());
    assertEquals("4u770k3n", user.getAuthToken());
    assertEquals(60, user.getMediaFilesCount());
    assertEquals(13, user.getPlaylistsCount());
    assertEquals(5, user.getTotalPlayCount());
    assertEquals(StringUtils.EMPTY, user.getCountry());
    assertEquals("UTC", user.getTimeZone());
    assertEquals("aac,mp3,m4a,flac,mp4,flv,webm", user.getAcceptedExtensions());
    assertEquals("audio/aac,audio/mpeg,audio/mp4,audio/flac,video/mp4,video/x-flv,video/webm",
            user.getAcceptedFormats());
    assertEquals("private-abc", user.getCometChannel());
    assertEquals("active", user.getSubscriptionState());
    assertEquals("audiobox_50", user.getPlan());
    assertEquals("000_offline", user.getOfflinePlaylist());

    Permissions perms = user.getPermissions();
    assertNotNull(perms);

    assertTrue(perms.hasPlayer());
    assertTrue(perms.hasLocal());
    assertTrue(perms.hasCloud());
    assertTrue(perms.hasDropbox());
    assertTrue(perms.hasGdrive());
    assertTrue(perms.hasSkydrive());
    assertTrue(perms.hasMega());
    assertTrue(perms.hasBox());
    assertTrue(perms.hasSoundcloud());
    assertTrue(perms.hasYoutube());
    assertTrue(perms.hasLastfm());
    assertTrue(perms.hasTwitchtv());
    assertTrue(perms.hasFacebook());
    assertTrue(perms.hasTwitter());
    assertTrue(perms.hasLyrics());
    assertTrue(perms.hasSongkick());

    ExternalTokens tks = user.getExternalTokens();
    assertNotNull(tks);

    assertFalse(tks.isDropboxEnabled());
    assertTrue(tks.isGdriveEnabled());
    assertTrue(tks.isSkydriveEnabled());
    assertFalse(tks.isMegaEnabled());
    assertFalse(tks.isSoundcloudEnabled());
    assertTrue(tks.isYoutubeEnabled());
    assertTrue(tks.isBoxEnabled());
    assertFalse(tks.isLastfmEnabled());
    assertFalse(tks.isTwitchtvEnabled());
    assertFalse(tks.isFacebookEnabled());
    assertFalse(tks.isTwitterEnabled());

    Stats stats = user.getStats();
    assertNotNull(stats);

    assertEquals(5, stats.getTotalPlayCount());
    assertEquals(777662290, stats.getDataServedOverall());
    assertEquals(777662290, stats.getDataServedThisMonth());
    assertEquals(5533908, stats.getBoxDataStoredOverall());
    assertEquals(0, stats.getCloudDataStoredOverall());
    assertEquals(0, stats.getLocalDataStoredOverall());
    assertEquals(5533908, stats.getBoxDataStoredThisMonth());
    assertEquals(170368034, stats.getGdriveDataStoredOverall());
    assertEquals(0, stats.getMegaDataStoredOverall());
    assertEquals(110981727, stats.getDropboxDataStoredOverall());
    assertEquals(1500, stats.getYoutubeDataStoredOverall());
    assertEquals(2175615, stats.getCloudDataStoredThisMonth());
    assertEquals(0, stats.getLocalDataStoredThisMonth());
    assertEquals(95088577, stats.getSkydriveDataStoredOverall());
    assertEquals(170368034, stats.getGdriveDataStoredThisMonth());
    assertEquals(0, stats.getMegaDataStoredThisMonth());
    assertEquals(110981727, stats.getDropboxDataStoredThisMonth());
    assertEquals(0, stats.getSoundcloudDataStoredOverall());
    assertEquals(1500, stats.getYoutubeDataStoredThisMonth());
    assertEquals(95088577, stats.getSkydriveDataStoredThisMonth());
    assertEquals(0, stats.getSoundcloudDataStoredThisMonth());

    Preferences prefs = user.getPreferences();
    assertNotNull(prefs);

    assertEquals("audiobox-fm-blue", prefs.getColor());
    assertTrue(prefs.isRepeatEnabled());
    assertFalse(prefs.isShuffleEnabled());
    assertFalse(prefs.isAutoplayEnabled());
    assertTrue(prefs.isPrebufferEnabled());
    assertFalse(prefs.isJsDemuxerEnabled());
    assertEquals("default", prefs.getTopBarBg());
    assertEquals("50", prefs.getVolumeLevel());
    assertTrue(prefs.doesAcceptsEmails());
    assertFalse(prefs.areTooltipsHidden());

    try {
        prefs.setColor("invalid-value");
        fail("Invalid color name should rise an exception");
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
    }

    prefs.setColor("flock-blue");
    prefs.setRepeat(false);
    prefs.setShuffle(true);
    prefs.setAutoplay(true);
    prefs.setPrebuffer(false);
    prefs.setJsDemuxer(true);
    prefs.setTopBarBg("String");
    prefs.setVolumeLevel("String");
    prefs.setAcceptEmails(false);
    prefs.setHideTooltips(true);

    assertEquals("flock-blue", prefs.getColor());
    assertEquals("#4096EE", prefs.getColorValue());
    assertEquals(false, prefs.isRepeatEnabled());
    assertEquals(true, prefs.isShuffleEnabled());
    assertEquals(true, prefs.isAutoplayEnabled());
    assertEquals(false, prefs.isPrebufferEnabled());
    assertEquals(true, prefs.isJsDemuxerEnabled());
    assertEquals("String", prefs.getTopBarBg());
    assertEquals("String", prefs.getVolumeLevel());
    assertEquals(false, prefs.doesAcceptsEmails());
    assertEquals(true, prefs.areTooltipsHidden());
}