Java Class to connect to WMS and run MOCA
- thecodingguy
- May 1
- 1 min read
Updated: May 2
This class is a utility class I wrote to connect to a JDA / BlueYonder WMS environment from Java and run MOCA commands. The constructor requires the WMS user id, password, URL, and warehouse id. Once connected, the executeMoca() methods can be used to execute MOCA commands ( with or without arguments ) and will return a MocaResults object.
Note the moca-core.jar file must be in the classpath for this class to work.
package com.thecodingguy.wms.samples;
import com.redprairie.moca.MocaArgument;
import java.util.HashMap;
import java.util.Map;
import com.redprairie.moca.MocaException;
import com.redprairie.moca.MocaResults;
import com.redprairie.moca.client.ConnectionUtils;
import com.redprairie.moca.client.MocaConnection;
public class WMSConnectionManager {
protected String wms_user;
protected String wms_pw;
protected String wms_url;
protected String wms_wh_id;
protected MocaConnection wms_connection;
public WMSConnectionManager ( String wms_user_in, String wms_pw_in, String wms_url_in, String wms_wh_id_in ) {
this.wms_user = wms_user_in;
this.wms_pw = wms_pw_in;
this.wms_url = wms_url_in;
this.wms_wh_id = wms_wh_id_in;
}
public void connect() throws MocaException {
Map<String, String> env = new HashMap<String, String>();
env.put("WH_ID", this.wms_wh_id);
wms_connection = ConnectionUtils.createConnection(this.wms_url, env);
ConnectionUtils.login(wms_connection, this.wms_user, this.wms_pw);
}
public void close() throws MocaException {
if (wms_connection != null) {
wms_connection.close();
}
}
public MocaResults executeMoca(String command_in) throws MocaException {
MocaResults res = wms_connection.executeCommand(command_in );
return res;
}
public MocaResults executeMoca(String command_in, MocaArgument[] args) throws MocaException {
MocaResults res = wms_connection.executeCommandWithArgs(command_in, args);
return res;
}
}
