List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void main(String args[]) { try {//w ww.j a v a 2 s .co m MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("test"); System.out.println("Connect to database successfully"); boolean auth = db.authenticate("myUser", "myPassword".toCharArray()); System.out.println("Authentication: " + auth); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:Main.java
public static void main(String args[]) { try {//from ww w . j ava2 s . c o m MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("test"); System.out.println("Connect to database successfully"); boolean auth = db.authenticate("myUserName", "myPassword".toCharArray()); System.out.println("Authentication: " + auth); DBCollection coll = db.createCollection("mycol", null); System.out.println("Collection created successfully"); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w. j a va2s . com*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("test"); System.out.println("Connect to database successfully"); boolean auth = db.authenticate("myUserName", "myPassword".toCharArray()); System.out.println("Authentication: " + auth); DBCollection coll = db.createCollection("mycol", null); System.out.println("Collection created successfully"); coll = db.getCollection("mycol"); System.out.println("Collection mycol selected successfully"); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:Main.java
public static void main(String args[]) { try {//w w w. jav a 2 s . co m MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("test"); System.out.println("Connect to database successfully"); boolean auth = db.authenticate("myUserName", "myPassword".toCharArray()); System.out.println("Authentication: " + auth); DBCollection coll = db.getCollection("mycol"); System.out.println("Collection mycol selected successfully"); BasicDBObject doc = new BasicDBObject("title", "MongoDB").append("description", "database") .append("likes", 100).append("url", "http://www.java2s.com"); coll.insert(doc); System.out.println("Document inserted successfully"); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:luceneindexer.Main.java
/** * @param args the command line arguments */// ww w . j a v a 2 s . c o m public static void main(String[] args) { // TODO code application logic here System.out.println("Hello world"); //Open the file of JSON for reading FileOpener fOpener = new FileOpener("parks.json"); //Create the object for writing LuceneWriter luceneWriter = new LuceneWriter("indexDir"); //This is from Jackson which allows for binding the JSON to the Park.java class ObjectMapper objectMapper = new ObjectMapper(); try { //first see if we can open a directory for writing if (luceneWriter.openIndex()) { //get a buffered reader handle to the file BufferedReader breader = new BufferedReader(fOpener.getFileForReading()); String value = null; //loop through the file line by line and parse while ((value = breader.readLine()) != null) { Park park = objectMapper.readValue(value, Park.class); //now submit each park to the lucene writer to add to the index luceneWriter.addPark(park); } } else { System.out.println("We had a problem opening the directory for writing"); } } catch (Exception e) { System.out.println("Threw exception " + e.getClass() + " :: " + e.getMessage()); } finally { //close out the index and release the lock on the file luceneWriter.finish(); } }
From source file:com.dhenton9000.jersey.client.JerseyClientExplorer.java
public static void main(String[] args) { try {//ww w. j a va2 s. com (new JerseyClientExplorer()).doErrorThing(); } catch (Exception err) { LOG.error("main error " + err.getClass().getName() + " " + err.getMessage()); } }
From source file:spatialluceneindexer.Main.java
/** * @param args the command line arguments */// w ww . j av a 2s . c om public static void main(String[] args) { System.out.println("Starting to create the index"); //Open the file of JSON for reading FileOpener fOpener = new FileOpener("parks.json"); //Create the object for writing LuceneWriter luceneWriter = new LuceneWriter("indexDir"); //This is from Jackson which allows for binding the JSON to the Park.java class ObjectMapper objectMapper = new ObjectMapper(); try { //first see if we can open a directory for writing if (luceneWriter.openIndex()) { //get a buffered reader handle to the file BufferedReader breader = new BufferedReader(fOpener.getFileForReading()); String value = null; //loop through the file line by line and parse while ((value = breader.readLine()) != null) { Park park = objectMapper.readValue(value, Park.class); //now submit each park to the lucene writer to add to the index luceneWriter.addPark(park); } } else { System.out.println("We had a problem opening the directory for writing"); } } catch (Exception e) { System.out.println("Threw exception " + e.getClass() + " :: " + e.getMessage()); } finally { luceneWriter.finish(); } System.out.println("Finished created the index"); }
From source file:de.oth.keycloak.TestRun.java
public static void main(String[] args) { try {/* ww w. ja v a2 s .c o m*/ String server = "http://localhost:8888/auth"; String realm = "master"; String user = "keycloak_admin"; String pwd = "k6ycloakAdmin"; String clientStr = "admin-cli"; String secret = null; String initFileStr = "conf/test_init1.json"; File initFile = new File(initFileStr); if (!initFile.isFile()) { URL url = TestRun.class.getClassLoader().getResource(initFileStr); if (url != null) { initFile = new File(url.getFile()); if (!initFile.isFile()) { log.error("init file does not exist: " + initFile); System.exit(1); } } else { log.error("init file does not exist: " + initFile); System.exit(1); } } Keycloak keycloak = (secret == null) ? Keycloak.getInstance(server, realm, user, pwd, clientStr) : Keycloak.getInstance(server, realm, user, pwd, clientStr, secret); ObjectMapper mapper = new ObjectMapper(); RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class); if (realmsConfig != null) { List<RealmConfig> realmList = realmsConfig.getRealms(); if (realmList == null || realmList.isEmpty()) { log.error("no realms config found 1"); return; } for (RealmConfig realmConf : realmList) { InitKeycloakServer.addRealm(keycloak, realmConf); } } else log.error("no realms config found 2"); } catch (Exception e) { log.error(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:lab.home.spring.redis.test.SpringRedisTest.java
public static void main(String argv[]) { ApplicationContext ctx = new AnnotationConfigApplicationContext(RedisTestConfig.class); DictionaryDao ddao = ctx.getBean(DictionaryDao.class); try {//from ww w.j a v a2 s. c om System.out.println("ddao.setValue(\"key1\", \"value1\")"); ddao.setValue("key1", "value1"); System.out.println("ddao.setValue(\"testkey\", \"testvalue\")"); ddao.setValue("testkey", "testvalue"); System.out.println("getting value for key1 = " + ddao.getValue("key1")); System.out.println("getting value for testkey = " + ddao.getValue("testkey")); } catch (Exception e) { System.out.println(e); System.out.println(e.fillInStackTrace()); System.out.println(e.getCause()); System.out.println(e.getClass()); System.out.println(e.getStackTrace()); e.printStackTrace(); } }
From source file:net.modelbased.proasense.storage.registry.StorageRegistrySensorDataTestClient.java
public static void main(String[] args) { // Get client properties from properties file // StorageRegistrySensorDataTestClient client = new StorageRegistrySensorDataTestClient(); // client.loadClientProperties(); // Hardcoded client properties (simple test client) String STORAGE_REGISTRY_SERVICE_URL = "http://192.168.84.34:8080/storage-registry"; // Default HTTP client and common properties for requests HttpClient client = new DefaultHttpClient(); StringBuilder requestUrl = null; List<NameValuePair> params = null; String queryString = null;//from w ww. jav a 2s . c o m // Default HTTP response and common properties for responses HttpResponse response = null; ResponseHandler<String> handler = null; int status = 0; String body = null; // Query for sensor list requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL); requestUrl.append("/query/sensor/list"); try { HttpGet query21 = new HttpGet(requestUrl.toString()); query21.setHeader("Content-type", "application/json"); response = client.execute(query21); // Check status code status = response.getStatusLine().getStatusCode(); if (status != 200) { throw new RuntimeException("Failed! HTTP error code: " + status); } // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SENSOR LIST: " + body); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } // Query for sensor properties requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL); requestUrl.append("/query/sensor/properties"); params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("sensorId", "visualInspection")); queryString = URLEncodedUtils.format(params, "utf-8"); requestUrl.append("?"); requestUrl.append(queryString); try { HttpGet query22 = new HttpGet(requestUrl.toString()); query22.setHeader("Content-type", "application/json"); response = client.execute(query22); // Check status code status = response.getStatusLine().getStatusCode(); if (status != 200) { throw new RuntimeException("Failed! HTTP error code: " + status); } // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SENSOR PROPERTIES: " + body); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } }