Searching SAP PI/PO message content with module development

Update 2022 This tool have been a round for a long time the service we ended up does not seem to have been evolving since 2010 when i wrote the original code. 
In the Figaf Tool, we have add a monitoring solution. This will allow you do download all payloads for message processing. This is the preferred way to have payload archived in a simple way.
I was talking with a friend about searching content and how easy it would be to implement your own search solution.
After taking a look at search APIs, such as Amazon’s, and having long discussions with a friend, I came across this useful page: https://www.searchify.com/documentation/java-client
I thought it would be a good project to start my development and be able to develop better solutions for searching. It would be fun to see how easy it is be to integrate this with the SAP PI/PO/XI module framework.
Spoiler: It is way too easy. 
As a seasoned PI consultant, I wanted to create an archiving solution that would make a developer’s work easier. Specifically, I wanted to create an archiving module that would store a lot of metadata on the file, while also adding a useful search function to it. This is how www.piarchiving.com was born, it is no longer being maintained because there is other solutions. Some of the newer user-defined message search modules also have different search criteria for text and so does HANA.

After gathering my ideas, I had created a module. In only takes one hour to learn and implement the code in an SAP PI module.

To get started, you need to add the API URL that should be used. The next step is to create and add the Index. After these steps, the content should be put into the text field and uploaded. A step-by-step explanation is shown in my video, with examples on how to find message IDs after the completion of keyword-based searches.


This is an easy application for those who wish to search through all of their content using Searchify in a PI/PO context. It is good for scenarios where you don’t have a HANA instance to save and search through messages.

It is also quite inexpensive, at only $59 per month which will not let you run much servers.
If this was to be used in a real scenario, there should be a focus on creating more stable code and an asynchronous process. Obviously, a better front end would also be needed.

For a more in-depth explanation, watch my video at:
The code is the following
package com.figaf.po.module.search;

import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

import com.flaptor.indextank.apiclient.IndexTankClient;
import com.sap.aii.af.lib.mp.module.Module;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.Payload;

public class SearchModule implements SessionBean, Module {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -91519383171871089L;

	

	 public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
			throws ModuleException {

		   IndexTankClient client = new IndexTankClient(API_URL);
			  
		    try {
		    	com.flaptor.indextank.apiclient.IndexTankClient.Index index = client.getIndex("daniel");
		    	
		    	 Message msg = (Message) inputModuleData.getPrincipalData();
		 		Payload payload = msg.getMainPayload();
		 		byte[] contentString = payload.getContent();
		    
				String documentId = msg.getMessageId();
				Map<String, String> fields = new HashMap<String, String>();
				fields.put("text", new String(contentString));
				fields.put("timestamp", 
			            Long.toString(System.currentTimeMillis() / 1000L));
				index.addDocument(documentId, fields);
		    }catch(Exception e){
		    	throw new ModuleException("Unable to save msg to index "+e.getMessage(),e);
		    }
		    
		 return inputModuleData;
	 }

	  private final static String API_URL = 
		    "http://:[email protected]";
	  
			@Override
		public void ejbActivate() throws EJBException, RemoteException {
			// TODO Auto-generated method stub
			
		}


		@Override
		public void ejbPassivate() throws EJBException, RemoteException {
			// TODO Auto-generated method stub
			
		}


		@Override
		public void ejbRemove() throws EJBException, RemoteException {
			// TODO Auto-generated method stub
			
		}


		@Override
		public void setSessionContext(SessionContext arg0) throws EJBException,
				RemoteException {
			// TODO Auto-generated method stub
			
		}
}

The post Searching SAP PI/PO message content with module development appeared first on SAP PI course.

Simplify your SAP Integration in under 10 minutes with Figaf DevOps Suite on Cloud.

 
No credit card is required. 30 days free trial.

Latest Articles