Pages

Contact

Removing BEGIN statements from Streamfiles with Java

In this example, we have a standard M3 Streamfile (PPS307PF – M3 Put-Away document) that contains separate BEGIN statements (the keyword that signifies a new event to Streamserve) for each item received against a purchase order. My client would like to see one document with all received items shown as separate lines. This will save a tremendous amount of paper and allow for easier processing. With the help of Java and Streamserve filter chains, we can remove unwanted BEGIN statements and quickly achieve a single event document without modification in M3.

In addition to Java knowledge, you’ll also need to have:

Experience with the M3 Output Solution including Streamserve Control Center and Design Center (version 5.6 is used in this example). Specifically:

We want to process PPS307PF as one document with multiple lines as opposed to the standard document which has multiple documents (indicated by the multiple BEGINPPS3070H statements in the Streamfile) each with a single line.

There is only one type of BEGIN statement in this Streamfile, but some Streamfiles have more than one, so we’ll take that into account in the code.

Step 2: Create Java filter to remove the unwanted BEGIN statements

In the Streamfile above we found two instances of BEGINPPS3070H. In order to remove the second (and any subsequent appearances) while keeping the first, we’ll create a class that will remove these lines as the Streamfile gets passed into Streamserve. We’ll also take into account that we may need to filter Streamfiles other than PPS307, so we’ll use a regular expression to find the instances of BEGIN in the file that end in ‘H’ (This way we’re excluding 0A BEGIN statements while including 0H, 1H, AH, etc.).

Our code creates a class called SingleEvent which reads the incoming Streamfile one line at a time and checks the current line to see if it matches our regular expression. If so, a counter is increased and if the counter is larger than one, it replaces the current line with new text. This text can be anything other than BEGINPPS3070H as Streamserve is looking for the BEGIN statements to create new documents. Each (new) line is then written to the console and Streamserve picks up each of the lines before processing the Streamfile.

When we replace the BEGIN statements with alternative text (in this case replacing them with the text “***BEGIN STATEMENT SKIPPED***”). Streamserve rejects the line, notes it in the Control Center log, and moves to the next line. Later in the process, we’ll see our skipped lines in the log.

Next, compile the code and create a SingleEvent.jar using your favorite tool. Copy the SingleEvent.jar to an accessible folder on the Streamserve server. Now we can begin prepping Streamserve to use Java.

Step 3: Prep Streamserve to use Java

Because we’ll be adding a filter on both the TCP/IN port and DirScan folder, it’s best to create a new Streamserve Application specifically for our new SingleEvent Streamfiles. We don’t want to place this filter on our base Streamserve Application and filter all Streamfiles. Follow the standard steps to create the new application in the correct domain in Control Center. For this example, we named our application “Dev_SingleEvent_22104” to indicate the domain, application purpose, and incoming port number. Next, right click on the application and select Java Configuration.

When the Java Configuration screen opens, we see the properties list. Click in the Value box and select the appropriate vendor. In my case, this was Oracle.

Next, we’ll need to import our SingleEvent.jar and add the new filter chain in the Streamserve Global_Resourceset. In the Global_Resourceset, right click and select “Import…”.

Navigate to the folder on the Streamserve server where you stored SingleEvent.jar. Highlight SingleEvent.jar and click Open.

Streamserve will automatically load the correct Resource Type (Java).

Click OK and your new Java resource will appear in the Global_Resourceset.

Now, let’s create our new filter chain. The filter chain is the heart of this transaction as Streamserve will filter the Streamfile through the Java program as it comes into the TCP port or is dropped into the DirScan folder.

First, navigate to the Filter Chain folder in the Global_Resourceset, right click and select New > Filter Chain.

We’ll name the filter chain “Platform – SingleEvent”. It will be used at both the TCP/IP and Directory input connectors.

Then, right click and select Start Editor.

There will be an existing Codepage Filter already in place. We won’t make any changes here. From the Filter Chain menu, select Add Filter > External Filter. Type “java.exe –jar ..\data\java\SingleEvent.jar” in the Value box, save and close.

Navigate to the Platform next, where we’ll copy/paste the standard TCP_MOVEX and DirScan_MOVEX input connectors and rename them as “SingleEvent_TCP_MOVEX” and “SingleEvent_DirScan_MOVEX”, respectively. Make the necessary changes to ports and input folders for the physical platform you’re using.

Now, we’ll add the Platform – SingleEvent filter chain to each of these input connectors. In the Platform, right click on the SingleEvent_TCP_MOVEX input connector and select Settings.

From the logical platform, click on the “Filter chain” button and add the new filter chain.

Repeat these steps for the SingleEvent_DirScan_MOVEX connector.

Verify all the changes, save and export the project and then deploy in Control Center to your new application.

Step 4: Test

To test, drop the Streamfile into the DirScan folder in the Management Gateway and see the Filter Chain at work in the Control Center log. Here is a snip from the log:

We can see our “Unknown line (ignored):***BEGIN STATEMENT SKIPPED***” message line and each duplicate header fields that has been ignored. We also see the “ExternFilter exitCode:0” message indicating the filter completed successfully.

Here is our new document with one event and multiple lines:

Final Thoughts

We’ve successfully written a Java class that works as a filter to remove unwanted BEGIN statements from a Streamfile, setup Streamserve to use Java and our new filter, and processed a test Streamfile through the filter. Let me know how it works for your project and any tweaks you made for it to deliver the document you want.

Special thanks to the posters at StreamShare whose excellent variety of posts on filtering and using Java with Streamserve allowed me to combine them to achieve a solution. If you work with Streamserve, make sure to check out the forums.

Now that we’ve seen how Java works with Streamserve, next time let’s discuss using Java to connect to M3 APIs and add information to a Streamserve PageOut.