Search in sources :

Example 21 with JsonParseException

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

the class YamlReader method getConfiguration.

/**
 * Gets the configuration.
 *
 * @return the configuration
 */
public static ConfigDTO getConfiguration() {
    File file = new File(DEVICE_MGT_CONFIG_PATH);
    ConfigDTO configPojo = new ConfigDTO();
    // jackson databind
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        configPojo = mapper.readValue(file, ConfigDTO.class);
    } catch (JsonParseException e) {
        log.error("Yaml Parsing Error", e);
    } catch (JsonMappingException e) {
        log.error("Yaml Mapping Error", e);
    } catch (IOException e) {
        log.error("Yaml File Error", e);
    }
    return configPojo;
}
Also used : ConfigDTO(com.wso2telco.core.pcrservice.model.ConfigDTO) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 22 with JsonParseException

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

the class StartSessionResource method createEvent.

@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String body) throws ClientResourceException {
    final Map<?, ?> values = newHashMap();
    try {
        if (!isNullOrEmpty(body)) {
            values.putAll(mapper.readValue(body, Map.class));
        }
    } catch (JsonMappingException | JsonParseException e) {
        throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
    } catch (final IOException e) {
        throw new ClientResourceException(SC_BAD_REQUEST);
    }
    final Map<String, String> properties = newHashMap();
    if (null != values.get(PROPERTIES)) {
        if (!(values.get(PROPERTIES) instanceof Map)) {
            throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
        } else {
            ((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {

                @Override
                public void accept(final Entry<?, ?> entry) {
                    properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
                }
            });
        }
    }
    return new SessionStartedEvent(sessionId, properties);
}
Also used : IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) ClientResourceException(org.eclipse.n4js.tester.server.resources.ClientResourceException) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map)

Example 23 with JsonParseException

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

the class StartTestResource method createEvent.

@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String testId, final String body) throws ClientResourceException {
    if (isNullOrEmpty(body))
        throw new ClientResourceException(SC_BAD_REQUEST);
    final Map<?, ?> values = newHashMap();
    try {
        values.putAll(mapper.readValue(body, Map.class));
    } catch (JsonMappingException | JsonParseException e) {
        throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
    } catch (final IOException e) {
        throw new ClientResourceException(SC_BAD_REQUEST);
    }
    final Object value = values.get(TIMEOUT_KEY);
    // incorrect schema
    if (null == value) {
        throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
    }
    final Map<String, String> properties = newHashMap();
    if (null != values.get(PROPERTIES)) {
        if (!(values.get(PROPERTIES) instanceof Map)) {
            throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
        } else {
            ((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {

                @Override
                public void accept(final Entry<?, ?> entry) {
                    properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
                }
            });
        }
    }
    try {
        final long timeout = parseLong(valueOf(value));
        return new TestStartedEvent(sessionId, testId, timeout, properties);
    } catch (final NumberFormatException e) {
        // although schema was valid the data was indeed invalid
        throw new ClientResourceException(SC_BAD_REQUEST);
    }
}
Also used : IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ClientResourceException(org.eclipse.n4js.tester.server.resources.ClientResourceException) TestStartedEvent(org.eclipse.n4js.tester.events.TestStartedEvent) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap)

Example 24 with JsonParseException

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

the class TagServiceIndexTest method testIndexSpotCheckMostRecentValidationTagsObjectMappingException.

@Test
public void testIndexSpotCheckMostRecentValidationTagsObjectMappingException() throws Exception {
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class)).thenReturn(10);
    when(tagDao.getMostRecentTags(10)).thenReturn(rootTagEntities);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
    when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(false);
    // Call the method under test
    boolean isSpotCheckMostRecentValid = tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_TYPE_TAG);
    assertThat("Tag service index spot check most recent validation is true when it should have been false.", isSpotCheckMostRecentValid, is(false));
    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
    verify(tagDao).getMostRecentTags(10);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
    verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper, jsonHelper, tagHelper);
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Test(org.junit.Test)

Example 25 with JsonParseException

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

the class BusinessObjectDefinitionHelperTest method testExecuteFunctionForBusinessObjectDefinitionEntitiesJsonParseException.

@Test
public void testExecuteFunctionForBusinessObjectDefinitionEntitiesJsonParseException() {
    // Create a list of business object definition entities.
    final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Collections.unmodifiableList(Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes2())));
    businessObjectDefinitionEntities.forEach(entity -> {
        entity.setDescriptiveBusinessObjectFormat(new BusinessObjectFormatEntity());
        entity.getDescriptiveBusinessObjectFormat().setSchemaColumns(new ArrayList<>());
        entity.setSubjectMatterExperts(new ArrayList<>());
    });
    // Mock the external calls.
    when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
    // Execute a function for all business object definition entities.
    businessObjectDefinitionHelper.executeFunctionForBusinessObjectDefinitionEntities(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE, businessObjectDefinitionEntities, (indexName, documentType, id, json) -> {
    });
    // Verify the external calls.
    verify(jsonHelper, times(businessObjectDefinitionEntities.size())).objectToJson(any());
    verifyNoMoreInteractions(alternateKeyHelper, jsonHelper);
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) JsonParseException(com.fasterxml.jackson.core.JsonParseException) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

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