use of com.fasterxml.jackson.core.JsonParseException in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodFail.
@Test
public void createProxyAndCallAsyncMethodFail() throws Exception {
// Expect this exception to be passed back to the callback onFailure and thrown in the future
final JoynrCommunicationException expectedException = new JoynrCommunicationException();
// final JoynCommunicationException expectedException = null;
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), any(ExpiryDate.class));
// pass the exception to the replyCaller
replyCallerCaptor.getValue().error(expectedException);
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
boolean exceptionThrown = false;
String reply = "";
final Future<String> future = proxy.asyncMethod(callback);
try {
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
reply = future.get(1000);
} catch (JoynrCommunicationException e) {
exceptionThrown = true;
}
Assert.assertTrue("exception must be thrown from get", exceptionThrown);
verify(callback).onFailure(expectedException);
verifyNoMoreInteractions(callback);
Assert.assertEquals(RequestStatusCode.ERROR, future.getStatus().getCode());
Assert.assertEquals("", reply);
}
use of com.fasterxml.jackson.core.JsonParseException in project irida by phac-nml.
the class AnalysisController method getSistrAnalysis.
/**
* Get the sistr analysis information to display
*
* @param id ID of the analysis submission
* @return Json results for the SISTR analysis
*/
@SuppressWarnings("resource")
@RequestMapping("/ajax/sistr/{id}")
@ResponseBody
public Map<String, Object> getSistrAnalysis(@PathVariable Long id) {
AnalysisSubmission submission = analysisSubmissionService.read(id);
Collection<Sample> samples = sampleService.getSamplesForAnalysisSubmission(submission);
Map<String, Object> result = ImmutableMap.of("parse_results_error", true);
final String sistrFileKey = "sistr-predictions";
// Get details about the workflow
UUID workflowUUID = submission.getWorkflowId();
IridaWorkflow iridaWorkflow;
try {
iridaWorkflow = workflowsService.getIridaWorkflow(workflowUUID);
} catch (IridaWorkflowNotFoundException e) {
logger.error("Error finding workflow, ", e);
throw new EntityNotFoundException("Couldn't find workflow for submission " + submission.getId(), e);
}
AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
Analysis analysis = submission.getAnalysis();
Path path = analysis.getAnalysisOutputFile(sistrFileKey).getFile();
try {
String json = new Scanner(new BufferedReader(new FileReader(path.toFile()))).useDelimiter("\\Z").next();
// verify file is proper json file
ObjectMapper mapper = new ObjectMapper();
List<Map<String, Object>> sistrResults = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {
});
if (sistrResults.size() > 0) {
// should only ever be one sample for these results
if (samples.size() == 1) {
Sample sample = samples.iterator().next();
result = sistrResults.get(0);
result.put("parse_results_error", false);
result.put("sample_name", sample.getSampleName());
} else {
logger.error("Invalid number of associated samles for submission " + submission);
}
} else {
logger.error("SISTR results for file [" + path + "] are not correctly formatted");
}
} catch (FileNotFoundException e) {
logger.error("File [" + path + "] not found", e);
} catch (JsonParseException | JsonMappingException e) {
logger.error("Error attempting to parse file [" + path + "] as JSON", e);
} catch (IOException e) {
logger.error("Error reading file [" + path + "]", e);
}
}
return result;
}
use of com.fasterxml.jackson.core.JsonParseException in project syndesis by syndesisio.
the class JsonRecordSupport method jsonStreamToRecords.
public static void jsonStreamToRecords(Set<String> indexes, String dbPath, InputStream is, Consumer<JsonRecord> consumer) throws IOException {
try (JsonParser jp = new JsonFactory().createParser(is)) {
jsonStreamToRecords(indexes, jp, dbPath, consumer);
JsonToken jsonToken = jp.nextToken();
if (jsonToken != null) {
throw new JsonParseException(jp, "Document did not terminate as expected.");
}
}
}
use of com.fasterxml.jackson.core.JsonParseException in project debezium by debezium.
the class JacksonReader method parseDocument.
private Document parseDocument(JsonParser parser, boolean nested) throws IOException {
// Iterate over the fields in the top-level document ...
BasicDocument doc = new BasicDocument();
JsonToken token = null;
if (!nested) {
// We expect the START_OBJECT token ...
token = parser.nextToken();
if (!nested && token != JsonToken.START_OBJECT) {
throw new IOException("Expected data to start with an Object, but was " + token);
}
}
String fieldName = null;
token = parser.nextToken();
while (token != JsonToken.END_OBJECT) {
switch(token) {
case FIELD_NAME:
fieldName = parser.getCurrentName();
break;
case START_OBJECT:
doc.setDocument(fieldName, parseDocument(parser, true));
break;
case START_ARRAY:
doc.setArray(fieldName, parseArray(parser, true));
break;
case VALUE_STRING:
doc.setString(fieldName, parser.getValueAsString());
break;
case VALUE_TRUE:
doc.setBoolean(fieldName, true);
break;
case VALUE_FALSE:
doc.setBoolean(fieldName, false);
break;
case VALUE_NULL:
doc.setNull(fieldName);
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
switch(parser.getNumberType()) {
case FLOAT:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getFloatValue());
}
break;
case DOUBLE:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getDoubleValue());
}
break;
case BIG_DECIMAL:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getDecimalValue());
}
break;
case INT:
doc.setNumber(fieldName, parser.getIntValue());
break;
case LONG:
doc.setNumber(fieldName, parser.getLongValue());
break;
case BIG_INTEGER:
doc.setNumber(fieldName, parser.getBigIntegerValue());
break;
}
break;
case VALUE_EMBEDDED_OBJECT:
// disregard this, since it's an extension ...
break;
case NOT_AVAILABLE:
throw new JsonParseException(parser, "Non-blocking parsers are not supported", parser.getCurrentLocation());
case END_ARRAY:
throw new JsonParseException(parser, "Not expecting an END_ARRAY token", parser.getCurrentLocation());
case END_OBJECT:
throw new JsonParseException(parser, "Not expecting an END_OBJECT token", parser.getCurrentLocation());
}
token = parser.nextToken();
}
return doc;
}
use of com.fasterxml.jackson.core.JsonParseException in project debezium by debezium.
the class JacksonReader method parseArray.
private Array parseArray(JsonParser parser, boolean nested) throws IOException {
// Iterate over the values in the array ...
BasicArray array = new BasicArray();
JsonToken token = null;
if (!nested) {
// We expect the START_ARRAY token ...
token = parser.nextToken();
if (!nested && token != JsonToken.START_ARRAY) {
throw new IOException("Expected data to start with an Array, but was " + token);
}
}
token = parser.nextToken();
while (token != JsonToken.END_ARRAY) {
switch(token) {
case START_OBJECT:
array.add(parseDocument(parser, true));
break;
case START_ARRAY:
array.add(parseArray(parser, true));
break;
case VALUE_STRING:
array.add(parser.getValueAsString());
break;
case VALUE_TRUE:
array.add(true);
break;
case VALUE_FALSE:
array.add(false);
break;
case VALUE_NULL:
array.addNull();
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
switch(parser.getNumberType()) {
case FLOAT:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getFloatValue());
}
break;
case DOUBLE:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getDoubleValue());
}
break;
case BIG_DECIMAL:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getDecimalValue());
}
break;
case INT:
array.add(parser.getIntValue());
break;
case LONG:
array.add(parser.getLongValue());
break;
case BIG_INTEGER:
array.add(parser.getBigIntegerValue());
break;
}
break;
case VALUE_EMBEDDED_OBJECT:
// disregard this, since it's an extension ...
break;
case NOT_AVAILABLE:
throw new JsonParseException(parser, "Non-blocking parsers are not supported", parser.getCurrentLocation());
case FIELD_NAME:
throw new JsonParseException(parser, "Not expecting a FIELD_NAME token", parser.getCurrentLocation());
case END_ARRAY:
throw new JsonParseException(parser, "Not expecting an END_ARRAY token", parser.getCurrentLocation());
case END_OBJECT:
throw new JsonParseException(parser, "Not expecting an END_OBJECT token", parser.getCurrentLocation());
}
token = parser.nextToken();
}
return array;
}
Aggregations