Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:net.lightbody.bmp.proxy.jetty.util.Resource.java

/** Construct a resource from a url.
 * @param url A URL.//w  w  w  .  j  a va  2 s.c o m
 * @return A Resource object.
 */
public static Resource newResource(URL url) throws IOException {
    if (url == null)
        return null;

    String urls = url.toExternalForm();
    if (urls.startsWith("file:")) {
        try {
            FileResource fileResource = new FileResource(url);
            return fileResource;
        } catch (Exception e) {
            log.debug(LogSupport.EXCEPTION, e);
            return new BadResource(url, e.toString());
        }
    } else if (urls.startsWith("jar:file:")) {
        return new JarFileResource(url);
    } else if (urls.startsWith("jar:")) {
        return new JarResource(url);
    }

    return new URLResource(url, null);
}

From source file:com.tethrnet.manage.db.AuthDB.java

/**
 * auth user and return auth token if valid auth
 *
 * @param auth username and password object
 * @return auth token if success/*from w w w  .j  a  v a 2s  . c o  m*/
 */
public static String login(Auth auth) {
    String authToken = null;
    //admin just for locally
    if (!auth.getUsername().equals("admin")) {
        //check ldap first
        authToken = ExternalAuthUtil.login(auth);
    }

    if (StringUtils.isEmpty(authToken)) {

        Connection con = null;

        try {
            con = DBUtils.getConn();

            //get salt for user
            String salt = getSaltByUsername(con, auth.getUsername());
            //login
            PreparedStatement stmt = con
                    .prepareStatement("select * from users where enabled=true and username=? and password=?");
            stmt.setString(1, auth.getUsername());
            stmt.setString(2, EncryptionUtil.hash(auth.getPassword() + salt));
            ResultSet rs = stmt.executeQuery();

            if (rs.next()) {

                auth.setId(rs.getLong("id"));
                authToken = UUID.randomUUID().toString();
                auth.setAuthToken(authToken);
                auth.setAuthType(Auth.AUTH_BASIC);
                updateLogin(con, auth);

            }
            DBUtils.closeRs(rs);
            DBUtils.closeStmt(stmt);

        } catch (Exception e) {
            log.error(e.toString(), e);
        }

        DBUtils.closeConn(con);
    }

    return authToken;

}

From source file:com.vmware.identity.idm.IdmDataCreator.java

private static RelyingParty processRelyingParty(CasIdmClient idmClient, String rpName) throws Exception {
    // create relying party
    RelyingParty rp = new RelyingParty(rpName);

    // add certificate and other parameters
    try {/*from  w ww .  ja  v a2 s  .  co  m*/
        rp.setUrl(ServerConfig.getRelyingPartyUrl(rpName));
        rp.setAuthnRequestsSigned(ServerConfig.getRelyingPartyAuthnRequestsSigned(rpName));

        KeyPair kp = readKeyStore(ServerConfig.getRelyingPartyCredentialDescriptor(rpName));
        List<Certificate> certificateChain = kp.getCertificateChain();
        // TODO change the Relaying Party to get a chain not only leaf
        // certificate
        assert certificateChain != null && certificateChain.size() > 0;
        rp.setCertificate(certificateChain.get(0));
    } catch (Exception e) {
        logger.debug("processRelyingParty: Caught exception {}", e.toString());
        throw new IllegalStateException(e);
    }

    // add Assertion Consumer Services
    int i = 0;
    ArrayList<AssertionConsumerService> services = new ArrayList<AssertionConsumerService>();
    String acsName = ServerConfig.getAssertionConsumerService(rpName, i);
    while (acsName != null) {
        AssertionConsumerService acs = processAssertionConsumerService(idmClient, acsName);
        // store service data
        services.add(acs);
        i++;
        acsName = ServerConfig.getAssertionConsumerService(rpName, i);
    }

    // commit Assertion Consumer Services
    rp.setAssertionConsumerServices(services);

    // get default assertion consumer service
    String defaultService = ServerConfig.getDefaultAssertionConsumerService(rpName);
    rp.setDefaultAssertionConsumerService(defaultService);

    // add Single Logout Services
    i = 0;
    ArrayList<ServiceEndpoint> sloServices = new ArrayList<ServiceEndpoint>();
    String sloName = ServerConfig.getSingleLogoutService(rpName, i);
    while (sloName != null) {
        ServiceEndpoint slo = processSingleLogoutService(idmClient, sloName);
        // store service data
        sloServices.add(slo);
        i++;
        sloName = ServerConfig.getSingleLogoutService(rpName, i);
    }

    // commit Single Logout Services
    rp.setSingleLogoutServices(sloServices);

    return rp;
}

