Example usage for java.lang Exception Exception

List of usage examples for java.lang Exception Exception

Introduction

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

Prototype

public Exception(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:customer.springboot.controller.UserController.java

@RequestMapping(value = "/loggedin", method = RequestMethod.GET)
public User getUserLoggedIn() throws Exception {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null) {
        throw new Exception("Unauthenticated Request");
    }//from ww w .j av  a  2  s  .c  om

    Object principal = auth.getPrincipal();
    if (principal == null) {
        throw new Exception("Invalid authentication object");
    }

    if (!org.springframework.security.core.userdetails.User.class.isAssignableFrom(principal.getClass())) {
        throw new Exception("Invalid authentication object" + principal.getClass().getName());
    }
    org.springframework.security.core.userdetails.User u = (org.springframework.security.core.userdetails.User) principal;
    return userDao.findByUsername(u.getUsername());
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.json.GetVClassesForVClassGroup.java

@Override
protected JSONObject process() throws Exception {
    JSONObject map = new JSONObject();
    String vcgUri = vreq.getParameter("classgroupUri");
    if (vcgUri == null) {
        throw new Exception("no URI passed for classgroupUri");
    }/* w w w .j a va 2  s  .c o m*/

    VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
    VClassGroup vcg = vcgc.getGroup(vcgUri);
    if (vcg == null) {
        throw new Exception("Could not find vclassgroup: " + vcgUri);
    }

    ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vcg.size());
    for (VClass vc : vcg) {
        JSONObject vcObj = new JSONObject();
        vcObj.put("name", vc.getName());
        vcObj.put("URI", vc.getURI());
        vcObj.put("entityCount", vc.getEntityCount());
        classes.add(vcObj);
    }
    map.put("classes", classes);
    map.put("classGroupName", vcg.getPublicName());
    map.put("classGroupUri", vcg.getURI());

    return map;
}

From source file:egovframework.rte.fdl.string.EgovObjectUtil.java

/**
 * ? ? ./*from   ww  w . j av  a2 s.c o m*/
 * @param className
 * @return
 * @throws ClassNotFoundException
 * @throws Exception
 */
public static Class<?> loadClass(String className) throws ClassNotFoundException, Exception {

    Class<?> clazz = null;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ClassNotFoundException();
    } catch (Exception e) {
        throw new Exception(e);
    }

    if (clazz == null) {
        clazz = Class.forName(className);
    }

    return clazz;

}

From source file:com.appranix.adapter.service.AdapterServiceImpl.java

@Override
public void adapterRead(int id) throws Exception {
    try {//from w ww .  jav a  2s .c  om
        final String uri = "http://localhost:9090/adapter/rest/cm/simple/cis/" + id;

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> result = restTemplate.getForEntity(uri, String.class);

        System.out.println(result);

    } catch (Exception e) {
        throw new Exception("Error in Read Operation");
    }
}

From source file:com.hangum.tadpole.db.bander.cubrid.CubridExecutePlanUtils.java

/**
 * cubrid execute plan//from   w  w w  .  jav a 2 s . c o  m
 * 
 * @param userDB
 * @param sql
 * @return
 * @throws Exception
 */
public static String plan(UserDBDAO userDB, String sql) throws Exception {
    if (!sql.toLowerCase().startsWith("select")) {
        logger.error("[cubrid execute plan ]" + sql);
        throw new Exception("This statment not select. please check.");
    }
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pstmt = null;

    try {
        //         Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
        //         conn = DriverManager.getConnection(userDB.getUrl(), userDB.getUsers(), userDB.getPasswd());
        //         conn.setAutoCommit(false); //     auto commit? false  .
        conn = TadpoleSQLManager.getInstance(userDB).getDataSource().getConnection();
        conn.setAutoCommit(false); //     auto commit? false  .

        sql = StringUtils.trim(sql).substring(6);
        if (logger.isDebugEnabled())
            logger.debug("[qubrid modifying query]" + sql);
        sql = "select " + RECOMPILE + sql;

        pstmt = conn.prepareStatement(sql);
        ((CUBRIDStatement) pstmt).setQueryInfo(true);
        rs = pstmt.executeQuery();

        String plan = ((CUBRIDStatement) pstmt).getQueryplan(); //  ?    .
        //         conn.commit();

        if (logger.isDebugEnabled())
            logger.debug("cubrid plan text : " + plan);

        return plan;

    } finally {
        if (rs != null)
            rs.close();
        if (pstmt != null)
            pstmt.close();
        if (conn != null)
            conn.close();
    }
}

