Search in sources :

Example 31 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.

the class ParserErrorHandlingTest method _testMangledNumbersFloat.

private void _testMangledNumbersFloat(int mode) throws Exception {
    // Also test with floats
    JsonParser p = createParser(mode, "1.5false");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 32 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.

the class ParserErrorHandlingTest method _testMangledNumbersInt.

private void _testMangledNumbersInt(int mode) throws Exception {
    JsonParser p = createParser(mode, "123true");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 33 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.

the class AsyncNumberCoercionTest method testToLongFailing.

public void testToLongFailing() throws Exception {
    AsyncReaderWrapper p;
    // BigInteger -> error
    BigInteger big = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
    p = createParser(String.valueOf(big));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(NumberType.BIG_INTEGER, p.getNumberType());
    assertEquals(big, p.getBigIntegerValue());
    assertEquals(big, p.getNumberValue());
    try {
        p.getLongValue();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "out of range of long");
    }
    BigInteger small = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.TEN);
    p = createParser(String.valueOf(small));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(small, p.getBigIntegerValue());
    try {
        p.getLongValue();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "out of range of long");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) BigInteger(java.math.BigInteger) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 34 with JsonParseException

use of org.apache.flink.shaded.jackson2.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);
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ReplyCaller(io.joynr.dispatching.rpc.ReplyCaller) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Test(org.junit.Test)

Example 35 with JsonParseException

use of org.apache.flink.shaded.jackson2.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;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)145 IOException (java.io.IOException)75 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)58 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 JsonParser (com.fasterxml.jackson.core.JsonParser)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 Map (java.util.Map)19 JsonToken (com.fasterxml.jackson.core.JsonToken)15 InputStream (java.io.InputStream)15 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 File (java.io.File)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonFactory (com.fasterxml.jackson.core.JsonFactory)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5