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;
}
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;
}
}
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;
}
};
}
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();
}
}
}
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;
}
}
Aggregations