Friday, July 23, 2010

JSON to COBOL

It turns out it is fairly simple to transform JSON strings to COBOL using LegStar and Jackson.
To do this you would start from a COBOL fragment and use the usual LegStar COBOL to XSD translator and then generate transformers using LegStar COBOL Binding Generator.
Here is a sample JUnit code performing transformation from JSON to COBOL and vice versa:
package json.lsfileae.test;

import java.io.StringWriter;

import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;

import com.legstar.coxb.host.HostData;
import com.legstar.test.coxb.lsfileae.Dfhcommarea;
import com.legstar.test.coxb.lsfileae.bind.DfhcommareaTransformers;

import junit.framework.TestCase;

/**
* Unit test JSON/COBOL transformation.
*/
public class JacksonTest
extends TestCase {

 /** Hex EBCDIC data orignating from mainframe. */
 public static final String HOST_DATA =
     /*0 0 0 1 0 0 */
     "f0f0f0f1f0f0"
     /*  S .  D .   B O R M A N                  */
     + "e24b40c44b40c2d6d9d4c1d54040404040404040"
     /*  L A B A S   S T R E E T                 */
     + "e2e4d9d9c5e86b40c5d5c7d3c1d5c44040404040"
     /*  3 2 1 5 6 7 7 8 */
     + "f3f2f1f5f6f7f7f8"
     /*  2 6   1 1   8 1  */
     + "f2f640f1f140f8f1"
     /*  $ 0 1 0 0 . 1 1  */
     + "5bf0f1f0f04bf1f1"
     /*  * * * * * * * * *  */
     + "5c5c5c5c5c5c5c5c5c"
 ;

 /** JSON serialization of the host data. */
 public static final String JSON_DATA =
   "{\"comNumber\":100," +
   "\"comPersonal\":{\"comName\":\"S. D. BORMAN\"," +
   "\"comAddress\":\"SURREY, ENGLAND\"," +
   "\"comPhone\":\"32156778\"}," +
   "\"comDate\":\"26 11 81\"," +
   "\"comAmount\":\"$0100.11\"," +
   "\"comComment\":\"*********\"}";

 /** Jackson mapper. */
 private ObjectMapper _mapper;

 /** LegStar transformer. */
 private DfhcommareaTransformers _transformer;

 public void setUp() {
   _mapper = new ObjectMapper();
   AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
   _mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
   _mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
   _transformer = new DfhcommareaTransformers();
 }

 /**
  * Transform host data to JSON and check
  * @throws Exception if transformation fails
  */
 public void testHostToJson() throws Exception {
   StringWriter sw = new StringWriter();
   _mapper.writeValue( sw, _transformer.toJava(HostData.toByteArray(HOST_DATA)));
   assertEquals(JSON_DATA,  sw.toString());
 }

 /**
  * Transform JSON to host data and check
  * @throws Exception if transformation fails
  */
 public void testJsonToHost() throws Exception {
   Dfhcommarea dfhcommarea = _mapper.readValue(JSON_DATA, Dfhcommarea.class);
   byte[] hostData = _transformer.toHost(dfhcommarea);
   assertEquals(HOST_DATA, HostData.toHexString(hostData));
 }
}

Tuesday, July 13, 2010

MuleSoftwebinar with MDI and LegStar

MuleSoft is putting together a Webinar on wednesday July 14th which features Mule ESB + MDI + LegStar. You can join the webinar here.
It tells a very compelling story where you want to web enable a CICS/COBOL program but would like a very different message structure than the original COBOL program input and output.
In this scenario LegStar does the COBOL parsing and mainframe transport while MDI takes over the transformation. The result is a Web Service with a nice interface deployed in Mule ESB. MDI really adds value here in that it hides the ugly COBOL structure and expose a set of friendly java classes instead.
COBOL structures, which typically describe CICS commareas, are often complex and convoluted due to the limitation of COBOL but also the need to reduce external calls and therefore cramming as much data as possible in a single commarea.
Exposing such complex structures as web services results in WSDL that is quite difficult to manipulate. MDI can be used to visually map these complex structures with simpler java classes and hence expose a nicer web service.

Friday, July 9, 2010

Just finished a series of videos showcasing how to create a mainframe adapter with LegStar for JBoss ESB.
I have become a fan of video demoes. I find them a lot easier to follow than reading paper documentation.
So I embarked in doing my own video demoes.
There are 2 things that I found amazing while doing this:
  1. How difficult it is to get something as obvious as a product demo video done
  2. How much data you can store on YouTube for free!
I had 3 choices when I started:
  1. filming myself doing the demo
  2. doing screen captures of the demo and recording my voice
  3. doing screen captures of the demo and adding subtitles
I ended up doing option 2. I ruled out option 1 for aesthetic reasons and 3 because I couldn't figure out how to do it .
I have been told that it would have been much easier on a Mac. Unfortunately, I am still a Windows user (Although I have one machine running Ubuntu, another running Fedora core and several other unixes running in VirtualBox).
I started by using Microsoft MovieMaker which is quite easy to learn, but the result was disappointing. I couldn't get the quality to be acceptable once the video was uploaded.
One of the issues with such product demoes is that you want the GUI to be readable. This is impossible with small frame sizes. Typically MovieMaker would not allow me to pick up 1024x768, which is what I ended up needing for the Eclipse GUI.
So I turned to these free products:
I also had to bring in the Xvid MPEG-4 Codec for compression. It turns out this is a codec that YouTube supports very well so there is very little quality loss when you upload to YouTube.
The result is not too bad although it still feels quite amateurish.
I have spent several days doing this, but feel I would need a lot lot more to make it look professional.
Hopefully this will be enough to help people learn the product faster.