import java.util.Hashtable;
import java.util.Map;
import com.sap.conn.jco.JCo;
import com.sap.conn.jco.JCoCustomRepository;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoFunctionTemplate;
import com.sap.conn.jco.JCoListMetaData;
import com.sap.conn.jco.JCoMetaData;
import com.sap.conn.jco.server.DefaultServerHandlerFactory;
import com.sap.conn.jco.server.JCoServer;
import com.sap.conn.jco.server.JCoServerContext;
import com.sap.conn.jco.server.JCoServerContextInfo;
import com.sap.conn.jco.server.JCoServerErrorListener;
import com.sap.conn.jco.server.JCoServerExceptionListener;
import com.sap.conn.jco.server.JCoServerFactory;
import com.sap.conn.jco.server.JCoServerFunctionHandler;
import com.sap.conn.jco.server.JCoServerState;
import com.sap.conn.jco.server.JCoServerStateChangedListener;
import com.sap.conn.jco.server.JCoServerTIDHandler;
public class StepByStepServer
{
static String SERVER_NAME1 = "SERVER";
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static MyTIDHandler myTIDHandler = null;
/**
* This class provides the implementation for the function STFC_CONNECTION. You will
* find the RFC-enabled function STFC_CONNECTION in almost any ABAP system. The
* function is pretty simple - it has 1 input parameter and 2 output parameter. The content
* of the input parameter REQUTEXT is copied to the output parameter ECHOTEXT. The
* output parameter RESPTEXT is set to "Hello World".
*/
static class StfcConnectionHandler implements JCoServerFunctionHandler
{
public void handleRequest(JCoServerContext serverCtx, JCoFunction function)
{
System.out.println("----------------------------------------------------------------");
System.out.println("call : " + function.getName());
System.out.println("ConnectionId : " + serverCtx.getConnectionID());
System.out.println("SessionId : " + serverCtx.getSessionID());
System.out.println("TID : " + serverCtx.getTID());
System.out.println("repository name : " + serverCtx.getRepository().getName());
System.out.println("is in transaction : " + serverCtx.isInTransaction());
System.out.println("is stateful : " + serverCtx.isStatefulSession());
System.out.println("----------------------------------------------------------------");
System.out.println("gwhost: " + serverCtx.getServer().getGatewayHost());
System.out.println("gwserv: " + serverCtx.getServer().getGatewayService());
System.out.println("progid: " + serverCtx.getServer().getProgramID());
System.out.println("----------------------------------------------------------------");
System.out.println("attributes : ");
System.out.println(serverCtx.getConnectionAttributes().toString());
System.out.println("----------------------------------------------------------------");
System.out.println("CPIC conversation ID: " + serverCtx.getConnectionAttributes().getCPICConversationID());
System.out.println("----------------------------------------------------------------");
System.out.println("req text: " + function.getImportParameterList().getString("REQUTEXT"));
function.getExportParameterList().setValue("ECHOTEXT", function.getImportParameterList().getString("REQUTEXT"));
function.getExportParameterList().setValue("RESPTEXT", "Hello World");
// In sample 3 (tRFC Server) we also set the status to executed:
if(myTIDHandler != null)
myTIDHandler.execute(serverCtx);
}
}
/**
* First server example. At first we get an instance of the JCoServer through JCoServerFactory. The requested instance
* will be created, or an existing one will be returned if the instance was created before. It is not possible to
* run more then one instance with a particular configuration. Then we register the implementation for the
* function STFC_CONNECTION provided by class StfcConnectionHandler through FunctionHandlerFactory
* provided by JCo. You are free to write your own implementation JCoServerFunctionHandlerFactory, if you need more
* than simple mapping between function name and java class implementing the function.
* Now we can start the server instance. After a while the JCo runtime opens the server connections. You may
* check the server connections via sm59 or invoke STFC_CONNECTION via se37.
*/
static void step1SimpleServer()
{
JCoServer server;
try
{
server = JCoServerFactory.getServer(SERVER_NAME1);
}
catch(JCoException ex)
{
throw new RuntimeException("Unable to create the server " + SERVER_NAME1 + " because of " + ex.getMessage(), ex);
}
JCoServerFunctionHandler stfcConnectionHandler = new StfcConnectionHandler();
DefaultServerHandlerFactory.FunctionHandlerFactory factory = new DefaultServerHandlerFactory.FunctionHandlerFactory();
factory.registerHandler("STFC_CONNECTION", stfcConnectionHandler);
server.setCallHandlerFactory(factory);
server.start();
System.out.println("The program can be stoped using <ctrl>+<c>");
}
static class MyThrowableListener implements JCoServerErrorListener, JCoServerExceptionListener
{
public void serverErrorOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Error error)
{
System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
error.printStackTrace();
}
public void serverExceptionOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Exception error)
{
System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
error.printStackTrace();
}
}
static class MyStateChangedListener implements JCoServerStateChangedListener
{
public void serverStateChangeOccurred(JCoServer server, JCoServerState oldState, JCoServerState newState)
{
// Defined states are: STARTED, DEAD, ALIVE, STOPPED;
// see JCoServerState class for details.
// Details for connections managed by a server instance
// are available via JCoServerMonitor.
System.out.println("Server state changed from " + oldState.toString() + " to " + newState.toString() + " on server with program id "
+ server.getProgramID());
}
}
static void step2SimpleServer()
{
JCoServer server;
try
{
server = JCoServerFactory.getServer(SERVER_NAME1);
}
catch(JCoException ex)
{
throw new RuntimeException("Unable to create the server " + SERVER_NAME1 + " because of " + ex.getMessage(), ex);
}
JCoServerFunctionHandler stfcConnectionHandler = new StfcConnectionHandler();
DefaultServerHandlerFactory.FunctionHandlerFactory factory = new DefaultServerHandlerFactory.FunctionHandlerFactory();
factory.registerHandler("STFC_CONNECTION", stfcConnectionHandler);
server.setCallHandlerFactory(factory);
// additionally to step 1
MyThrowableListener eListener = new MyThrowableListener();
server.addServerErrorListener(eListener);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sapjco3-NTintel-3.0.14.zip【x86】【201601】 (236个子文件)
sap.css 4KB
sapjco3.dll 4.13MB
inherit.gif 57B
index-all.html 375KB
JCoRecord.html 130KB
JCo.html 85KB
releasenotes.html 79KB
DestinationDataProvider.html 77KB
JCoException.html 76KB
constant-values.html 72KB
JCoMetaData.html 66KB
JCoDestination.html 60KB
JCoServer.html 57KB
JCoField.html 49KB
JCoListMetaData.html 43KB
Environment.html 38KB
JCoRepository.html 36KB
JCoTable.html 34KB
ServerDataProvider.html 34KB
JCoClassMetaData.html 33KB
JCoRecordMetaData.html 32KB
overview-tree.html 30KB
JCoException.html 30KB
JCoAttributes.html 29KB
JCoConnectionData.html 29KB
package-use.html 28KB
AbapClassException.html 27KB
JCoFunction.html 25KB
JCoRequest.html 24KB
package-summary.html 24KB
JCoParameterList.html 24KB
JCoServerContext.html 23KB
JCoCustomDestination.html 23KB
DefaultServerHandlerFactory.html 23KB
JCoDestinationManager.html 22KB
JCoRuntimeException.html 22KB
JCoDestination.html 22KB
AbapException.html 21KB
JCoCustomRepository.html 21KB
DefaultSessionReferenceProvider.html 20KB
JCoDestinationMonitor.html 20KB
JCoBackgroundUnitAttributes.html 20KB
JCoStructure.html 19KB
JCoRecordMetaData.html 18KB
JCoAbapObject.html 18KB
package-tree.html 18KB
JCoFunctionTemplate.html 18KB
SessionReferenceProvider.html 18KB
JCoResponse.html 18KB
JCoServerUnitIDHandler.html 18KB
JCoListMetaData.html 18KB
JCoUnitIdentifier.html 17KB
JCoCustomDestination.UserData.html 17KB
DefaultServerHandlerFactory.FunctionHandlerFactory.html 17KB
DefaultServerHandlerFactory.RequestHandlerFactory.html 17KB
package-summary.html 17KB
AbapException.html 17KB
JCoRuntimeException.html 17KB
SessionException.Type.html 17KB
JCoServerContextInfo.html 17KB
JCoFunctionUnit.html 17KB
JCoRequestUnit.html 17KB
JCoParameterField.html 16KB
JCoRepositoryQueryResult.html 16KB
DataProviderException.html 16KB
JCoServerFactory.html 16KB
JCoTraceListener.html 16KB
JCoServerState.html 16KB
JCoRemoteContext.html 16KB
package-summary.html 16KB
package-use.html 16KB
JCoRepository.html 15KB
JCoFunctionUnitState.html 15KB
JCoCustomRepository.QueryMode.html 15KB
JCoClassMetaData.JCoAttributeKind.html 15KB
JCoRepositoryMonitor.html 15KB
JCoServerCallType.html 15KB
DataProviderException.Reason.html 15KB
JCoContext.html 15KB
JCoServerAuthorizationData.html 15KB
SessionException.html 15KB
AbapClassException.Mode.html 15KB
allclasses-frame.html 15KB
serialized-form.html 14KB
JCoServerMonitor.html 14KB
JCoUnitIdentifier.Type.html 14KB
JCoThroughput.html 14KB
JCoDestinationMonitor.html 14KB
JCoServerTIDHandler.html 14KB
JCoExtendedFieldMetaData.html 14KB
JCoAbapObject.html 14KB
JCoApplicationAuthorizationException.html 14KB
JCoFunction.html 14KB
JCoRecordField.html 14KB
JCoRequest.html 13KB
JCoClassMetaData.html 13KB
JCoSessionReference.html 13KB
installation.html 13KB
JCoServer.html 13KB
allclasses-noframe.html 13KB
共 236 条
- 1
- 2
- 3
资源评论
- xiaozechongchong2017-09-26版本太老的了
- wantdraw2017-10-29非常好的资源,做SAP集成必备
- qpingwu2017-02-20外部连接系统必备工具
girl829475l
- 粉丝: 9
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功