Example usage for java.lang Exception printStackTrace

List of usage examples for java.lang Exception printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.ucsd.ccdb.cil.xml2json.ElasticsearchClient.java

public static void main(String[] args) throws Exception {
    try {/*from  w  ww.ja  v  a 2s.c o  m*/
        DefaultHttpClient httpClient = new DefaultHttpClient();

        //HttpPut put = new HttpPut("http://localhost:9200/customer/user/john@smith.com");  //-X PUT
        //put.setEntity(new FileEntity(new File("/Users/ncmir/NetBeansProjects/MyTest/web/customer.json"), "application/json"));  //@ - absolute path
        HttpPut put = new HttpPut("http://localhost:9200/ccdb/data/1"); //-X PUT
        put.setEntity(
                new FileEntity(new File("/Users/ncmir/Documents/CCDB/ccdbJson/1.json"), "application/json")); //@ - absolute path

        BasicResponseHandler responseHandler = new BasicResponseHandler();

        String o = httpClient.execute(put, responseHandler);
        System.out.println(o);
    } catch (Exception e) {
        //-f, fail silently
        e.printStackTrace();
    }
}

From source file:DescribeMObject.java

public static void main(String[] args) {

    System.out.println("Executing Describe MObject");
    try {//from  w  w  w.  ja  v  a 2 s. c o m
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsDescribeMObject request = new ParamsDescribeMObject();
        request.setObjectName("ActivityRecord");

        SuccessDescribeMObject result = port.describeMObject(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessDescribeMObject.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SerializeJavaObjects_MySQL.java

public static void main(String args[]) throws Exception {
    Connection conn = null;/*from   w  ww .j  a v a  2s  . c om*/
    try {
        conn = getConnection();
        System.out.println("conn=" + conn);
        conn.setAutoCommit(false);
        List<Object> list = new ArrayList<Object>();
        list.add("This is a short string.");
        list.add(new Integer(1234));
        list.add(new Date());

        long objectID = writeJavaObject(conn, list);
        conn.commit();
        System.out.println("Serialized objectID => " + objectID);
        List listFromDatabase = (List) readJavaObject(conn, objectID);
        System.out.println("[After De-Serialization] list=" + listFromDatabase);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        conn.close();
    }
}

From source file:XMLTransform.java

public static void main(String args[]) {

    if (args.length != 2) {
        System.err.println("Usage: java XMLTransform xmlfile.xml stylesheet.xsl");
        System.exit(-1);//from   www  . j a  v a 2 s.  c o m
    }

    try {
        StreamSource source = new StreamSource(args[0]);
        StreamSource stylesource = new StreamSource(args[1]);

        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer(stylesource);

        StreamResult result = new StreamResult(System.out);
        transformer.transform(source, result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:LoggingExample1.java

public static void main(String args[]) {
    try {//from  w w  w.  j  av  a  2s.  c o  m
        LogManager lm = LogManager.getLogManager();
        Logger logger;
        FileHandler fh = new FileHandler("log_test.txt");

        logger = Logger.getLogger("LoggingExample1");

        lm.addLogger(logger);
        logger.setLevel(Level.INFO);
        fh.setFormatter(new XMLFormatter());

        logger.addHandler(fh);
        //logger.setUseParentHandlers(false);
        logger.log(Level.INFO, "test 1");
        logger.log(Level.INFO, "test 2");
        logger.log(Level.INFO, "test 3");
        fh.close();
    } catch (Exception e) {
        System.out.println("Exception thrown: " + e);
        e.printStackTrace();
    }
}

From source file:com.baomidou.mybatisplus.test.MybatisMapperRefreshTest.java

/**
 *  Mybatis XML //  ww  w.j a  va2s.c o  m
 */
public static void main(String[] args) throws IOException, InterruptedException {
    InputStream in = UserMapperTest.class.getClassLoader().getResourceAsStream("mysql-config.xml");
    MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
    mf.setGlobalConfig(new GlobalConfiguration(new MySqlInjector()));
    Resource[] resource = new ClassPathResource[] { new ClassPathResource("mysql/UserMapper.xml") };
    SqlSessionFactory sessionFactory = mf.build(in);
    new MybatisMapperRefresh(resource, sessionFactory, 0, 5, true);
    boolean isReturn = false;
    SqlSession session = null;
    while (!isReturn) {
        try {
            session = sessionFactory.openSession();
            UserMapper userMapper = session.getMapper(UserMapper.class);
            userMapper.selectListRow(new Pagination(1, 10));
            resource[0].getFile().setLastModified(SystemClock.now());
            session.commit();
            session.close();
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null) {
                session.close();
            }
            Thread.sleep(5000);
        }
    }
    System.exit(0);
}

From source file:SearchWithFilterObjs.java

public static void main(String[] args) {

    // Set up the environment for creating the initial context
    Hashtable<String, Object> env = new Hashtable<String, Object>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

    try {/*from  w w  w  .ja  v  a  2s  . c  o  m*/
        // Create initial context
        DirContext ctx = new InitialDirContext(env);

        // Specify the ids of the attributes to return
        String[] attrIDs = { "sn", "telephonenumber", "golfhandicap", "mail" };
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes(attrIDs);

        // Specify the search filter to match
        // Ask for objects with attribute sn == Geisel and which have
        // the "mail" attribute.
        String filter = "(&(sn={0})(mail=*))";

        // Search for objects using filter
        NamingEnumeration answer = ctx.search("ou=People", filter, new Object[] { "Geisel" }, ctls);

        // Print the answer
        // Search.printSearchEnumeration(answer);

        // Close the context when we're done
        ctx.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SearchWithFilter.java

public static void main(String[] args) {

    // Set up the environment for creating the initial context
    Hashtable<String, Object> env = new Hashtable<String, Object>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

    try {//from  ww  w  .j a v a  2 s .c o  m
        // Create initial context
        DirContext ctx = new InitialDirContext(env);

        // Specify the ids of the attributes to return
        String[] attrIDs = { "sn", "telephonenumber", "golfhandicap", "mail" };
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes(attrIDs);

        // Specify the search filter to match
        // Ask for objects with attribute sn == Geisel and which have
        // the "mail" attribute.
        String filter = "(&(sn=Geisel)(mail=*))";

        // Search for objects using filter
        NamingEnumeration answer = ctx.search("ou=People", filter, ctls);

        // Print the answer
        // Search.printSearchEnumeration(answer);

        // Close the context when we're done
        ctx.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ch.windmobile.server.socialmodel.mogodb.HeavyLoadTest.java

public static void main(String[] args) {
    try {/*from w  w  w. ja va 2  s .c o m*/
        HeavyLoadTest test = new HeavyLoadTest();
        test.beforeTest();
        long before = System.nanoTime();
        test.testFullChatCycle();
        System.out.println("Time : " + TimeUnit.NANOSECONDS.toMicros((System.nanoTime() - before)) + " s");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zergiu.tvman.TVMan.java

public static void main(String[] args) {
    try {/*from   w  w  w  .ja v a  2  s.co  m*/
        TVManOptions options = TVManOptions.getInstance();
        options.parseCommandLine(args);
        configureLoggers(options);
        log.info("Starting TVMan .... ");
        final TVManWebServer server = new TVManWebServer();
        addShutdownHook(server);
        startServer(server);
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
    }
}