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);
server.addServerExceptionListener(eListener);
MyStateChangedListener slistener = new MyStateChangedListener();
serve
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SAP3的windows下和linux下安装使用 (238个子文件)
sap.css 4KB
sapjco3.dll 4.06MB
inherit.gif 57B
index-all.html 371KB
JCoRecord.html 127KB
JCo.html 83KB
DestinationDataProvider.html 75KB
JCoException.html 75KB
releasenotes.html 71KB
constant-values.html 70KB
JCoMetaData.html 65KB
JCoDestination.html 59KB
JCoServer.html 57KB
JCoField.html 47KB
JCoListMetaData.html 43KB
Environment.html 38KB
JCoRepository.html 35KB
JCoTable.html 34KB
JCoClassMetaData.html 33KB
ServerDataProvider.html 32KB
JCoRecordMetaData.html 31KB
overview-tree.html 30KB
JCoException.html 29KB
JCoAttributes.html 28KB
JCoConnectionData.html 28KB
package-use.html 27KB
AbapClassException.html 27KB
JCoRequest.html 24KB
package-summary.html 23KB
JCoParameterList.html 23KB
JCoServerContext.html 23KB
JCoFunction.html 23KB
JCoCustomDestination.html 23KB
DefaultServerHandlerFactory.html 22KB
JCoDestinationManager.html 22KB
JCoRuntimeException.html 22KB
JCoDestination.html 22KB
AbapException.html 21KB
JCoCustomRepository.html 20KB
DefaultSessionReferenceProvider.html 20KB
JCoDestinationMonitor.html 20KB
JCoBackgroundUnitAttributes.html 19KB
JCoStructure.html 19KB
JCoAbapObject.html 18KB
JCoRecordMetaData.html 18KB
package-tree.html 17KB
JCoResponse.html 17KB
SessionReferenceProvider.html 17KB
JCoServerUnitIDHandler.html 17KB
JCoFunctionTemplate.html 17KB
JCoListMetaData.html 17KB
JCoUnitIdentifier.html 17KB
DefaultServerHandlerFactory.FunctionHandlerFactory.html 17KB
DefaultServerHandlerFactory.RequestHandlerFactory.html 17KB
JCoCustomDestination.UserData.html 17KB
package-summary.html 17KB
AbapException.html 17KB
JCoRuntimeException.html 16KB
SessionException.Type.html 16KB
JCoServerContextInfo.html 16KB
JCoFunctionUnit.html 16KB
JCoRequestUnit.html 16KB
JCoParameterField.html 16KB
JCoRepositoryQueryResult.html 16KB
DataProviderException.html 16KB
JCoServerFactory.html 16KB
JCoTraceListener.html 16KB
JCoServerState.html 15KB
JCoRemoteContext.html 15KB
package-use.html 15KB
package-summary.html 15KB
JCoRepository.html 15KB
JCoCustomRepository.QueryMode.html 15KB
JCoFunctionUnitState.html 15KB
JCoClassMetaData.JCoAttributeKind.html 15KB
JCoServerCallType.html 15KB
JCoRepositoryMonitor.html 15KB
DataProviderException.Reason.html 15KB
JCoContext.html 14KB
allclasses-frame.html 14KB
SessionException.html 14KB
JCoServerAuthorizationData.html 14KB
AbapClassException.Mode.html 14KB
JCoUnitIdentifier.Type.html 14KB
JCoServerMonitor.html 14KB
serialized-form.html 14KB
JCoDestinationMonitor.html 14KB
JCoThroughput.html 14KB
JCoServerTIDHandler.html 14KB
JCoAbapObject.html 13KB
JCoExtendedFieldMetaData.html 13KB
JCoApplicationAuthorizationException.html 13KB
JCoRecordField.html 13KB
JCoRequest.html 13KB
JCoClassMetaData.html 13KB
JCoFunction.html 13KB
installation.html 13KB
JCoServer.html 13KB
JCoSessionReference.html 13KB
allclasses-noframe.html 13KB
共 238 条
- 1
- 2
- 3
资源评论
- 番茄配黄瓜2017-12-04假,不是我想要的文件。说明与实际不符吖secretpeople2017-12-06这个是我最近项目亲测可用的,请问你的有什么问题?
secretpeople
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功