Here is how to call M3 API using the MI-WS application proxy of the Infor Grid.
This is useful if we want to benefit from what is already setup in the Grid and not have to deal with creating our own connection to the M3 API server with Java library, hostname, port number, userid, password, connection pool, etc.
Note: For details on what Grid application proxies are, refer to the previous post.
MI-WS application proxy
The MI-WS application is part of the M3 Business Engine Foundation. We will need foundation-client.jar to compile our classes:
Step 1. Logon to the Grid
First, login to the Grid from your application and get a SessionId and optionally a GridPrincipal.
From a Grid application:
import com.lawson.grid.proxy.access.GridPrincipal; import com.lawson.grid.proxy.access.SessionController; import com.lawson.grid.proxy.access.SessionId; // get session id SessionId sid = ??? // PENDING GridPrincipal principal = ??? // PENDING;
From a client application outside the Grid:
import com.lawson.grid.proxy.access.GridPrincipal; import com.lawson.grid.proxy.access.SessionId; import com.lawson.grid.proxy.access.SessionProvider; import com.lawson.grid.proxy.access.SessionUtils; import com.lawson.grid.proxy.ProxyException; // logon and get session id SessionUtils su = SessionUtils.getInstance(registry); SessionProvider sp = su.getProvider(SessionProvider.TYPE_USER_PASSWORD); SessionId sid; try { sid = sp.logon(userid, password.toCharArray()); } catch (ProxyException e) { ... } GridPrincipal principal = su.getPrincipal(sid);
Step 2. Call the M3 API
Second, call the M3 API, for example CRS610MI.LstByNumber, and get the result:
import java.util.ArrayList; import java.util.List; import com.lawson.grid.proxy.ProxyClient; import com.lawson.grid.proxy.ProxyException; import com.lawson.miws.api.data.MIParameters; import com.lawson.miws.api.data.MIParameters.ColumnList; import com.lawson.miws.api.data.MIRecord; import com.lawson.miws.api.data.MIResult; import com.lawson.miws.api.MITransactionException; import com.lawson.miws.proxy.MIAccessProxy; // get the proxy MIAccessProxy proxy = (MIAccessProxy)registry.getProxy(MIAccessProxy.class); // login to M3 ProxyClient.setSessionId(proxy, sid); // prepare the parameters MIParameters paramMIParameters = new MIParameters(); paramMIParameters.setProgram("CRS610MI"); paramMIParameters.setTransaction("LstByNumber"); paramMIParameters.setMaxReturnedRecords(10); // set the return columns ColumnList returnColumns = new ColumnList(); List<String> returnColumnNames = new ArrayList<String>(); returnColumnNames.add("CONO"); returnColumnNames.add("CUNO"); returnColumnNames.add("CUNM"); returnColumns.setReturnColumnNames(returnColumnNames); paramMIParameters.setReturnColumns(returnColumns); // execute MIResult result; try { result = proxy.execute(paramMIParameters); } catch (MITransactionException e) { ... } catch (ProxyException e) { ... } // show the result List<MIRecord> records = result.getResult(); for (MIRecord record: records) { record.toString(); }
Note: When I use ColumnList it throws java.io.NotSerializableException: com.lawson.miws.api.data.MIParameters$ColumnList. It appears to be a bug in that the ColumnList class is missing implements Serializable
. I reported it in Infor Xtreme incident 8629267.
That’s it. Please let me know what you think in the comments below.
UPDATE: Also, I just got java.io.NotSerializableException: com.lawson.miws.api.MITransactionExceptionDetail. Updated Infor Xtreme ticket.
LikeLike
UPDATE: The code I used to logon in a Grid application doesn’t work. PENDING
LikeLike
UPDATE: Also, it should be possible for the grid proxy client to authenticate with a certificate signed by the grid root key of the keystore server.ks. To be tested.
LikeLike