Show TOC Anfang des Inhaltsbereichs

Diese Grafik wird im zugehörigen Text erklärt Server Programming Model  Dokument im Navigationsbaum lokalisieren

 

The following section shows examples for the setup of a server program.

 

In a first step - at development time - you need to decide whether you intend to receive synchronous calls (sRFC calls) or asynchronous calls (tRFC).

 

Hinweis

If your design requires that all requests to the particular ProgramID (see SAPJRA Configuration on the Application Server Java) are processed by the same MDB, you will need to set for the FunctionName your ProgramID, e.g. for the ProgramID “MyProgramID” you would set the entry

 

<activation-config-property-name>

          FunctionName

</activation-config-property-name>

<activation-config-property-value>

          MyProgramID

</activation-config-property-value>

 

Calls over sRFC

 

For synchronous calls you need to comprise your business logic in a MDB (MessageDrivenBean) and additionally implement the interface com.sap.mw.jco.jra.SynchronousMessageListener.

 

At runtime this interface is available on the Java EE Application Server as soon as at least one instance of SAPJRA is deployed.

 

Hinweis

If your application does not depend on any proprietary interfaces and if you use only synchronous calls, you can use javax.resource.cci.MessageListener  instead of com.sap.mw.jco.jra.SynchronousMessageListener. Here is the example bean:

 

import javax.ejb.*;

import javax.resource.cci.*;

import java.util.*;

/**

 * JCA Server Bean Class automatically created on Tue Dec 06 10:18:10 CET 2005

 */

public class STFC_CONNECTION_Server implements MessageDrivenBean,

MessageListener

{

 

  private MessageDrivenContext m_context;

  public void ejbCreate() {}

  public void ejbRemove() {}

  public void setMessageDrivenContext(MessageDrivenContext

context)

  {m_context = context;}

 

  public Record onMessage(Record inputData)

        throws javax.resource.cci.ResourceWarning {

     MappedRecord request = (MappedRecord)inputData;

     MappedRecord response =

(MappedRecord)request.get("$RESPONSE");

     Properties info = (Properties)request.get("$CALLER_INFO");

     String request_requtext = (String)request.get("REQUTEXT");

 

     response.put("ECHOTEXT",request_requtext);

     rsponse.put("RESPTEXT","01234567890ABCD");

 

     return response;

  }// onMessage

}// class

 

Hinweis

The request and response objects that are passed over method onMessage for a synchronous call, keep references to the same table and changing parameters. So setting your table in response will result in getting an updated value in request.

 

 

The ejb-jar.xml will have then the following entry for the messaging-type:

 

<messaging-type>

  javax.resource.cci.MessageListener

</messaging-type>        

 

 

 

The following shows an example MDB receiving synchronous calls from SAP to a Java Application with com.sap.mw.jco.jra.SynchronousMessageListener :

 

Hinweis

Facades and Compilation describes how to get access to this interface.

 

 

import javax.ejb.*;

import com.sap.mw.jco.jra.SynchronousMessageListener;

import javax.resource.cci.MappedRecord;

 

public class STFC_CONNECTIONBean implements MessageDrivenBean,

SynchronousMessageListener

{

    ………………………………………

 

   // this is a method from the interface

   // SynchronousMessageListener, which should

   // be implemented by the application listening for calls from

   // SAP.

 

   public MappedRecord onMessage(MappedRecord request, MappedRecord

                  response, Properties info)

   {

 

        // data from SAP are passed over request.

        // response contains initial data as defined in SAP

     

        // set import parameter RESPTEXT of the Remote Function

        // Module STFC_CONNECTION

      

        response.put("RESPTEXT",

 

        "This is a response from STFC_CONNECTIONBean ");

 

        // get value of the import parameter REQUTEXT and copy  

        // it into export parameter ECHOTEXT

 

        response.put("ECHOTEXT", request.get("REQUTEXT"));

 

        return response;

    }

}

     

An additional entry for the ejb-jar.xml descriptor of this Message Driven Bean could look like this:

 

Hinweis

You need to use ejb-jar_2_1.xsd and not ejb-jar_2_0.dtd, since the support of some required tags was introduced beginning with the ejb2.1 specification.

     

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar version="2.1"

   xmlns="http://java.sun.com/xml/ns/j2ee"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

   http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">

    <display-name xml:lang="de">functions</display-name>

  

<enterprise-beans>

  <message-driven>

    <display-name>STFC_CONNECTION</display-name>

    <ejb-name>My_STFC_CONNECTION</ejb-name>

    <ejb-class>

      com.sap.mw.jco.jra.tests.server.STFC_CONNECTIONBean

    </ejb-class>

    <messaging-type>

      com.sap.mw.jco.jra.SynchronousMessageListener

    </messaging-type>

    <transaction-type>Bean</transaction-type>

    <activation-config>

      <activation-config-property>

        <activation-config-property-name>

          FunctionName

        </activation-config-property-name>

        <activation-config-property-value>

          STFC_CONNECTION

        </activation-config-property-value>

     </activation-config-property>

  </activation-config>

     </message-driven>

      ………………………………………………….

     

Using the entries

  

<ejb-name> My_STFC_CONNECTION </ejb-name>

   ……………………………………………………………………………………………………

<activation-config-property-name>

          FunctionName

</activation-config-property-name>

<activation-config-property-value>

          STFC_CONNECTION

</activation-config-property-value>

 

you define that when the function with FunctionName STFC_CONNECTION is called this call will be handled by the bean My_STFC_CONNECTION.

 

See also [http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd]

for details of the ejb-jar.xml descriptor.

 

 

Calls over tRFC

 

 

For calls over tRFC you need to comprise your business logic in a MessageDrivenBean and implement the interface com.sap.mw.jco.jra.AsynchronousMessageListener.

     

The application would need to implement the method

public void onMessage(MappedRecord msg, java.util.Properties info)

 

The only difference to the ejb-jar.xml shown above is that you will need to adjust the entry to the messaging-type:

 

<messaging-type>

         com.sap.mw.jco.jra.AsynchronousMessageListener

</messaging-type>

 

Further Information

 

      Callback

      Stateful Communication

      Security for the Server Programming Model

Ende des Inhaltsbereichs