Search in sources :

Example 81 with JsonParseException

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

the class JSONEqualAssertionVerifier method _verify.

/**
 * @param assertion
 * @param input the JSON string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult _verify(Assertion assertion, Object input) {
    JSONEqualAssertionProperties assertionProperties = (JSONEqualAssertionProperties) assertion.getOtherProperties();
    // validate arguments
    if (assertionProperties.getExpectedJSON() == null) {
        throw new IllegalArgumentException("Expected JSON is null.");
    } else if (input == null) {
        throw new IllegalArgumentException("Actual JSON is null.");
    }
    String expectedJSON = assertionProperties.getExpectedJSON().replaceAll(JSON_UNIT_PLACEHOLDER_REGEX, JSON_UNIT_PLACEHOLDER_DELIMITER_REPLACEMENT);
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    try {
        assertJsonEquals(expectedJSON, input);
    } catch (IllegalArgumentException e) {
        Throwable c = e.getCause();
        if (c instanceof JsonParseException) {
            throw new IllegalArgumentException(e.getMessage() + " " + c.getMessage());
        } else {
            throw e;
        }
    } catch (AssertionError ae) {
        result.setDifferences(ae.getMessage());
    }
    if (result.getDifferences() == null) {
        result.setResult(TestResult.PASSED);
    } else {
        result.setResult(TestResult.FAILED);
    }
    return result;
}
Also used : JSONEqualAssertionProperties(io.irontest.models.assertion.JSONEqualAssertionProperties) JsonParseException(com.fasterxml.jackson.core.JsonParseException) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Example 82 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method unmarshall.

/**
 * NOTE: This method has been set protected for Stunner support. Stunner bpmn implementation provides a custom JsonParser that
 * is used instead of the one used in jbpm-designer-backend.
 * <p>
 * Start unmarshalling using the parser.
 * @param parser
 * @param preProcessingData
 * @return the root element of a bpmn2 document.
 * @throws JsonParseException
 * @throws IOException
 */
protected Bpmn2Resource unmarshall(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
    try {
        // open the object
        parser.nextToken();
        ResourceSet rSet = new ResourceSetImpl();
        rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
        Bpmn2Resource bpmn2 = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2"));
        rSet.getResources().add(bpmn2);
        _currentResource = bpmn2;
        if (preProcessingData == null || preProcessingData.length() < 1) {
            preProcessingData = "ReadOnlyService";
        }
        // do the unmarshalling now:
        Definitions def = (Definitions) unmarshallItem(parser, preProcessingData);
        def.setExporter("jBPM Designer");
        def.setExporterVersion("6.2.0");
        revisitUserTasks(def);
        revisitServiceTasks(def);
        revisitMessages(def);
        revisitCatchEvents(def);
        revisitThrowEvents(def);
        revisitLanes(def);
        revisitSubProcessItemDefs(def);
        revisitArtifacts(def);
        revisitGroups(def);
        revisitTaskAssociations(def);
        revisitSendReceiveTasks(def);
        reconnectFlows();
        revisitGateways(def);
        revisitCatchEventsConvertToBoundary(def);
        revisitBoundaryEventsPositions(def);
        createDiagram(def);
        updateIDs(def);
        revisitDataObjects(def);
        revisitAssociationsIoSpec(def);
        revisitWsdlImports(def);
        revisitMultiInstanceTasks(def);
        addSimulation(def);
        revisitItemDefinitions(def);
        revisitProcessDoc(def);
        revisitDI(def);
        revisitSignalRef(def);
        orderDiagramElements(def);
        // return def;
        _currentResource.getContents().add(def);
        return _currentResource;
    } catch (Exception e) {
        _logger.error(e.getMessage());
        return _currentResource;
    } finally {
        parser.close();
        _objMap.clear();
        _idMap.clear();
        _outgoingFlows.clear();
        _sequenceFlowTargets.clear();
        _bounds.clear();
        _currentResource = null;
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 83 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project kie-wb-common by kiegroup.

the class DefaultProfileImpl method createMarshaller.

public IDiagramMarshaller createMarshaller() {
    return new IDiagramMarshaller() {

        public String parseModel(String jsonModel, String preProcessingData) {
            Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
            // Definitions def;
            Resource res;
            try {
                res = unmarshaller.unmarshall(jsonModel, preProcessingData);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                Map saveMap = new HashMap();
                saveMap.put(XMLResource.OPTION_ENCODING, "UTF-8");
                saveMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
                saveMap.put(XMLResource.OPTION_DISABLE_NOTIFY, true);
                saveMap.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
                res.save(outputStream, saveMap);
                return outputStream.toString();
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return "";
        }

        public Definitions getDefinitions(String jsonModel, String preProcessingData) {
            try {
                Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
                JBPMBpmn2ResourceImpl res = (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
                return (Definitions) res.getContents().get(0);
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return null;
        }

        public Resource getResource(String jsonModel, String preProcessingData) {
            try {
                Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
                return (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return null;
        }
    };
}
Also used : Bpmn2JsonUnmarshaller(org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) Definitions(org.eclipse.bpmn2.Definitions) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 84 with JsonParseException

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

the class ContentBuilderUtil method addComplexField.

public static void addComplexField(XContentBuilder builder, String fieldName, XContentType contentType, byte[] data) throws IOException {
    XContentParser parser = null;
    try {
        // Elasticsearch will accept JSON directly but we need to validate that
        // the incoming event is JSON first. Sadly, the elasticsearch JSON parser
        // is a stream parser so we need to instantiate it, parse the event to
        // validate it, then instantiate it again to provide the JSON to
        // elasticsearch.
        // If validation fails then the incoming event is submitted to
        // elasticsearch as plain text.
        parser = XContentFactory.xContent(contentType).createParser(NamedXContentRegistry.EMPTY, data);
        while (parser.nextToken() != null) {
        }
        ;
        // If the JSON is valid then include it
        try {
            parser = XContentFactory.xContent(contentType).createParser(NamedXContentRegistry.EMPTY, data);
            // Add the field name, but not the value.
            builder.field(fieldName);
            // This will add the whole parsed content as the value of the field.
            builder.copyCurrentStructure(parser);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
    } catch (JsonParseException ex) {
        // If we get an exception here the most likely cause is nested JSON that
        // can't be figured out in the body. At this point just push it through
        // as is
        addSimpleField(builder, fieldName, data);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : JsonParseException(com.fasterxml.jackson.core.JsonParseException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 85 with JsonParseException

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

the class SiteToSiteRestApiClient method readResponse.

private TransactionResultEntity readResponse(final InputStream inputStream) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    StreamUtils.copy(inputStream, bos);
    String responseMessage = null;
    try {
        responseMessage = new String(bos.toByteArray(), "UTF-8");
        logger.debug("readResponse responseMessage={}", responseMessage);
        final ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(responseMessage, TransactionResultEntity.class);
    } catch (JsonParseException | JsonMappingException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to parse JSON.", e);
        }
        final TransactionResultEntity entity = new TransactionResultEntity();
        entity.setResponseCode(ResponseCode.ABORT.getCode());
        entity.setMessage(responseMessage);
        return entity;
    }
}
Also used : TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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