JCO SERVER CONNECTION使用说明
JCo(Sap Java Connect 2010-01-09 22:03:02 阅读66 评论0 字号:大中小 订阅
1. Jco Server Connection实现要点
1) Implement the JCoServerFunctionHandler and the coding to be executed when the call is received.
2) Create an instance for your JCoServer implementation and start it with start().
1.1. 建立与sap端的连接
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "10.52.41.3");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "02");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "CRCTEST");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "12345678");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);
Properties servertProperties = new Properties();
servertProperties.setProperty(ServerDataProvider.JCO_GWHOST, "10.52.41.3");
servertProperties.setProperty(ServerDataProvider.JCO_GWSERV, "3302");
servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCODEMO");
servertProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");
servertProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");
createDataFile(SERVER_NAME1, "jcoServer", servertProperties);
}
其中ServerDataProvider.JCO_GWHOST 设置的是server端的ip地址,ServerDataProvider.JCO_GWSERV设置的是sap端的端口号。
1.2. StfcConnectionHandle类处理RFC
StfcConnectionHandle类继承JCoServerFunctionHandle接口,并重写了handleRequest(JCoServerContext serverCtx,JCoFunction function)方法。
New 一个DefaultServerHandlerFactory.FunctionHandlerFactory 对象,使用registerHandler(Function Name,stfcConnectionHandler)方法,前面一个参数是sap端所要调用的函数,后面一个参数是StfcConnectionHandler类的一个实例。
然后使用server name的setCallHandlerFactory(DefaultServerHandlerFactory.FunctionHandlerFactory factory)方法,就可以用server.start()了。
补充handleRequest(JCoServerContext serverCtx,JCoFunction function)功能:
function.getImportParameterList()用来获取sap call Function 传递过来的exporting参数。
function.getExportParameterList().setValue()用来设置importing参数。
1.3. Simple Server Connection 、With Exception Listener Server Connection 和 tRFC Server Connection
1.3.1. With Exception Server Connection 在Simple Server Connection 的基础上,register Listener Class.
MyThrowableListener eListener = new MyThrowableListener(); server.addServerErrorListener(eListener); server.addServerExceptionListener(eListener); |
MyThrowableListener 继承JCoServerErrorListener 和JCoServerExceptionListener 两个接口,重写了serverErrorOccurred() 和serverExceptionOccurred()方法。
1.3.2. tRFC Server Connection 在Simple Server Connection的基础上,通过TIDHandler实现事务型Connection。
myTIDHandler = new MyTIDHandler();
server.setTIDHandler(myTIDHandler);
MyTIDHandler类继承JCoServerTIDHandler 接口,重写了checkTID(),commit(),rollback(),confirmTID(),execute()方法。
使用了一个HashTable存储status(CREATED, EXECUTED, COMMITTED, ROLLED_BACK, CONFIRMED ),TIDState state = availableTIDs.get(tid)。如果status为null,则改变为CREATED,返回TRUE;如果status为CREATED或者ROLLED_BACK,则返回TRUE,其他返回FALSE。