From source file:com.tethrnet.manage.db.SessionAuditDB.java

/**
 * returns sessions based on sort order defined
 *
 * @param sortedSet object that defines sort order
 * @return session list// ww w.j ava 2 s  . co  m
 */
public static SortedSet getSessions(SortedSet sortedSet) {
    //get db connection
    Connection con = null;
    List<SessionAudit> outputList = new LinkedList<SessionAudit>();

    String orderBy = "";
    if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
        orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
    }

    String sql = "select * from session_log, users where users.id= session_log.user_id ";
    sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))
            ? " and session_log.user_id=? "
            : "";
    sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID))
            ? " and session_log.id in ( select session_id from terminal_log where terminal_log.system_id=? ) "
            : "";
    sql += orderBy;

    try {

        con = DBUtils.getConn();
        deleteAuditHistory(con);

        PreparedStatement stmt = con.prepareStatement(sql);
        int i = 1;
        //set filters in prepared statement
        if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) {
            stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)));
        }
        if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID))) {
            stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID)));
        }

        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            SessionAudit sessionAudit = new SessionAudit();
            sessionAudit.setId(rs.getLong("session_log.id"));
            sessionAudit.setSessionTm(rs.getTimestamp("session_tm"));
            sessionAudit.setUser(UserDB.getUser(con, rs.getLong("user_id")));
            outputList.add(sessionAudit);

        }

        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    //close db connection
    DBUtils.closeConn(con);

    sortedSet.setItemList(outputList);

    return sortedSet;

}

From source file:gdt.jgui.entity.bonddetail.JBondDetailPanel.java

private static void saveSelection(JMainConsole console, String entihome$, String edgeKey$, String bondKey$) {
    try {//from w w  w .j  a  va2s . c  o  m
        if (bondKey$ == null)
            return;
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack edge = entigrator.getEntityAtKey(edgeKey$);
        if (!edge.existsElement("parameter"))
            edge.createElement("parameter");
        edge.putElementItem("parameter", new Core(null, JBondsPanel.BOND_KEY, bondKey$));
        entigrator.save(edge);
    } catch (Exception e) {
        System.out.println("JBondsPanel:saveSelectedBond:" + e.toString());
    }
}

From source file:cn.apputest.ctria.service.UploadFailRecordService.java

public static void setServiceAlarm(Context context) {
    Log.i("ServiceUtil-AlarmManager", "invokeTimerPOIService wac called..");
    PendingIntent alarmSender = null;//  w  w w.j  av  a  2 s  .  c o m
    Intent startIntent = new Intent(context, UploadFailRecordService.class);
    startIntent.setAction(Constants.POI_SERVICE_ACTION);
    try {
        alarmSender = PendingIntent.getService(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    } catch (Exception e) {
        Log.i("ServiceUtil-AlarmManager", "failed to start " + e.toString());
    }
    AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.ELAPSED_TIME_F,
            alarmSender);
}

From source file:com.keybox.manage.db.SessionAuditDB.java

/**
 * returns sessions based on sort order defined
 *
 * @param sortedSet object that defines sort order
 * @return session list//from   w  w w.j av  a  2  s.  c o m
 */
