use of 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 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 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 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;
}
}
use of com.fasterxml.jackson.core.JsonParseException in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method schemaMatch.
/**
* Check if response matches schema
*
* @param p Path to the schema to be tested
* @return TestItemReport
*/
private TestExecReport schemaMatch(String p) {
LOGGER.info("Testing Schema");
TestExecReport tr = new TestExecReport("Json matches schema: " + p, false);
tr.setType("schema mismatch");
tr.setSchema(p);
try {
String jsonString = vr.extract().response().asString();
SchemaValidator schemaValidator = new SchemaValidator();
ProcessingReport r = schemaValidator.validate(p, jsonString);
if (r.isSuccess()) {
LOGGER.info("Schema Test Passed");
tr.addMessage("Response structure matches schema.");
tr.setPassed(true);
} else {
LOGGER.info("Schema Test Failed");
tr.addMessage("Response structure doesn't match schema.");
r.forEach(message -> tr.addError(message.asJson()));
}
return tr;
} catch (ConnectionClosedException | JsonParseException e1) {
LOGGER.info("Invalid response");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage("Server response is not valid JSON.");
return tr;
} catch (AssertionError | IOException | ProcessingException e1) {
LOGGER.info("Doesn't match schema");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage(e1.getMessage());
return tr;
}
}
Aggregations