List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace
public void printStackTrace()
From source file:com.mejmo.appletraus.client.service.AtmosphereService.java
public void connectAtmosphere(String baseUrl, final AppletRausInstanceProxy applet, String sessionId) { AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class); final ObjectMapper mapper = new ObjectMapper(); RequestBuilder request = client.newRequestBuilder().method(Request.METHOD.GET) .uri(baseUrl + "/appletraus-boot/appletraus?sessionId=" + sessionId) .encoder(new Encoder<Message, String>() { // Stream the request body @Override/*from w w w. j a v a2 s. c o m*/ public String encode(Message s) { try { return mapper.writeValueAsString(s); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }).decoder(new Decoder<String, Message>() { @Override public Message decode(Event type, String s) { Message message; if (type != Event.MESSAGE || s.trim().length() == 0) return null; try { message = mapper.readValue(s, Message.class); } catch (IOException e) { logger.error("Cannot decode JSON message: " + s); return null; } return message; } }).transport(Request.TRANSPORT.WEBSOCKET).transport(Request.TRANSPORT.LONG_POLLING) .trackMessageLength(true); final Socket socket = client.create(); try { socket.on(Event.CLOSE.name(), new Function<String>() { @Override public void on(String t) { logger.info("Atmosphere resource closed. Existing JNLP application"); System.exit(0); } }).on(Event.REOPENED.name(), new Function<String>() { @Override public void on(String t) { } }).on(Event.MESSAGE.name(), new Function<Message>() { @Override public void on(Message t) { logger.info("Got message"); if (t.getMessageType() == MessageType.METHOD_CALL) { try { Object ret = applet.invokeMethod(t.getMethod(), t.getParameters()); t.setMessageType(MessageType.METHOD_RESULT); t.setResult(mapper.writeValueAsString(ret)); } catch (IllegalAccessException | InvocationTargetException | JsonProcessingException e) { throw new AppletRausException("Error occured while invoking the method", e); } try { socket.fire(t); } catch (IOException e) { throw new AppletRausException("Error occured while sending method result", e); } } if (t.getMessageType() == MessageType.DISCONNECT) { logger.info("DISCONNECT message received. Existing JNLP application"); System.exit(0); } } }).on(new Function<IOException>() { @Override public void on(IOException ioe) { ioe.printStackTrace(); } }).on(Event.OPEN.name(), new Function<String>() { @Override public void on(String t) { logger.info("Atmosphere connection established."); Message message = new Message(); message.setMessageType(MessageType.GET_AVAILABLE_METHODS); message.getAppletMethodList().addAll(applet.getMappedMethodNames()); try { socket.fire(message); } catch (IOException e) { e.printStackTrace(); } } }).open(request.build()).fire("echo").fire("bong"); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java
public void testSetChoiceList() { ArrayList<Object> values = new ArrayList<Object>(); Map<String, Object> myMap = new TreeMap<String, Object>(); Map<String, Object> displayText = new TreeMap<String, Object>(); displayText.put("text", "displayText"); myMap.put("choice_list_name", "test_list"); myMap.put("data_value", "test"); myMap.put("display", displayText); values.add(myMap);/*ww w .j a va 2 s . c o m*/ ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, null, activeUser, RoleConsts.ADMIN_ROLES_LIST); String jsonChoiceList = null; try { jsonChoiceList = ODKFileUtils.mapper.writeValueAsString(values); } catch (JsonProcessingException e) { e.printStackTrace(); } String choiceListId = ODKDatabaseImplUtils.get().setChoiceList(db, jsonChoiceList); // Select the _choice_list_id from the _choice_lists table String sel = "SELECT * FROM " + DatabaseConstants.CHOICE_LIST_TABLE_NAME + " WHERE " + ChoiceListColumns.CHOICE_LIST_ID + " = ?"; String[] selArgs = { "" + choiceListId }; Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext); assertEquals(cursor.getCount(), 1); String val = null; while (cursor.moveToNext()) { int ind = cursor.getColumnIndex(ChoiceListColumns.CHOICE_LIST_JSON); int type = cursor.getType(ind); assertEquals(type, Cursor.FIELD_TYPE_STRING); val = cursor.getString(ind); } assertEquals(val, jsonChoiceList); }
From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java
public void testGetChoiceList_ExpectPass() { ArrayList<Object> values = new ArrayList<Object>(); Map<String, Object> myMap = new TreeMap<String, Object>(); Map<String, Object> displayText = new TreeMap<String, Object>(); displayText.put("text", "displayText"); myMap.put("choice_list_name", "test_list"); myMap.put("data_value", "test"); myMap.put("display", displayText); values.add(myMap);//from w w w .j a v a2 s. c o m String jsonChoiceList = null; try { jsonChoiceList = ODKFileUtils.mapper.writeValueAsString(values); } catch (JsonProcessingException e) { e.printStackTrace(); } // Set the choice list id String choiceListId = ODKDatabaseImplUtils.get().setChoiceList(db, jsonChoiceList); // Get the choice list String retJsonChoiceList = ODKDatabaseImplUtils.get().getChoiceList(db, choiceListId); assertEquals(jsonChoiceList, retJsonChoiceList); ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, null, activeUser, RoleConsts.ADMIN_ROLES_LIST); // Select the _choice_list_id from the _choice_lists table String sel = "SELECT * FROM " + DatabaseConstants.CHOICE_LIST_TABLE_NAME + " WHERE " + ChoiceListColumns.CHOICE_LIST_ID + " = ?"; String[] selArgs = { "" + choiceListId }; Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext); assertEquals(cursor.getCount(), 1); String val = null; while (cursor.moveToNext()) { int ind = cursor.getColumnIndex(ChoiceListColumns.CHOICE_LIST_JSON); int type = cursor.getType(ind); assertEquals(type, Cursor.FIELD_TYPE_STRING); val = cursor.getString(ind); } assertEquals(val, retJsonChoiceList); }
From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java
@Test public void testSetChoiceList() { ArrayList<Object> values = new ArrayList<Object>(); Map<String, Object> myMap = new TreeMap<String, Object>(); Map<String, Object> displayText = new TreeMap<String, Object>(); displayText.put("text", "displayText"); myMap.put("choice_list_name", "test_list"); myMap.put("data_value", "test"); myMap.put("display", displayText); values.add(myMap);/* ww w .ja va2s . c o m*/ ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, null, activeUser, RoleConsts.ADMIN_ROLES_LIST); String jsonChoiceList = null; try { jsonChoiceList = ODKFileUtils.mapper.writeValueAsString(values); } catch (JsonProcessingException e) { e.printStackTrace(); } String choiceListId = ODKDatabaseImplUtils.get().setChoiceList(db, jsonChoiceList); // Select the _choice_list_id from the _choice_lists table String sel = "SELECT * FROM " + DatabaseConstants.CHOICE_LIST_TABLE_NAME + " WHERE " + ChoiceListColumns.CHOICE_LIST_ID + " = ?"; String[] selArgs = { "" + choiceListId }; Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext); assertEquals(cursor.getCount(), 1); String val = null; while (cursor.moveToNext()) { int ind = cursor.getColumnIndex(ChoiceListColumns.CHOICE_LIST_JSON); int type = cursor.getType(ind); assertEquals(type, Cursor.FIELD_TYPE_STRING); val = cursor.getString(ind); } assertEquals(val, jsonChoiceList); }
From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java
@Test public void testGetChoiceList_ExpectPass() { ArrayList<Object> values = new ArrayList<Object>(); Map<String, Object> myMap = new TreeMap<String, Object>(); Map<String, Object> displayText = new TreeMap<String, Object>(); displayText.put("text", "displayText"); myMap.put("choice_list_name", "test_list"); myMap.put("data_value", "test"); myMap.put("display", displayText); values.add(myMap);//from w w w . ja v a 2 s. c o m String jsonChoiceList = null; try { jsonChoiceList = ODKFileUtils.mapper.writeValueAsString(values); } catch (JsonProcessingException e) { e.printStackTrace(); } // Set the choice list id String choiceListId = ODKDatabaseImplUtils.get().setChoiceList(db, jsonChoiceList); // Get the choice list String retJsonChoiceList = ODKDatabaseImplUtils.get().getChoiceList(db, choiceListId); assertEquals(jsonChoiceList, retJsonChoiceList); ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, null, activeUser, RoleConsts.ADMIN_ROLES_LIST); // Select the _choice_list_id from the _choice_lists table String sel = "SELECT * FROM " + DatabaseConstants.CHOICE_LIST_TABLE_NAME + " WHERE " + ChoiceListColumns.CHOICE_LIST_ID + " = ?"; String[] selArgs = { "" + choiceListId }; Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext); assertEquals(cursor.getCount(), 1); String val = null; while (cursor.moveToNext()) { int ind = cursor.getColumnIndex(ChoiceListColumns.CHOICE_LIST_JSON); int type = cursor.getType(ind); assertEquals(type, Cursor.FIELD_TYPE_STRING); val = cursor.getString(ind); } assertEquals(val, retJsonChoiceList); }
From source file:ca.oson.json.Oson.java
public <T> String serialize(T source, Class<T> valueType) { JSON_PROCESSOR processor = getJsonProcessor(); // should not reach here, just for reference if (processor == JSON_PROCESSOR.JACKSON) { try {// www . j a v a 2 s .com return getJackson().writeValueAsString(source); } catch (JsonProcessingException e) { if (getPrintErrorUseOsonInFailure()) { e.printStackTrace(); } else { throw new RuntimeException(e); } } } else if (processor == JSON_PROCESSOR.GSON) { try { return getGson().toJson(source, valueType); } catch (Exception e) { if (getPrintErrorUseOsonInFailure()) { e.printStackTrace(); } else { throw new RuntimeException(e); } } } if (valueType == null) { valueType = (Class<T>) source.getClass(); } String value = object2Json(new FieldData(source, valueType, false)); if (value == null) { return "null"; } return value; }
From source file:ca.oson.json.Oson.java
public <T> String serialize(T source, Type type) { JSON_PROCESSOR processor = getJsonProcessor(); // should not reach here, just for reference if (processor == JSON_PROCESSOR.JACKSON) { try {/* w ww .j a va2 s . c o m*/ return getJackson().writeValueAsString(source); } catch (JsonProcessingException e) { if (getPrintErrorUseOsonInFailure()) { e.printStackTrace(); } else { throw new RuntimeException(e); } } } else if (processor == JSON_PROCESSOR.GSON) { try { return getGson().toJson(source, type); } catch (Exception e) { if (getPrintErrorUseOsonInFailure()) { e.printStackTrace(); } else { throw new RuntimeException(e); } } } Class<T> valueType = null; ComponentType componentType = null; if (type != null) { if (ComponentType.class.isAssignableFrom(type.getClass())) { componentType = (ComponentType) type; } else { componentType = new ComponentType(type); } valueType = componentType.getClassType(); } if (valueType == null) { valueType = (Class<T>) source.getClass(); } return object2Json(new FieldData(source, valueType, componentType, false)); }