一、配置環境:?
1.下載sapjco3.dll插件置放在JDK、bin文件夾下?
2.下載sapjco3.jar置放工程中
二、配置訪問屬性文件?
SAPConnectionPool.properties
#sap服務器IP地址,如果是外網訪問,則在內網IP前加/H/外網IP/H/192.168.0.10
jco
.client.ashost=
192.168.0.10
#系統編號
jco
.client.sysnr=
01
#配置client
jco
.client.client=
999
jco
.client.user=likb
jco
.client.passwd=
330330
jco
.destination.pool_capacity=
3
jco
.destination.peak_limit=
10
jco
.client.lang=
ZH
三、封裝獲取鏈接池鏈接Java類,以便接口使用時調用?
SAPConnectionPool類:
@Service(
"SAPConnectionPool")
public class SAPConnectionPool {private static final String SAP_CONN=
"SAP_CONN";
public static JCoDestination
getSAPDestination(){
try {JCoDestination dest = JCoDestinationManager.getDestination(SAP_CONN);
return dest;}
catch (JCoException ex) {System.out.println(ex);System.out.println(
"連接失敗");
return RegetJocodestination();} }
/****** @author :QZC* @createDate :2015年8月27日 上午11:08:47* 函數功能描述:重新獲取JCODestination* @return*****/public static JCoDestination
RegetJocodestination(){
try{Properties properFile =
new Properties();ClassLoader cl=Thread.currentThread().getContextClassLoader();String filePath=cl.getResource(
"").toString()+
"SAPConnectionPool.properties";filePath=filePath.replace(
"file:",
"");FileInputStream inputFile =
new FileInputStream(filePath);properFile.load(inputFile);inputFile.close();Properties connectProperties =
new Properties();connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, properFile.getProperty(
"jco.client.ashost"));connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, properFile.getProperty(
"jco.client.sysnr"));connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, properFile.getProperty(
"jco.client.client"));connectProperties.setProperty(DestinationDataProvider.JCO_USER, properFile.getProperty(
"jco.client.user"));connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, properFile.getProperty(
"jco.client.passwd"));connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, properFile.getProperty(
"jco.destination.pool_capacity"));connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, properFile.getProperty(
"jco.destination.peak_limit"));connectProperties.setProperty(DestinationDataProvider.JCO_LANG, properFile.getProperty(
"jco.client.lang"));CustomDestinationDataProvider provider =
new CustomDestinationDataProvider();provider.addDestinationProperties(SAP_CONN, connectProperties);Environment.registerDestinationDataProvider(provider);
try {JCoDestination dest = JCoDestinationManager.getDestination(SAP_CONN);
return dest;}
catch (JCoException ex) {System.out.println(ex);System.out.println(
"重新連接失敗");} }
catch(Exception e){e.printStackTrace();}
return null; }}
- 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
- 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
獲取鏈接的輔助處理類:CustomDestinationDataProvider.java
public class CustomDestinationDataProvider implements DestinationDataProvider {private Map providers =
new HashMap();
@Overridepublic Properties
getDestinationProperties(String destName) {
if (destName ==
null)
throw new NullPointerException(
"請指定目的名稱");
if (providers.size() ==
0)
throw new IllegalStateException(
"請加入一個目的連接參數屬性給提供者");
return (Properties)providers.get(destName);}
@Overridepublic boolean supportsEvents(){
return false;}
@Overridepublic void setDestinationDataEventListener(DestinationDataEventListener listener) {
throw new UnsupportedOperationException();}
public void addDestinationProperties(String destName, Properties provider) {providers.put(destName, provider);}
}
總結
以上是生活随笔為你收集整理的JCO3远程调用SAP接口随笔一(配置连接池)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。