Originally updated on October 4, 2018 by HarishBM |
FTP 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 pre-defined 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 FTP Server and corresponding Java Interfaces:
Post File Upload Append: com.sterlingcommerce.woodstock.userexit.services.ftpserver.interfaces. IFtpServerUserExit_OnPutSuccessAddCustomMessage
Allows you to execute your code for tracking/tracing the file further when FTP server has received file and this custom code is used to track and trace the file. Customer can specify custom message to be displayed at client end with 226 response code.
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.
- User Exit Scenario: To display a Reference Number at the end of the successful file transfer into SB2Bi FTP Server.
Here are the parameters offered by IFtpServerUserExit_OnPutSuccessAddCustomMessage. As mentioned above Java Doc APIs for these interfaces are available under install/userexit/docs folder.
package com.sterlingcommerce.woodstock.userexit.services.ftpserver.interfaces;
import java.util.Map;
public interface IFtpServerUserExit_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 KEY_INSTANCE_NAME = "instanceName";
public static final String KEY_CLIENT_ADDRESS = "clientAddress";
public static final String KEY_CLIENT_PORT = "clientPort";
public static final String KEY_SERVER_ADDRESS = "serverAddress";
public static final String KEY_SERVER_PORT = "serverPort";
public static final String KEY_USER_ID = "userId";
public static final String KEY_COMMAND_NAME = "command";
public static final String KEY_FILE_NAME = "fileName";
public static final String KEY_FILE_SIZE = "fileSize";
public static final String KEY_PATH = "path";
public static final String KEY_TRANSFER_TYPE = "transferType";
public static final String KEY_INPUT_STREAM = "input";
public static final String KEY_CONTENT_TYPE = "contentType";
public static final String KEY_CHAR_ENCODING = "charEncoding";
public static final String KEY_DOCUMENT_ID = "docID";
public static final String KEY_IS_SECURE = "isSecure";
public boolean onPutSuccessAddCustomMessage(Map<String, Object> inargs, Map<String, Object> outargs) throws Exception;
}
- Next is to implement your custom class to achieve this. Here is what I wrote for this scenario.
package com.ibm.ftpue;
import com.sterlingcommerce.woodstock.userexit.services.ftpserver.interfaces.IFtpServerUserExit_OnPutSuccessAddCustomMessage;
import java.util.Map;
import java.util.UUID;
public class FTP_Custom_Message implements IFtpServerUserExit_OnPutSuccessAddCustomMessage {
public static final String CLASS_NAME = "FTP_Custom_Message";
public static final String KEY_LOG_BUFFER = "logBuffer";
public static final String KEY_SUCC_BUFFER = "successBuffer";
public boolean onPutSuccessAddCustomMessage(Map<String, Object> in, Map<String, Object> out) throws Exception {
try {
System.out.println("FTP_USEREXIT INPUT PARAMETERS = "+in);
String customMessage = getScotiaTicketNumber();
System.out.println("FTP_USEREXIT - FILE NAME = "+in.get(IFtpServerUserExit_OnPutSuccessAddCustomMessage.KEY_FILE_NAME));
System.out.println("FTP_USEREXIT - DOCUMENT ID = "+in.get(IFtpServerUserExit_OnPutSuccessAddCustomMessage.KEY_DOCUMENT_ID));
((StringBuffer)out.get(IFtpServerUserExit_OnPutSuccessAddCustomMessage.KEY_SUCC_BUFFER)).append(customMessage);
System.out.println("FTP_USEREXIT - CUSTOM MESSAGE = "+out.get(IFtpServerUserExit_OnPutSuccessAddCustomMessage.KEY_SUCC_BUFFER));
System.out.println("FTP_USEREXIT - THIS CUSTOM MESSAGE = "+customMessage);
} catch (Exception e) {
e.printStackTrace(System.out);
}
return true;
}
public static String getScotiaTicketNumber() {
String scotiaTicketNumber = UUID.randomUUID().toString();
return "TICKET NUMBER = "+scotiaTicketNumber;
}
}
- Compile this custom java program
javac -cp ftpserver.jar -d . FTP_Custom_Message.java
NOTE: ftpserver.jar is available under install/userexit/jars folder
- Create a jar with this classs
jar -cvf <FileName.jar> com
- Plug this jar file to SB2Bi using ./install3rdParty.sh script
cd $<SB2Bi_Install_Direcxtory>/install/bin
./install3rdParty.sh < ftpuserexit> 1_0 -j <jar filename created in Step#4>
- Add custom class name from #5 into install/properties/userexit/FtpServerUserExits.xml under corresponding user exit bean tag.
<bean id="com.sterlingcommerce.woodstock.userexit.services.ftpserver.interfaces.IFtpServerUserExit_OnPutSuccessAddCustomMessage" class="com.sterlingcommerce.woodstock.userexit.services.ftpserver.FtpServerUserExit">
<property name="implementations">
<list>
<value>com.ibm.ftpue.FTP_Custom_Message</value>
</list>
</property>
<property name="generalParameters">
<props>
<prop key="return.on.exception">false</prop>
<prop key="pool.size">100</prop>
<prop key="maximum.queue.length">500</prop>
<prop key="wait.time">60</prop>
<prop key="execution.threshold.time">600000</prop>
</props>
</property>
</bean>
- Start B2B SI to take all these changes effective.
- Testing and Observation
Try uploading a file onto SB2Bi FTP Server
Using any other client, if you upload a file, kindly check the corresponding the log file , there will be an entry as shown below. For ex: Using FileZilla
2018-06-07 11:42:24 5956 3 Response: 226 Closing data connection, Binary transfer complete. TICKET NUMBER = f69d9f0d-febf-4c48-ac27-746a8ee53e2f
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