Changes

Jump to: navigation, search

JSON Integration Adapter

2,188 bytes added, 22:41, 26 January 2014
no edit summary
{{Admon/obsolete}} [[category: NexJ Current Past Projects]]
[[category: NexJ Express JSON Message Adapter]]
 
== Project Repository ==
 
https://bitbucket.org/b_lim/nexj-express-json-integration-adapter/overview
 
== Project Goal==
To create an adapter for the NexJ Core similar in methodology and design of existing message adapters (XML, Fixed, CSV etc.) but using the JSON format
===Contributors===
* [[User:Gbatumbya|Grace Batumbya]]
* [[User:Brianlim | Brian Lim]]
 
== Current Status==
* '''Completed''' (February 02, 2012)
Currently at Phase II and beginning Phase III.
==Project PhasesRepository == JSON Integration Adapter Phases ===Phase IBitBucket : https://bitbucket. Research (DONE)=== # Complete Fundamentals of NexJ Studio tutorial# Complete NexJ Integration tutorial# Install NexJ Studio Express from sourceorg/gbatumbya/nexjexpress-jsonintergrationadapter/===Phase II<br/>Deprecated: <del>https://bitbucket. Planning and Approval (DONE)=== # Receive general approval for project# Receive approval for JSON encoding options# Receive approval for JSON formatting options ===Phase III. Message Formatter (80% DONE)=== # Add JSON to .XSD base types# Create sample JSON .message # Parse sample JSON .message with JUnit Test# Create first set of unit tests for Message Formatter# Code Message Formatter first draft# Resolve issues with first set of unit tests# Create second set of unit tests# Resolve issues with second set of unit tests# Refactor and code message formatter ===Phase IV. Message Parser === # Discover how to connect JSON RPC parser with Message Parser# Create first set of trivial unit tests for Message Parser# Code Message Parser skeleton# Pass first set of trivial unit tests# Create second set of unit tests (nonorg/b_lim/nexj-express-json-trivial) for Message Parser# Code Message Formatter first draft# Resolve issues with second set of unit tests# Refactor ===Phase V. Integration and Stress Tests=== # Test Message Formatter and Message Parser with integration and stress tests# Test through NexJ Studio Express GUI (manual testing) ===Phase VI. Internal Code Review=== # Internally review code at CDOT ===Phase VII. Optimization=== # Find more code optimizations relevant to Enterprise environments ===Phase VIII. First Code Review at NexJ=== # Date TBA ===Phase IX. Code Rewrite=== # Rewrite code to conform with NexJ suggestions and standards-adapter/</del>
===Phase X. Second Code Review at NexJ===
# Date TBA== Definitions ==
{| class="wikitable" border==Phase XI"1"|-! Term! Description|-| Formatter| Turns data into JSON|-| Parser| Turns JSON into data|-| Message| The metadata to be used when formatting and parsing a message. The grammar. It is a tree-like structure. Project Completion===|-| MessageInstance| The information to be parsed or formatted|}
== Project Repository ==Because the Integration layer allows a Model to interact with external applications asynchronously, a description / grammar of the data to be exchanged between the two systems is defined using a Message in the Model.
BitBucket : https://bitbucket* Formatting is turning internal NexJ representation of a MessageInstance into JSON.org/b_lim/nexjThe formatter is given a Message (the grammar), MessageInstance (the data), and a pipe. This accomplished by walking the Message tree-express-json-integration-adapter/like structure while validating the data in the MessageInstance and streaming JSON format to the pipe. If the data in the MessageInstance does not conform to the Message, the formatter throws an exception.
== Technical Notes ==* Parsing is turning JSON representation of a MessageInstance into an internal NexJ representation of a MessageInstance. The parser is given a Message (the grammar) and an input stream. First the input stream is parsed for JSON using a JSONParser which returns either an Object or an Array. The formatter walks the Message building the structure of the MessageInstance and adding validated values in the object returned by the JSONParser to the MessageInstance. If the data from the input stream does not match the expected input at any time, the parser throws an exception.
=== Message Details ===
==== Message Fundamentals ====
Message - Messages can contain values or other messages. The red nodes are messages, the green nodes are values.
{
part = (MessagePart)it.next());
if (isCompositeMessagePartInstance(part)instanceof CompositeMessagePartInstance)
{
// This part is a message
}
else if (isPrimitiveMessagePart(part)instanceof PrimitiveMessagePart)
{
// This part is a value
NOTE: THE MESSAGE PARAMETER DOES NOT CONTAIN THE MESSAGE VALUES. THE MESSAGE PARAMETER CONTAINS THE MESSAGE METADATA. THE TRANSFER OBJECT CONTAINS THE MESSAGE VALUES WHICH MUST BE VALIDATED AGAINST THE MESSAGE TO ENSURE CORRECT FORMAT.
; MessagePart.java - :Parts of a message. Messages can contain values or other messages. NexJ Express has two types of message parts, ''CompositeMessagePart'' and ''PrimitiveMessagePart''.
Currently NexJ Express has two types of message parts, ; CompositeMessagePart: implementation is CompositeMessagePartInstance .java The relationship between CompositeMessagePartInstance and PrimitiveMessagePart with the above picture is as follows - CompositeMessagePartInstance are messages (the red nodes) and PrimitiveMessagePartare values (the green nodes). To determine multiplicity of MessageParts, use isCollection() method of MessagePart. Note that multiplicity of the above screenshot are all '''[0..1]''', that is zero or one instance. Possible node multiplicities:; '''[0..java 1]''' : zero or one instance (i. e. an optional entry); '''[1..1]''' : exactly one instance (i.e. required); '''[1..N]''' : collection of at least one, at most N instances; '''[0..0]''' : collection of zero to infinite instances (displayed as '''[*]'''); '''[1..0]''' : collection of at least one, possibly unlimited instances
CompositeMessagePart.java implementation is CompositeMessagePartInstance . The relationship between CompositeMessagePartInstance and PrimitiveMessagePart with the above picture is as follows ; XMLJSONMessageMappingLoader: CompositeMessagePartInstance are messages (Used by the red nodes) and PrimitiveMessagePart are values (framework to autoload JSONMessagePartMapping for each of the green nodes)message parts.
To determine multiplicity of MessageParts; JSONMessagePartMapping: Each node in the above picture ''may'' has a corresponding JSONMessagePartMapping. Each node may have its own mapping, with its own values initialized in XMLJSONMessageMappingLoader. In order to get the mapping, first cast MessagePart to a concrete class such as CompositeMessagePartInstance or PrimitiveMessagePart, then use isCollectionpart.getMapping() method . The purpose of MessagePart the mapping is metadata for each node.
Note that multiplicity of the above screenshot are all 1. A real message would have ; JSONMessageFormatter: Used to turn messages and values with > 1 multiplicity or 0 (infinite) multiplicityinto JSON format.
XMLJSONMessageMappingLoader.java - ; JSONMessageParser: Used by the framework to autoload JSONMessagePartMapping for each of the turn JSON into a message parts.
JSONMessagePartMapping - Each node in the above picture has a corresponding JSONMessagePartMapping.Each node has its own mapping, with its own values initialized in XMLJSONMessageMappingLoader.In order to get the mapping, first cast MessagePart to a concrete class such as CompositeMessagePartInstance or PrimitiveMessagePart, then use part.getMapping(). The purpose of the mapping is metadata for each node.==== Algorithm ====
JSONMessageFormatter - Used format(TransferObject tobj, Message message, Output out)Algorithm for format method is as follows# Retrieve the root of the message# Iterate through each of the parts of the root## If the part is a CompositeMessagePartInstance, it is a message node## If the part is a PrimitiveMessagePart, it is a value node## Validate the part against the MessagePartMapping. Different types of validation must be done if the part is a Composite versus if it is a Primitive.## If the part is a CompositeMessagePartInstance, recursively call the format method with TransferObject set to turn messages into JSON the part. Suggested to overload the formatmethod to format(TransferObject tobj, MessagePart message, Output out) and pass in the part, since retrieving a message root with getRoot() will always get the highest root of the message but what you want is the parent.## If the part is a PrimitiveMessagePart, write the message part to the output.
JSONMessageParser - Used to turn JSON into a message.
format==Project Phases== ===Phase 1. Research (DONE)===# Complete Fundamentals of NexJ Studio tutorial# Complete NexJ Integration tutorial# Install NexJ Studio Express from source ===Phase 2. Design Proposal (TransferObject tobj, Message message, Output outDONE)===Algorithm # Receive general approval for format method is as followsproject1# Receive approval for JSON encoding options# Receive approval for JSON formatting options# [https://docs.google.com/document/d/1wAjG-xSJi227GBPUZtADAROSydIn3KuimoZarqO7xDQ/edit?hl=en_US Final Project Proposal] ===Phase 3. Retrieve the root of the messageCreate Classes (DONE)===# JSONMessagePartMapping# XMLJSONMessageMappingLoader# JSONMessageFormatter# JSONMessageParser# JSONMessageFormatterTest 2===Phase 4. Iterate through each of the parts of the rootInternal Code Review (DONE)===# Internally review code at CDOT  2===Phase 5.Code Review 1 If the part is a CompositeMessagePartInstance(DONE)===# August 9, it is a message node2011 2# Code review took place at NexJ with [[User:Gbatumbya|Grace Batumbya]], [[User:Brianlim | Brian Lim]] and Andrew Borzenko (NexJ Developer) in attendance.2 If the part is a PrimitiveMessagePart, it is a value node 2===Phase 6.Apply Changes from Code Review 1===# Estimated Duration: 3 Validate Weeks (August 29, 2011)# [[JSON_Integration_Adapter_Code_Review_1_Changes | Changes to make]]'''Summary of [[JSON_Integration_Adapter_Code_Review_1_Changes | changes]]'''# Allowing modes for all Composite message parts, not just the part against the MessagePartMappingroot. Different types # Refactoring methods to check for != right condition instead of validation must be done if checking for the part is a Composite versus if it is a Primitivewrong condition to throw an exception.(whitelist instead of blacklist) 2# Formatting all primitives before writing or storing them (e.g.4 If the part is a CompositeMessagePartInstancetimestamps, recursively call the format method with TransferObject set to the partdecimal numbers.)# Creating a RootJSONMessagePartMapping extending JSONMessagePartMapping  ===Phase 7. Code Review 2===* Proposed Date: Week of <del>September 23</del> October 15 ===Phase 8.4 If the part is a PrimitiveMessagePart, write the message part Apply Changes from Code Review 2===*[[JSON_Integration_Adapter_Code_Review_2_Changes | Changes to the outputmake]] ===Phase 9. Code Review 3===* Week of November 14 ===Phase 10.Apply Changes from Code Review 3===*[[JSON_Integration_Adapter_Code_Review_3_Changes | Changes to make]] 
== Resources ==

Navigation menu