public static SortedSet getSessions(SortedSet sortedSet) {
    //get db connection
    Connection con = null;
    List<SessionAudit> outputList = new LinkedList<>();

    String orderBy = "";
    if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
        orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
    }

    String sql = "select * from session_log, users where users.id= session_log.user_id ";
    sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))
            ? " and session_log.user_id=? "
            : "";
    sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID))
            ? " and session_log.id in ( select session_id from terminal_log where terminal_log.system_id=? ) "
            : "";
    sql += orderBy;

    try {

        con = DBUtils.getConn();
        deleteAuditHistory(con);

        PreparedStatement stmt = con.prepareStatement(sql);
        int i = 1;
        //set filters in prepared statement
        if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) {
            stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)));
        }
        if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID))) {
            stmt.setLong(i, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM_ID)));
        }

        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            SessionAudit sessionAudit = new SessionAudit();
            sessionAudit.setId(rs.getLong("session_log.id"));
            sessionAudit.setSessionTm(rs.getTimestamp(SESSION_TM));
            sessionAudit.setUser(UserDB.getUser(con, rs.getLong(USER_ID)));
            outputList.add(sessionAudit);

        }

        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    //close db connection
    DBUtils.closeConn(con);

    sortedSet.setItemList(outputList);

    return sortedSet;

}

From source file:com.gtwm.pb.servlets.ServletUtilMethods.java

/**
 * Log errors in a helpful format. Use this version when no
 * HttpServletRequest object is available
 * /*w  ww  . ja v a 2  s  .co  m*/
 * @see #logException(Exception, HttpServletRequest, String)
 */
public static void logException(Exception ex, String topLevelMessage) {
    String errorMessage = "";
    if (topLevelMessage != null) {
        errorMessage += topLevelMessage + "\r\n" + " - ";
    }
    errorMessage += ex.toString() + "\r\n";
    errorMessage += getExceptionCauses(ex);
    logger.error(errorMessage);
}

From source file:gdt.data.grain.Support.java

/**
 * Get an icon encoded as Base64 string located as file in the class path. 
 * @param handler the class//from w  w  w  .  j  a  v  a 2s . co m
 * @param iconResource$ the name of the icon file.
 * @return input stream.
 */
/*
 public static String readHandlerIcon(Class<?> handler,String icon$) {
    try {
  System.out.println("Support:readHandlerIcon:handler="+handler.getName()+" icon="+icon$);
  //InputStream is=handler.getResourceAsStream(icon$);
  InputStream is= getClassResource(handler,icon$);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = is.read(b)) != -1) {
           bos.write(b, 0, bytesRead);
        }
        byte[] ba = bos.toByteArray();
        is.close();
       return Base64.encodeBase64String(ba);
    } catch (Exception e) {
  Logger.getLogger(gdt.data.grain.Support.class.getName()).severe(e.toString());
    }
    return null;
 }
 */
public static String readHandlerIcon(Entigrator entigrator, Class<?> handler, String iconResource$) {
    try {
        //   System.out.println("Support:readHandlerIcon:handler="+handler.getName()+" icon="+iconResource$);
        //InputStream is=handler.getResourceAsStream(icon$);
        InputStream is = getClassResource(handler, iconResource$);
        if (is != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int bytesRead = 0;
            while ((bytesRead = is.read(b)) != -1) {
                bos.write(b, 0, bytesRead);
            }
            byte[] ba = bos.toByteArray();
            is.close();
            return Base64.encodeBase64String(ba);
        } else {
            if (entigrator == null) {
                System.out.println("Support:readHandlerIcon:entigrator is null");
                return null;
            }
            String[] sa = entigrator.indx_listEntities("entity", "extension");
            if (sa != null) {
                String icon$ = null;
                for (String s : sa) {
                    icon$ = ExtensionHandler.loadIcon(entigrator, s, iconResource$);
                    if (icon$ != null)
                        return icon$;
                }
            }
        }
    } catch (Exception e) {
        Logger.getLogger(gdt.data.grain.Support.class.getName()).severe(e.toString());
    }
    return null;
}

From source file:es.uvigo.ei.sing.jarvest.core.HTTPUtils.java

private static SSLContext createEasySSLContext() {
    try {// w w w  . ja v  a  2  s .  com
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {

        throw new HttpClientError(e.toString());
    }
}