Module:SAP ECC SOAP Communication/Developers Guide/How To Import And Export iDocs
Introduction
In this document is described how to use the SAP ECC SOAP Communication module for interchanging iDocs between Openbravo and a SAP Server.
Exporting IDocs
The first step to enable the IDoc exportation from Openbravo to SAP is to develop a consumer for the SOAP web service that exposes the operation to export the IDocs into SAP.
To define and configure this consumer, we need to develop a class that extends the SAPExportClient class. For example:
public class IDocExportClient extends SAPExportClient<IDocExportService> { public IDocExportClient(SOAPConfiguration configuration) { super(configuration); } @Override protected void export(IDocExportService service, Map<String, String> iDocsToExport) { // Call the service operation that exports the iDocs iDocsToExport.entrySet() .stream() .forEach(iDoc -> service.invoke(iDoc.getKey(), iDoc.getValue())); } @Override protected SOAPClient<IDocExportService> getSOAPClient(SOAPConfiguration soapConfiguration) { IDocSOAPExporter consumer = new IDocSOAPExporter(getIDocExportServiceImpl()); consumer.configure(soapConfiguration); return consumer; } private IDocExportService getIDocExportServiceImpl() { // return the implementation of the IDocExportService } }
class IDocSOAPExporter extends SOAPClient<IDocExportService> { IDocSOAPExporter() { super(new IDocExportService().getPort()); } void configure(SOAPConfiguration soapConfiguration) { // Configure the client // The SOAPConfiguration parameter can be used to get the AD configuration data Map<String, Object> requestData = new HashMap<>(); requestData.put(BindingProvider.USERNAME_PROPERTY, soapConfiguration.getMyUserField()); requestData.put(BindingProvider.PASSWORD_PROPERTY, soapConfiguration.getMyPassField()); setRequestData(requestData); } }
Some notes about the previous code:
- The IDocExportService is the implementation of the service that indeed executes the web service operation to export the IDocs. Typically this will be a Java stub class generated from the WSDL document that defines the SAP service.
- The IDocSOAPExporter is a class that we use to define the SOAPClient wrapper. This helps to configure the service implementation in an easy way by using its setRequestData and addInterceptors methods in order to set the request data (like the required credentials) and the outgoing interceptors (if any) respectively.
- The getSOAPClient method is the place where the service may be configured. Here it is possible to add custom configuration settings defined in the Application Dictionary by using the SOAPConfiguration argument.
- The export method should be use to invoke the service operation to export the IDoc information that is received through the map argument. The keys of the map are the proposals for the file names to be created in the SAP ECC server and the values are the contents of the IDocs to be exported.
The second step consist of registering our SAPExportClient class into the Application Dictionary. This is done by creating a SOAP configuration into the Communication with SAP ECC Server window:
In the header:
- Communication Protocol: SOAP
In the SOAP Configuration tab:
- Export Client Class Name: the name of our SAPExportClient class
Note the SOAP Configuration tab is the place to add additional configuration settings (like HTTP basic credentials). This can be done by adding new fields into this tab. The value of this new fields can be retrieved in the getSOAPClient method of our SAPExportClient as explained above.
Importing IDocs
For importing IDocs coming from SAP into Openbravo a SOAP web service is exposed by default at:
<openbravo_url>/org.openbravo.base.cxf/sapImportService?wsdl
This web receives an IDoc that is processed asynchronously using the default SAP import process.
See here to find a guide that explains how SOAP web services can be consumed.