From source file:geotag.example.sbickt.SbicktAPI.java

public static void newGeoTag(List<NameValuePair> geoTagData) throws Exception {
    String url = Properties.getUrlIndex();

    HttpHelper httpConnection = HttpHelper.getInstance(url);

    if (!httpConnection.POSTRequest(geoTagData)) {
        throw new Exception("SbicktAPI -> newGeoTag: Failed to add new geotag");
    }/* ww  w.  ja  v  a 2s.  c  om*/
}

From source file:com.card.loop.xyz.service.LearningElementService.java

public boolean acceptLE(LearningElementDto le) throws UnknownHostException, Exception {
    boolean ok = false;
    LearningElement model = dao.getLE(le.getId());
    if (model != null) {
        model.setStatus(2);// ww  w . j a v a2 s .c  om
        dao.acceptLE(model);
        ok = true;
    } else
        throw new Exception("LearningElement does not exist. ");
    return ok;

}

From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java

public static void setEntity(final StructEntityReflect enref, final HashMap<String, AbstractEntity> entities,
        final ResultSet rs) throws Exception {
    Class<?> type = Class.forName(enref.Class);
    Object obj = type.newInstance();
    if (!(obj instanceof AbstractEntity))
        throw new Exception("Unsupported Entity type [" + type.getCanonicalName() + "]");
    AbstractEntity entity = (AbstractEntity) obj;
    AbstractJoinGraph gr = AbstractJoinGraph.lookup(type);

    for (StructAttributeReflect attr : enref.Attributes) {
        Stack<KeyValuePair<Class<?>>> path = new Stack<KeyValuePair<Class<?>>>();
        Class<?> at = attr.Field.getType();
        KeyValuePair<Class<?>> ak = new KeyValuePair<Class<?>>();
        ak.setValue(entity.getClass());//from w  w w .  j av  a  2 s. c o m
        ak.setKey(attr.Column);
        path.push(ak);

        if (attr.Reference == null || attr.Reference.Type != EnumRefereceType.One2Many) {
            setColumnValue(rs, attr, entity, gr, path);
        } else if (attr.Reference != null) {
            // Object ao = createListInstance(entity, attr);
            Class<?> rt = Class.forName(attr.Reference.Class);
            Object ro = rt.newInstance();
            if (!(ro instanceof AbstractEntity))
                throw new Exception(
                        "Reference [" + attr.Column + "] is of invalid type. [" + at.getCanonicalName()
                                + "] does not extend from [" + AbstractEntity.class.getCanonicalName() + "]");
            AbstractEntity ae = (AbstractEntity) getColumnValue(rs, attr, entity, gr, path);
            addListValue(ae, entity, attr);
        }

    }
    String key = entity.getEntityKey();
    if (!entities.containsKey(key)) {
        entities.put(entity.getEntityKey(), entity);
    } else {
        AbstractEntity target = entities.get(key);
        for (StructAttributeReflect attr : enref.Attributes) {
            if (attr.Reference.Type == EnumRefereceType.One2Many) {
                copyToList(entity, target, attr);
            }
        }
    }
}

From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForRequest.java

public StartUpRemoteForRequest(Properties prop) throws Exception {
    if (!((String) prop.get("adapterType")).toUpperCase().equals("REQUEST"))
        throw new Exception("?" + prop.get("adapterType") + "?!");
    m_props = prop;//from   www  .  j  a  v a2  s. co m
}

From source file:com.xinferin.licensing.LicenceActivator.java

private void initialiseKeys() throws Exception {
    try {/*w w  w  .  ja  v a  2 s .  c o m*/

        byte[] publicKeyBytes = Base64.decodeBase64(spublicKey);

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);
        publicKey = keyFactory.generatePublic(publicKeySpec);

    } catch (InvalidKeySpecException e) {
        throw new Exception("Invalid Key Specs not valid Key files." + e.getCause());
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("There is no such algorithm. Please check the JDK ver." + e.getCause());
    }
}