Bind raw data to a Java byte array ?

110 views
Skip to first unread message

Vincent M

unread,
Jan 15, 2014, 11:55:53 AM1/15/14
to legsta...@googlegroups.com
Hi,

This is my first post on this forum, so hello everyone. I also need some help ...

I am working on java application which do requests to a CICS, and everything go right for most of them. However, for programs with pagination features, there is a special field used as pagination key.

This is an example from a CBL file :
                15  LOV036-CLE-PDD-SUIV          PIC  X(200).

This field has an arbitrary format (depending on the called program) and may contain binary data (because of concatenated fields : alphanumeric or packed decimal) ! The binding with a Java String field results with an encoding translation (host encoding is CP1147), and therefore an invalid pagination key.

How can I bind this field as a byte[] Java field ? Base64 maybe ?

I tried some changes to the generated XSD file for JAXB :

            <element name="lov036ClePddSuiv">
                <annotation>
                    <appinfo>
                        <cb:cobolElement cobolName="LOV036-CLE-PDD-SUIV" levelNumber="15" picture="X(200)" srceLine="84" type="ALPHANUMERIC_ITEM" />
                    </appinfo>
                </annotation>
                <simpleType>
                    <restriction base="string">
                        <maxLength value="200"/>
                    </restriction>
                </simpleType>
            </element>


I changed restriction base to hexBinary. Generated field is byte[], but I got when executing request :
fr.swisslife.tra.mid.fast.ws.TechniqueException: I/O exception during bytes conversion; nested exception is java.io.IOException: com.legstar.coxb.transform.HostTransformException: Attempt to set binding Lov036ClePddSuiv from an incompatible value [B@166debb


I also changed the cb:cobolElement type to OCTET_STREAM_ITEM and the call fails because action parameter becomes 0 ! I don't know why ...

I can access the whole Comarea byte array, but it would be difficult to short-cut the binding mechanism, isn't it ?

Any idea on what is going on ? I will be grateful for a solution to this issue.

Fady

unread,
Jan 16, 2014, 3:13:33 AM1/16/14
to legsta...@googlegroups.com
Actually you are doing the right thing.

I just run a similar test starting from this copybook:

       01 LOV036.
          15  LOV036-CLE-PDD-SUIV          PIC  X(200).
          
I then changed the cobolElement type and xsd restriction just like you did (both are needed):

    <complexType name="Lov036">
        <sequence>
            <element name="lov036ClePddSuiv">
                <annotation>
                    <appinfo>
                        <cb:cobolElement cobolName="LOV036-CLE-PDD-SUIV" levelNumber="15" picture="X(200)" srceLine="2" type="OCTET_STREAM_ITEM"/>
                    </appinfo>
                </annotation>
                <simpleType>
                    <restriction base="hexBinary">
                        <maxLength value="200"/>
                    </restriction>
                </simpleType>
            </element>
        </sequence>
    </complexType>
    <element name="lov036" type="tns:Lov036">
        <annotation>
            <appinfo>
                <cb:cobolElement cobolName="LOV036" levelNumber="1" srceLine="1" type="GROUP_ITEM"/>
            </appinfo>
        </annotation>
    </element>

Then I re-generate the binding code (important) and ran this test successfully:

  public void testApp() throws Exception {
      byte[] hostData = new byte[200];
      for (int i = 0; i < 200; i++) {
          hostData[i] = (byte) i; 
      }
      Lov036Transformers xf = new Lov036Transformers();
      byte[] javaData = xf.toJava(hostData).getLov036ClePddSuiv();
      assertEquals("0001020304", HostData.toHexString(javaData).substring(0, 10));
  }

Could it be you did not regenerate the transformers?

Vincent M

unread,
Jan 16, 2014, 7:04:47 AM1/16/14
to legsta...@googlegroups.com
Thank you very much Fady for your excellent answer.

I focused on this solution and solved my action number issue. Obviously, I needed a well formatted byte array for the first call :
        cleRepositionnement = new byte[200];
        Arrays.fill(cleRepositionnement, (byte)0x40);
Reply all
Reply to author
Forward
0 new messages