
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.
For a more in-depth explanation, watch my video at:
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.