import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.JCoParameterList;
import com.sap.conn.jco.JCoTable;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class ConnectPooled {// 鏈接池
private static Log log = LogFactory.getLog(ConnectPooled.class);
static String ABAP_AS_POOLED_XG_PRE = "ABAP_AS_POOLED_XG_PRE";
static String ABAP_AS_POOLED_R3_DEV = "ABAP_AS_POOLED_R3_DEV";
static {
config("192.168.118.xx");// dev
config("10.242.6.xxx");// pre
}
private static void config(String ip) {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, ip);
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
connectProperties
.setProperty(DestinationDataProvider.JCO_CLIENT, "200");
connectProperties.setProperty(DestinationDataProvider.JCO_USER,
"1504xxxx");
// 注:密碼是區分大小寫的,要注意大小寫
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,
"axxxxxx");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
// *********鏈接池方式與直接不一樣的是設置了下面兩個鏈接屬性
// JCO_PEAK_LIMIT - 同時可建立的最大活動鏈接數,0表示無限制,默認爲JCO_POOL_CAPACITY的值
// 若是小於JCO_POOL_CAPACITY的值,則自動設置爲該值,在沒有設置JCO_POOL_CAPACITY的狀況下爲0
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,
"10");
// JCO_POOL_CAPACITY - 空閒鏈接數,若是爲0,則沒有鏈接池效果,默認爲1
connectProperties.setProperty(
DestinationDataProvider.JCO_POOL_CAPACITY, "3");
createDataFile(ABAP_AS_POOLED_XG_PRE, "jcoDestination",
connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties) {
File cfg = new File(name + "." + suffix);
if (!cfg.exists()) {
try {
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
log.error("", e);
}
}
}
/**
* 根據輸入的傳輸請求號,從DEV上獲取傳輸請求所對應的傳輸文件
* @param REQUESTNO
* @return
* @throws JCoException
*/
public static JCoTable getTransRequestFiles(String REQUESTNO)
throws JCoException {
JCoDestination destination = JCoDestinationManager
.getDestination(ABAP_AS_POOLED_R3_DEV);
JCoFunction function = destination.getRepository().getFunction(
"ZXG_PRE_FUC");// 從對象倉庫中獲取 RFM 函數
if (function == null)
throw new RuntimeException("ZXG_PRE_FUC not found in SAP.");
JCoParameterList jpl = function.getImportParameterList();
jpl.setValue("REQUESTNO", REQUESTNO);
try {
function.execute(destination);
} catch (AbapException e) {
log.error("", e);
return null;
}
jpl = function.getExportParameterList();
JCoTable jt = jpl.getTable("FILES");
return jt;
}
/**
* 將DEV上的傳輸請求文件上傳到PRE上去,並實現後繼的自動發佈過程
* @param jt
* @param req
* @throws JCoException
*/
public static void sendTransReqFiles2xgpre(JCoTable jt, String req)
throws JCoException {
JCoDestination destination = JCoDestinationManager
.getDestination(ABAP_AS_POOLED_XG_PRE);
JCoFunction function = destination.getRepository().getFunction(
"ZXG_PRE_FUC");// 從對象倉庫中獲取 RFM 函數
if (function == null)
throw new RuntimeException("ZXG_PRE_FUC not found in SAP.");
function.getImportParameterList().setValue("FILES", jt);
function.getImportParameterList().setValue("REQUESTNOS", req);
try {
function.execute(destination);
} catch (AbapException e) {
log.error("", e);
}
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.sap.conn.jco.JCoException;
@Controller
@RequestMapping("/xgpresync")
public class XGPRECtrl {
private static Log log = LogFactory.getLog(XGPRECtrl.class);
@RequestMapping("/gettransreq")
public void gettransreq(HttpServletRequest request,
HttpServletResponse response, String transreq) throws JCoException {
log.info("reqs:" + transreq);
try {
ConnectPooled.sendTransReqFiles2xgpre(
ConnectPooled.getTransRequestFiles(transreq), transreq);
JsonPrintUtil.printJson(response, true, "", "");
} catch (Exception e) {
log.error("", e);
JsonPrintUtil.printJson(response, false, e.getMessage(), "");
}
}
}
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">html