We need implement SAP client on java to listen IDoc
s.
We use
<properties>
<java.version>17</java.version>
<com.sap.conn.idoc.version>3.1.3</com.sap.conn.idoc.version>
<com.sap.conn.jco.version>3.1.7</com.sap.conn.jco.version>
<lib.directory>${project.build.directory}/lib</lib.directory>
</properties>
...
<dependencies>
<dependency>
<groupId>com.sap.conn.idoc</groupId>
<artifactId>com.sap.conn.idoc.sapidoc3</artifactId>
<version>${com.sap.conn.idoc.version}</version>
</dependency>
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>com.sap.conn.jco.sapjco3</artifactId>
<version>${com.sap.conn.jco.version}</version>
</dependency>
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>${com.sap.conn.jco.version}</version>
<classifier>external-library</classifier>
<type>dll</type>
</dependency>
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>libsapjco3</artifactId>
<version>${com.sap.conn.jco.version}</version>
<classifier>external-library</classifier>
<type>so</type>
</dependency>
</dependencies>
the client configuration:
Properties properties = new Properties();
properties.setProperty(DestinationDataProvider.JCO_ASHOST, host);
properties.setProperty(DestinationDataProvider.JCO_SYSNR, systemNumber);
properties.setProperty(DestinationDataProvider.JCO_CLIENT, client);
properties.setProperty(DestinationDataProvider.JCO_USER, username);
properties.setProperty(DestinationDataProvider.JCO_PASSWD, password);
properties.setProperty(DestinationDataProvider.JCO_LANG, language);
properties.setProperty(DestinationDataProvider.JCO_GWHOST, host);
properties.setProperty(DestinationDataProvider.JCO_GWSERV, gatewayService);
properties.setProperty(DestinationDataProvider.JCO_GROUP, group);
properties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, peakLimit);
Using remind propertied we create DestinationDataProvider
registering one in Environment Environment.registerDestinationDataProvider(destinationDataProvider)
then we can create JCoDestination
, JCoRepository
or IDocRepository
without issues.
JCoDestination jCoDestination = JCoDestinationManager.getDestination("MULE_IDOC_TEST");
JCoRepository jCoRepository = jCoDestination.getRepository();
IDocRepository iDocRepository = JCoIDoc.getIDocRepository(jCoDestination);
Finally I need IDoc listener. I described class for one:
import com.sap.conn.idoc.IDocDocument;
import com.sap.conn.idoc.IDocDocumentIterator;
import com.sap.conn.idoc.IDocDocumentList;
import com.sap.conn.idoc.jco.JCoIDocHandler;
import com.sap.conn.jco.server.JCoServerContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j(topic = "JCo IDoc Listener Logger")
public class JCoIDocListener implements JCoIDocHandler {
@Override
public void handleRequest(JCoServerContext jCoServerContext, IDocDocumentList iDocDocumentList) {
log.info("idocs something");
IDocDocumentIterator iterator = iDocDocumentList.iterator();
while (iterator.hasNext()) {
IDocDocument idoc = iterator.next();
log.info("idoc : {}", idoc.toString());
}
log.info("server: {}", jCoServerContext.getServer());
}
}
But I have no idea how to register it in SAP client Environment
.
Question 1
Can you please help me to register object based on JCoIDocListener
in SAP client Environment
?
Other way.
I described one more listener like:
import com.sap.conn.idoc.jco.JCoIDoc;
import com.sap.conn.jco.AbapClassException;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.server.JCoServerContext;
import com.sap.conn.jco.server.JCoServerFunctionHandler;
import lombok.extern.slf4j.Slf4j;
@Slf4j(topic = "JCo IDoc Server Listener Logger")
public class JCoIDocServerListener implements JCoServerFunctionHandler {
@Override
public void handleRequest(JCoServerContext jCoServerContext, JCoFunction jCoFunction)
throws AbapException, AbapClassException {
log.info("received something");
}
}
But the issue is also I have no idea how to register it in environment (beside that, it looks like server part).
Question 2
Should I change my configuration for client DestinationDataProvider
for using JCoIDocServerListener
? If yes, how? (i think some server properties should be specified)
How to register JCoIDocServerListener.class
?
These properties are superfluous in your DestinationDataProvider client configuration:
And yes, your JCoIDocListener class implements RFC server functionality for receiving IDocs. For registering an RFC server, you have to implement and register a ServerDataProvider using the same pattern as with your implementation for the DestinationDataProvider.
Then you can call JCoIDoc.getServer(String name) for getting your JCoIDocServer instance. Finally, this instance must be started by calling JCoIDocServer.start(), but only after setting your JCoIDocHandler and a TIDHandler for it.
I recommend to have a look into the SAP Java IDoc Library's small example program IDocServerExample.java which is shipped with the SDK.