Skip to Content
avatar image
Former Member

MessageTransformBean - SimplePlain2XML - Multiple records on a single line

Hi,

I am trying to convert multiple record from a single line to multipe rows in an XML message with the MessageTransformBean.

If the record look like this it's working:

RECORD1textETC

RECORD2textETC

But the incoming message are all on a single line:

RECORD1textETCRECORD2textETC

Is there a way to add a linefeed to my incoming message after X characters, or to tell the adapter to split by length instead of spliting on the end of line?

Thanks,

Martin

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 22, 2010 at 09:14 PM

    Hi Martin,

    You can come up with one interface where in your mapping you can write the UDF to add a new line after some x characters or Probably we can come up with some script while breaks your one line string and add a new line and save it in a different location. You can pick from that location.

    Regards,

    ---Satish

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 27, 2010 at 08:05 AM

    > Is there a way to add a linefeed to my incoming message after X characters, or to tell the adapter to split by length instead of spliting on the end of line?

    This is not possible.

    You have to write an adapter module which you place before the MessageTransformBean

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I had to code a custom Module Adapter to do it.

      Here's the main part of the module adapter EOLConvertBean...

      ...

      Message msg = (Message) inputModuleData.getPrincipalData();

      ...

      XMLPayload xmlpayload = msg.getDocument();

      byte[] content = xmlpayload.getContent();

      byte crlf = 0x0A; // end of line char

      int current = 0; // current bytes read

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      int lines = content.length / recordLen; // record len = insert EOL after X recordLen

      // TODO change for do while for 1x line record

      for (int i = 0; i <= lines; i++) {

      baos.write(content, current, recordLen);

      baos.write(crlf);

      current += recordLen;

      }

      xmlpayload.setContent(baos.toByteArray());

      ...

      inputModuleData.setPrincipalData(msg);

      ...

      Edited by: Martin Lavoie Rousseau on Oct 6, 2010 9:08 PM