SAPConn.java
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.huaheng.common.sapJco;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
/**
* 与SAP连接配置
* @author jay
*/
public class SAPConn {
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.168.102.78"); //服务器
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00"); //系统编号
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800"); //SAP集团
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "HT_WMSHH"); //用户名
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "ht654321"); //密码
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH"); //登录语言
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3"); //最大连接数
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "100"); //最大线程数
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
/**
* 创建SAP接口属性文件。
* @param name ABAP管道名称
* @param suffix 属性文件后缀
* @param properties 属性文件内容
*/
private static void createDataFile(String name, String suffix, Properties properties){
File cfg = new File(name+"."+suffix);
if(cfg.exists()){
cfg.deleteOnExit();
}
try{
FileOutputStream 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);
}
}
/**
* 获取SAP连接
* @return SAP连接对象
*/
public static JCoDestination connect(){
JCoDestination destination =null;
try {
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
} catch (JCoException e) {
}
return destination;
}
}