Topic
6 replies Latest Post - ‏2012-06-25T12:49:58Z by AvV
SystemAdmin
SystemAdmin
527 Posts
ACCEPTED ANSWER

Pinned topic How do I split one message into several messages in a receiver user exit

‏2012-06-12T15:30:35Z |
I have a client that sends messages for several destinations in the same message, and I need to split it into several messages. However, I have no idea how to create new instances of the ReceiverDocumentInterface to populate the array to return from the process method.

For returning a single message, I do all the work on the single instance supplied as a parameter, but for generating multiple messages, I am lost.

I am using WPG 6.2.1.
Updated on 2012-06-25T12:49:58Z at 2012-06-25T12:49:58Z by AvV
  • AvV
    AvV
    117 Posts
    ACCEPTED ANSWER

    Re: How do I split one message into several messages in a receiver user exit

    ‏2012-06-12T15:56:28Z  in response to SystemAdmin
    Hi,

    Before writing any custom code, I would like to make a reference to the build-in EDI, XML and ROD Splitter (http://www-304.ibm.com/support/docview.wss?uid=swg27018754&aid=1):
    • EDI Splitter - EDI Splitter Splits single EDI Document having multiple interchanges into documents having single interchanges
    • XML Splitter - XML Splitter locates for the prologue of each individual document within a single file and then split it based on the location of prologue of next XML Document
    • ROD Splitter - ROD Splitter parses the document definition created in DIS Client and accordingly locate the beginning and end of each document within a single file and split it into individual ROD documents.

    Some sample code snippets for a custom pre process receiver:
    // Create array for the new documents
    recv = new ReceiverDocumentInterface[http://v.size()]; // (please ignore http://)
    for (int i = 0; i < v.size(); i++) {
    // Create new document
    ReceiverDocumentInterface newRDI = BCGReceiverUtil.createReceiverDocument();
    // Set the document attributes
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPACKAGINGNAME, WPGDocumentConst.NO_PACKAGING);
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPACKAGINGVER, WPGDocumentConst.NO_PACKAGINGVER);
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPROTOCOLNAME, "Binary");
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPROTOCOLVER, "1.0");
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPROCESSCD, fromProcessCode);
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRPROCESSVER, fromProcessVersion);
    newRDI.setAttribute(BCGDocumentConstants.BCG_PKG_INITBUSINESSID, senderId);
    newRDI.setAttribute(BCGDocumentConstants.BCG_PKG_FRBUSINESSID, senderId);
    newRDI.setAttribute(BCGDocumentConstants.BCG_PKG_TOBUSINESSID, receiverId);
    newRDI.setAttribute(BCGDocumentConstants.BCG_FRBUSINESSID, senderId);
    newRDI.setAttribute(BCGDocumentConstants.BCG_TOBUSINESSID, receiverId);
    newRDI.setAttribute(BCGDocumentConstants.BCG_INITBUSINESSID, senderId);
    recv[i] = newRDI;
    }
    return recv;

    Hope this helps.

    Arjan

    Senior IT-Specialist
    WebSphere B2B (WPG/WDI), WMQ AMS, WMQ FTE
    IBM Software Services for WebSphere
    Software Group, IMT BNL
    • SystemAdmin
      SystemAdmin
      527 Posts
      ACCEPTED ANSWER

      Re: How do I split one message into several messages in a receiver user exit

      ‏2012-06-12T19:54:32Z  in response to AvV
      Hi Arjan,

      Thanks. That's perfect. The EDI Splitter is exactly what I need - that way I can handle each message individually.

      I was working off old information, where it wasn't working before, but in 6.2.1 I can confirm that it works.

      Thanks,

      John
    • SystemAdmin
      SystemAdmin
      527 Posts
      ACCEPTED ANSWER

      Re: How do I split one message into several messages in a receiver user exit

      ‏2012-06-15T21:26:30Z  in response to AvV
      Hi Arjen,

      There are some circumstances where I have to edit the split documents before sending them on. I tried using a second PreProcess Receiver, but have just found out that it will only ever use one, so I can't put both.

      In your example, there is no way to set the split documents. I have tried myself by using temporary files, but keep getting errors:

      6/15/12 20:06:41:241 UTC 0000009c WoodwardHandl I WoodwardHandler trace User exit executing
      6/15/12 20:06:41:246 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace There are 3 messages
      6/15/12 20:06:41:247 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new Receiver Document
      6/15/12 20:06:41:247 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new file: /wpg-common/common/receiver/tmp/133979080053
      8005056BF002502470163BD88E08E4226880..bcg_tmp
      6/15/12 20:06:41:253 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new Receiver Document
      6/15/12 20:06:41:254 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new file: /wpg-common/common/receiver/tmp/133979080053
      8005056BF002502470163BD88E08E4226881..bcg_tmp
      6/15/12 20:06:41:261 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new Receiver Document
      6/15/12 20:06:41:262 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Creating new file: /wpg-common/common/receiver/tmp/133979080053
      8005056BF002502470163BD88E08E4226882..bcg_tmp
      6/15/12 20:06:41:268 UTC 0000009c WoodwardHandl W aero.sita.omh.receiver.handler.WoodwardHandler trace Returning documents
      6/15/12 20:06:41:270 UTC 0000009c ReceiverFrame E com.ibm.bcg.bcgdk.receiver.ReceiverFrameWorkImpl preProcess java.lang.NullPointerException
      6/15/12 20:06:41:277 UTC 0000009c DirectoryFile E com.ibm.bcg.server.receiver.DirectoryFile handleException couldnt move the content file to reject directory
      Do you have any hints on how I can get this working?

      Regards,

      John
      • AvV
        AvV
        117 Posts
        ACCEPTED ANSWER

        Re: How do I split one message into several messages in a receiver user exit

        ‏2012-06-18T13:41:22Z  in response to SystemAdmin
        hi John,

        I have appended "Sample code : PreProcessReceiverPOP3 exit for receiving plain e-mail" (https://www.ibm.com/developerworks/forums/thread.jspa?threadID=437735&tstart=0) into this Forum.

        In this sample code you will find "File.createTempFile("POP3_", ".eml", BCGReceiverUtil.getTempDir());". This will create your temporarily file. This is your new business document.

        Instead of modifying the document in the preprocessreceiver, it would be nicer to create a transformation action in your document connection :
        • Use the DIS client and import the transformation map
        • Create a custom transformation, a class which implements the "BusinessProcessInterface". See sample below.
        Regards,
        Arjan

        Senior IT-Specialist
        WebSphere B2B (WPG/WDI), WMQ AMS, WMQ FTE
        IBM Software Services for WebSphere
        Software Group, IMT BNL

        =================================================================
        public BusinessDocumentInterface process(Context context, BusinessDocumentInterface businessDocumentInterface) {
        String methodName = "process";
        logger.entering(className, methodName);

        try {
        // Get the Business document file.
        File sourceFile = businessDocumentInterface.getDocument();

        // Create a new file to store transformed
        File targetFile = businessDocumentInterface.createFile();

        if (logger.isLoggable(Level.FINE)) {
        logger.logp(Level.FINE, className, methodName, "sourceFile.getAbsolutePath() = " + sourceFile.getAbsolutePath());
        logger.logp(Level.FINE, className, methodName, "targetFile.getAbsolutePath() = " + targetFile.getAbsolutePath());
        }

        FileUtils.removeLineFeed(sourceFile, targetFile);

        // Store the transformed target file into business document.
        businessDocumentInterface.setDocument(targetFile);
        } catch (Exception e) {
        logger.logp(Level.SEVERE, className, methodName, "Caught exception: " + e.toString());

        businessDocumentInterface.setDocumentState(BCGDocumentConstants.BCG_DOCSTATE_FAILED);

        EventInfo eventInfo = new EventInfo("BCG200005", businessDocumentInterface, new String[] { "process(): exception received" }, e);
        eventInfo.setSourceClass(RemoveCRLFProcess.class.getName());
        eventInfo.setFaultType(EventInfo.FAULTTYPE_SOURCE);

        EventInfo] aei = new EventInfo[ { eventInfo };
        businessDocumentInterface.addEvents(aei);
        }

        logger.exiting(className, methodName);
        return businessDocumentInterface;
        }
        • SystemAdmin
          SystemAdmin
          527 Posts
          ACCEPTED ANSWER

          Re: How do I split one message into several messages in a receiver user exit

          ‏2012-06-25T12:37:56Z  in response to AvV
          Hi Arjan,

          Thanks for that. Where can I get the

          com.ibm.issw.wpg.utils.WPGDocumentConst

          file? I cannot find it in any of the library files I have.

          Regards,

          John
          • AvV
            AvV
            117 Posts
            ACCEPTED ANSWER

            Re: How do I split one message into several messages in a receiver user exit

            ‏2012-06-25T12:49:58Z  in response to SystemAdmin
            Hi John,

            The class WPGDocumentConst is in pop3.jar which is available from the pop3.zip attached in "Sample code : PreProcessReceiverPOP3 exit for receiving plain e-mail." (http://www.ibm.com/developerworks/forums/thread.jspa?threadID=437735&tstart=0).

            pop3.jar --> com\ibm\issw\wpg\utils\WPGDocumentConst.java
            Regards, Arjan