Sterling Managed File Transfer

Sterling Managed File Transfer

Come for answers, stay for best practices. All we're missing is you.

 View Only

AS2 User Exit for inserting a custom message

By Tanvi Kakodkar posted Tue March 03, 2020 02:29 AM

  
Originally updated on October 4, 2018 by HarishBM

AS2 User Exit for inserting a custom message for track and trace of an inbound file in SB2Bi

User exit allows one to hook custom java code during certain predefined operations. Availability of User Exit points is nothing but Java Interface made available for users' custom implementation based on customer specific requirement


New User Exits for AS2 and corresponding Java Interfaces:

Post File Upload Append: com.sterlingcommerce.woodstock.userexit.services.as2.interfaces. IAs2ServerUserExit_OnPutSuccessAddCustomMessage

Allows you to execute your code for tracking/tracing the file further when AS2 has received file and this custom code is used to track and trace the file. Customer can specify custom message to be displayed in the MDN screen

Java Doc API for these interfaces are available under install/userexit/docs folder.


Sample User Exit Implementation

Let me take one user exit scenario here and explain how to implement custom code with the help of the above Java Interfaces and plug it into SB2Bi.

  1. User Exit Scenario: To display a Reference Number at the end of the successful inbound file coming into customer’s AS2 system of SB2Bi.

Here are the parameters offered by IAs2ServerUserExit_OnPutSuccessAddCustomMessage. As mentioned above Java Doc APIs for these interfaces are available under install/userexit/docs folder.

package com.sterlingcommerce.woodstock.userexit.services.as2.interfaces;
import java.util.Map;
public interface IAs2ServerUserExit_OnPutSuccessAddCustomMessage {
        public static final String KEY_LOG_BUFFER = "logBuffer";
        public static final String KEY_SUCC_BUFFER = "successMessage";
        public static final String KEY_ERROR_BUFFER = "errorsMessage";
        public static final String AS2_TO = "ssTo";
        public static final String MESSAGE_ID = "ssMessageID";
        public static final String AS2_FROM = "ssFrom";
        public static final String RECEIVED_CONTENT_MIC = "ssReceivedContentMIC";
        public static final String AS2_ORIGINAL_MESSAGE_ID = "ssOriginalMessageID";
        public static final String FINAL_RECIPIENT = "ssFinalRecipient";
        public boolean onPutSuccessAddCustomMessage(Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
}

 

 

  1. Next is to implement your custom class to achieve this. Here is what I wrote for this scenario.

package com.ibm.as2ue;

 

import com.sterlingcommerce.woodstock.userexit.services.as2.interfaces.IAs2ServerUserExit_OnPutSuccessAddCustomMessage;

import java.util.Map;

import java.io.*;

import java.util.UUID;

 

public class  AS2_Custom_Message implements IAs2ServerUserExit_OnPutSuccessAddCustomMessage {

 

        public static final String KEY_LOG_BUFFER = "logBuffer";

        public static final String KEY_SUCC_BUFFER = "successMessage";

 

        public boolean onPutSuccessAddCustomMessage(Map<String, Object> in, Map<String, Object> out) throws Exception {

        String METHOD_NAME = "onPutSuccessAddCustomMessage";

        try {

                System.out.println("USEREXIT AS2 IBM INPUT PARAMETERS = "+in);

                String customMessage = getScotiaTicketNumber();

                ((StringBuffer)out.get(IAs2ServerUserExit_OnPutSuccessAddCustomMessage.KEY_SUCC_BUFFER)).append(customMessage);

                System.out.println("SCOTIA_AS2 USEREXIT CODE CUSTOM MESSAGE = "+customMessage);

                System.out.println("USEREXIT AS2 IBM OUTPUT PARAMETERS = "+out);

 

        } catch (Exception e) {

                e.printStackTrace(System.out);

        }

        return true;

     }

 

    public static String getScotiaTicketNumber() {

        String scotiaTicketNumber = UUID.randomUUID().toString();

        return "TICKET NUMBER = "+scotiaTicketNumber;

    }

}

 

  1. Compile this custom java program

javac -cp as2server.jar  -d  .  AS2_Custom_Message.java

NOTE: as2server.jar is available under install/userexit/jars folder

  1. Create a jar with this classs

jar -cvf <FileName.jar> com

  1. Plug this jar file to SB2Bi using ./install3rdParty.sh script

cd $<SB2Bi_Install_Direcxtory>/install/bin

./install3rdParty.sh < as2userexit> 1_0 -j <jar filename created in Step#4>

       6. Add custom class name from #5 into install/properties/userexit/As2ServerUserExits.xml under corresponding user exit bean tag.

 

<bean id="com.sterlingcommerce.woodstock.userexit.services.as2.interfaces.IAs2ServerUserExit_OnPutSuccessAddCustomMessage" class="com.sterlingcommerce.woodstock.userexit.services.as2.As2ServerUserExit">

     <property name="implementations">

           <list>

               <value>com.ibm.as2ue.AS2_Custom_Message</value>

           </list>

      </property>

      <property name="generalParameters">

            <props>

                    <prop key="return.on.exception">false</prop>

                    <prop key="pool.size">5</prop>

                    <prop key="maximum.queue.length">5</prop>

                    <prop key="wait.time">10</prop>

                    <prop key="execution.threshold.time">600000</prop>

             </props>

       </property>

</bean>

 

  1. Start B2B SI to take all these changes effective.
  2. Testing and Observation

Try Sending a file onto SB2Bi using AS2. Below is the MDN screen with the Custom Message displayed in it. Custom message can be anything returned from the userexit implementation program in this case it is a Ticket number which is used to track and trace the inbound message received by AS2

 

noapp.log shows lines correspond to System.out in custom class for troubleshooting.

 

NOTE: This feature is available in the upcoming product release 6.0; Please contact the product management for details


#IBMSterlingB2BIntegratorandIBMSterlingFileGatewayDevelopers
#DataExchange
0 comments
22 views

Permalink