OFBiz调用SAP
package org.ofbiz.rfc;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class JCOClientDemo {
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.168.1.10");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "10");
// connectProperties.setProperty(DestinationDataProvider.JCO_R3NAME, "C01");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "USER_1");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "password1");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(ABAP_AS, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "5");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties) {
File cfg = new File(name + "." + suffix);
if (!cfg.exists()) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
} finally {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
public static void call() throws JCoException {
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("STFC_CONNECTION");
if (function == null)
throw new RuntimeException("STFC_CONNECTION not found in SAP.");
function.getImportParameterList().setValue("REQUTEXT", "Hello SAP");
try {
function.execute(destination);
} catch (AbapException e) {
System.out.println(e.toString());
return;
}
System.out.println("STFC_CONNECTION finished:");
System.out.println(" Echo: " + function.getExportParameterList().getString("ECHOTEXT"));
System.out.println(" Response: " + function.getExportParameterList().getString("RESPTEXT"));
System.out.println();
}
public static void main(String[] args) {
try {
JCOClientDemo.call();
} catch (JCoException e) {
e.printStackTrace();
}
}
}
页:
[1]