List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace
public void printStackTrace()
From source file:com.easarrive.aws.plugins.common.service.impl.TestSNSService.java
@Test public void aaa() { // String message = // "{\"Records\":[{\"eventVersion\":\"2.0\",\"eventSource\":\"aws:s3\",\"awsRegion\":\"us-west-2\",\"eventTime\":\"2016-06-28T12:59:55.700Z\",\"eventName\":\"ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"AFRDGXV7XRMK5\"},\"requestParameters\":{\"sourceIPAddress\":\"124.205.19.130\"},\"responseElements\":{\"x-amz-request-id\":\"CA17C6B0CA3B9D5B\",\"x-amz-id-2\":\"8OnEzpN3a49R+oHXc+BXDRGEaLRjgM9sygcuNhg+G2g6FNWxK9CkE1vaxJhc+WiW\"},\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"test\",\"bucket\":{\"name\":\"etago-app-dev\",\"ownerIdentity\":{\"principalId\":\"AFRDGXV7XRMK5\"},\"arn\":\"arn:aws:s3:::etago-app-dev\"},\"object\":{\"key\":\"users/image/22.jpg\",\"size\":4006886,\"eTag\":\"229f0eddc267a22e02d938e294ebd7e5\",\"sequencer\":\"00577274CB93A5D229\"}}}]}"; String message = "{\"Service\":\"Amazon S3\",\"Event\":\"s3:TestEvent\",\"Time\":\"2016-06-29T09:35:00.087Z\",\"Bucket\":\"etago-app-dev\",\"RequestId\":\"3AFC2B9075E9D4F1\",\"HostId\":\"aNL0geUz8N1uvZwQZ9mEdphu3wOYpvYCt9FiHIDTKzAEUjF6xXuOzybqRItfVtLc\"}"; ObjectMapper mapper = JsonUtil.getInstance(); try {// ww w. j a v a 2 s .co m if (StringUtil.isEmpty(message)) { return; } JsonNode jsonNode = mapper.readTree(message); if (jsonNode == null) { return; } JsonNode recordsJsonNode = jsonNode.get("Records"); if (recordsJsonNode == null) { return; } Iterator<JsonNode> recordsJsonNodeI = recordsJsonNode.elements(); if (recordsJsonNodeI == null) { return; } while (recordsJsonNodeI.hasNext()) { JsonNode recordJsonNode = recordsJsonNodeI.next(); if (recordJsonNode == null) { continue; } JsonNode eventVersion = recordJsonNode.get("eventVersion"); System.out.println(eventVersion.asText()); JsonNode eventSource = recordJsonNode.get("eventSource"); System.out.println(eventSource.asText()); JsonNode eventName = recordJsonNode.get("eventName"); System.out.println(eventName.asText()); } } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.baidubce.services.bmr.BmrClientTest.java
@Test public void testCreateCluster() { CreateClusterResponse response = this.bmrClient.createCluster(new CreateClusterRequest() .withName(this.clusterName).withImageType(this.imageType).withImageVersion(this.imageVersion) .withAutoTerminate(this.autoTerminate).withLogUri(this.logUri) .withInstanceGroup(new InstanceGroupConfig().withType("Master").withInstanceType("g.small") .withInstanceCount(1)) .withInstanceGroup(/*from www.ja v a 2s . com*/ new InstanceGroupConfig().withType("Core").withInstanceType("g.small").withInstanceCount(2)) .withStep(new JavaStepConfig().withName("init-step").withActionOnFailure("Continue") .withJar("bos://bmr/samples/mapreduce/libs/hadoop-mapreduce-examples.jar") .withMainClass("org.apache.hadoop.examples.WordCount") .withArguments("bos://bmr/samples/mapreduce/wordcount/hamlet.txt bos://liukun01/out"))); try { System.out.println(JsonUtils.toJsonPrettyString(response)); } catch (JsonProcessingException e) { e.printStackTrace(); } assertThat(response, hasProperty("clusterId")); this.clusterId = response.getClusterId(); testAddStep(); testGetStep(); testListSteps(); }
From source file:org.apache.hadoop.gateway.services.registry.impl.DefaultServiceRegistryService.java
private String renderAsJsonString(HashMap<String, HashMap<String, RegEntry>> registry) { String json = null;//from ww w . j a va 2 s. c o m ObjectMapper mapper = new ObjectMapper(); try { // write JSON to a file json = mapper.writeValueAsString((Object) registry); } catch (JsonProcessingException e) { e.printStackTrace(); //TODO: I18N } return json; }
From source file:api.QuizResource.java
@GET @Path("question/{chapter}/{number}") @Produces(MediaType.APPLICATION_JSON)//from w w w . j a v a 2 s. c o m public String getSpecificQuestion(@PathParam("chapter") Integer chapter, @PathParam("number") Integer number) { // if(!userBean.isLoggedIn()) { // return null; // } // ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(quizBean.lookupQuestion(chapter, number)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return ""; }
From source file:api.QuizResource.java
@GET @Path("check/{chapter}/{number}") @Produces(MediaType.APPLICATION_JSON)/*from w w w .ja v a 2s . c o m*/ public String checkAnswer(@PathParam("chapter") Integer chapter, @PathParam("number") Integer number, @QueryParam("answer") List<String> answers) { boolean result = quizBean.checkAnswer(chapter, number, answers); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(Collections.singletonMap("isCorrect", result)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return jsonError("Unknown json failure :("); }
From source file:api.QuizResource.java
/** * Retrieves representation of an instance of api.QuizResource * @return an instance of java.lang.String *//*from w w w.j a v a2 s . c om*/ @GET @Path("{chapter}") @Produces(MediaType.APPLICATION_JSON) public String getAllChapterQuestions(@PathParam("chapter") Integer chapter) { // if(!userBean.isLoggedIn()) { // return null; // } // ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(quizBean.lookupQuestionsByChapter(chapter)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return ""; }
From source file:api.QuizResource.java
@GET @Path("{chapter}/{section}") @Produces(MediaType.APPLICATION_JSON)//from ww w .j ava 2s . c om public String getAllSectionQuestions(@PathParam("chapter") Integer chapter, @PathParam("section") Integer section) { // if(!userBean.isLoggedIn()) { // return null; // } // ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(quizBean.lookupQuestionsBySection(chapter, section)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return ""; }
From source file:api.QuizResource.java
@GET @Path("userstatus/{chapter}/{number}/{username}") @Produces(MediaType.APPLICATION_JSON)/* w w w .ja v a2 s . com*/ public String getUserAnswerStatus(@PathParam("chapter") Integer chapter, @PathParam("number") Integer number, @PathParam("username") String username) { int status = quizBean.answerStatus(chapter, number, username); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString( Collections.singletonMap("answerStatus", QuizQuestion.statusToString(status))); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return jsonError("Unknown json failure :("); }
From source file:api.QuizResource.java
@GET @Path("submit/{chapter}/{number}") @Produces(MediaType.APPLICATION_JSON)// w w w . j a v a2 s . co m public String submitAnswer(@PathParam("chapter") Integer chapter, @PathParam("number") Integer number, @QueryParam("answer") List<String> answers) { if (!userBean.isLoggedIn()) { return jsonError("Gotta be logged in bruv."); } boolean result = quizBean.submitAnswer(chapter, number, answers, userBean); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(Collections.singletonMap("isCorrect", result)); } catch (JsonProcessingException ex) { ex.printStackTrace(); } return jsonError("Unknown json failure :("); }
From source file:org.n52.tamis.core.test.serialize.ExecuteInputSerializer_Test.java
@Test public void testDataInputSerialization() { try {// ww w. j a v a 2 s . co m String dataJsonOutput = mapper.writeValueAsString(dataInput); JsonNode parsedJsonData = mapper.readTree(dataJsonOutput); JsonNode dataNode = parsedJsonData.get("Data"); Assert.assertTrue(dataNode.has("_text")); Assert.assertTrue(parsedJsonData.has("_id")); Assert.assertEquals( "[0.03550405161598, -0.01860639146241, -0.01860639146241, -0.03550405161598, 385795.23669382796000, 5667086.67852447180000]", dataNode.get("_text").asText()); Assert.assertEquals("dataInputID", parsedJsonData.get("_id").asText()); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }