com.sap.mw.jco
Class JCO.Server

java.lang.Object
  |
  +--com.sap.mw.jco.JCO.Connection
        |
        +--com.sap.mw.jco.JCO.Server
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable
Enclosing class:
JCO

public static class JCO.Server
extends JCO.Connection
implements java.lang.Runnable

Encapsulates the basic JCO server functionality. Application programmers will extend this class and at least override the handleRequest() method to implement a specific server. e.g.:


  class MyServer extends JCO.Server {

      // Process incoming requests
      public void handleRequest(JCO.Function fct) {
          // Application specific processing goes here
      }
  }
  
Depending on the type of middleware layer loaded, the properties recognized by the JCO server may vary.
For com.sap.mw.jco.rfc.MiddlewareRFC, i.e. the default RFC layer, the supported properties are:

jco.server.gwhost Gateway host
jco.server.gwserv Gateway service
jco.server.progid Program ID of the server
jco.server.trace Enable/disable RFC trace (1 or 0)
jco.server.params Arbitrary parameters for RFC library
jco.server.snc_myname SNC name
jco.server.snc_qop SNC level of security, 1 to 9
jco.server.snc_lib Path to the SNC library
jco.server.unicode Flags whether to connect in unicode mode (1 or 0)
jco.server.max_startup_delayMaximum server startup delay time in seconds


Field Summary
static int AUTHORIZATION_MODE_BASIC
          Authorization mode basic
static int AUTHORIZATION_MODE_SNC
          Authorization mode SNC
static int FUNCTION_MODEL
          Call void handleRequest(Function) method on incoming requests
static int REQUEST_RESPONSE_MODEL
          Call Response handleRequest(Request) method on incoming requests
 
Constructor Summary
JCO.Server(java.util.Properties properties)
          Creates an instance of a server connection
JCO.Server(java.util.Properties properties, IRepository repository)
          Creates an instance of a server connection
JCO.Server(java.util.Properties properties, IServerThread thread, IRepository repository)
          Creates an instance of a server connection
JCO.Server(java.lang.String[][] params, IRepository repository)
          Creates an instance of a server using an array to specify the connection parameters.
JCO.Server(java.lang.String[] argv, IRepository repository)
          Creates an instance of a server using an arv array as passed by void main(String[] argv)
JCO.Server(java.lang.String gwhost, java.lang.String gwserv, java.lang.String progid, IRepository repository)
          Creates an instance of a server connection
JCO.Server(java.lang.String gwhost, java.lang.String gwserv, java.lang.String progid, IServerThread thread, IRepository repository)
          Creates an instance of a server connection
 
Method Summary
 void abort(java.lang.String message)
          Aborts the connection to the remote system, i.e. tries to send a final message to the host before it disconnects.
 void disconnect()
          Closes the connection to the remote system.
 JCO.Attributes getAttributes()
          Returns the attributes object for this server.
 int getCallModel()
          Returns the call model which can be either JCO.Server.FUNCTION_MODEL or JCO.Server.REQUEST_RESPONSE_MODEL.
 java.lang.String getGWHost()
          Returns the gateway server
 java.lang.String getGWServ()
          Returns the gateway service
 java.lang.String getProgID()
          Returns the program id
 java.lang.String[][] getPropertyInfo()
          Returns the property info for the server
 byte getState()
          Returns the server's state as a bit vector
 java.lang.Thread getThread()
          Returns the thread this server is running in
 boolean getTrace()
          Returns whether trace is enabled or not.
 void handleRequest(JCO.Function function)
          Called after a request for a service has arrived.
Derived servers will override this function to actually implement a specific request handling.
When this routine exits without any pending exception the output parameters and tables will be sent back to the calling SAP system.
 void handleRequest(JCO.Request request, JCO.Response response)
          Called after a request for a service has arrived.
Derived servers will override this function to actually implement a specific request handling.
When this routine exits without any pending exception the output parameters and tables will be sent back to the calling SAP system.
 boolean isAlive()
          Checks whether the server is still alive
 boolean onCheckTID(java.lang.String tid)
          This function will be invoked when a transactional RFC is being called from a SAP system.
 void onCommit(java.lang.String tid)
          This function will be called after all RFC functions belonging to a certain transaction have been successfully completed.
 void onConfirmTID(java.lang.String tid)
          This function will be called after the local transaction has been completed.
 void onRollback(java.lang.String tid)
          This function will be called if an error in one of the RFC functions belonging to a certain transaction has occurred.
Derived servers can override this method to locally rollback the transaction.
 void run()
          Implements the run method from the runnable interface
 void setCallModel(int call_model)
          Sets the call model which can be either JCO.Server.FUNCTION_MODEL or JCO.Server.REQUEST_RESPONSE_MODEL.
 void setTrace(boolean trace)
          Enables/disables trace
 void start()
          Starts or resumes execution of the server thread
 void stop()
          Forces the server and its underlying thread to stop execution The server can not be restarted after this method has been called.
 void suspend()
          Forces the server to temporarily stop execution.
 
Methods inherited from class com.sap.mw.jco.JCO.Connection
clone, getProperties, getProperty, getThroughput, isValid, setThroughput
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTHORIZATION_MODE_SNC

public static final int AUTHORIZATION_MODE_SNC
Authorization mode SNC

AUTHORIZATION_MODE_BASIC

public static final int AUTHORIZATION_MODE_BASIC
Authorization mode basic

FUNCTION_MODEL

public static final int FUNCTION_MODEL
Call void handleRequest(Function) method on incoming requests

REQUEST_RESPONSE_MODEL

public static final int REQUEST_RESPONSE_MODEL
Call Response handleRequest(Request) method on incoming requests
Constructor Detail

JCO.Server

public JCO.Server(java.util.Properties properties)
Creates an instance of a server connection
Parameters:
properties - the connection parameters passed as a properties object

JCO.Server

public JCO.Server(java.util.Properties properties,
                  IRepository repository)
Creates an instance of a server connection
Parameters:
properties - the connection parameters passed as a properties object
repository - the repository used by the server to lookup the definitions of an incoming function call
Since:
JCo 1.1.04

JCO.Server

public JCO.Server(java.util.Properties properties,
                  IServerThread thread,
                  IRepository repository)
Creates an instance of a server connection
Parameters:
properties - the connection parameters passed as a properties object
thread - the thread this server is running in
repository - the repository used by the server to lookup the definitions of an incoming function call
Since:
JCo 2.0

JCO.Server

public JCO.Server(java.lang.String[][] params,
                  IRepository repository)
Creates an instance of a server using an array to specify the connection parameters. Each item in the array is a name/value pair where the first element is the name and the second is the value associated with the name, e.g.
     static String[][] login_params  = {
        { "gwhost" ,   "bin20"     },
        { "gwserv"   , "gwbin20"   },
        { "progid" ,   "PROGRAM01" },
     };
 
Parameters:
params - the connection parameters as an two-dimemsional array
repository - the repository used by the server to lookup the definitions of an incoming function call

JCO.Server

public JCO.Server(java.lang.String[] argv,
                  IRepository repository)
Creates an instance of a server using an arv array as passed by void main(String[] argv)
Parameters:
arv - the array of argument as passed by void main(String[] argv)
repository - the repository used by the server to lookup the definitions of an incoming function call
Since:
1.1.03

JCO.Server

public JCO.Server(java.lang.String gwhost,
                  java.lang.String gwserv,
                  java.lang.String progid,
                  IRepository repository)
Creates an instance of a server connection
Parameters:
gwhost - the gateway host
gwserv - the gateway service number
progid - the program id
repository - the repository used by the server to lookup the definitions of an incoming function call

JCO.Server

public JCO.Server(java.lang.String gwhost,
                  java.lang.String gwserv,
                  java.lang.String progid,
                  IServerThread thread,
                  IRepository repository)
Creates an instance of a server connection
Parameters:
gwhost - the gateway host
gwserv - the gateway service number
progid - the program id
thread - the thread this server is running in
repository - the repository used by the server to lookup the definitions of an incoming function call
Method Detail

getPropertyInfo

public final java.lang.String[][] getPropertyInfo()
Returns the property info for the server
Overrides:
getPropertyInfo in class JCO.Connection

setCallModel

public void setCallModel(int call_model)
Sets the call model which can be either JCO.Server.FUNCTION_MODEL or JCO.Server.REQUEST_RESPONSE_MODEL. Depending on the call model either the void handleRequest(JCO.Function function) or tje method void handleRequest(JCO.Request, JCO.Response) will be called on incoming requests. The default is calling void handleRequest(Function function)
Parameters:
call_model - the call model which this server uses
See Also:
getCallModel()

getCallModel

public int getCallModel()
Returns the call model which can be either JCO.Server.FUNCTION_MODEL or JCO.Server.REQUEST_RESPONSE_MODEL.
Since:
JCo 2.0
See Also:
setCallModel(int), handleRequest(JCO.Function), handleRequest(JCO.Request, JCO.Response)

getState

public byte getState()
Returns the server's state as a bit vector
Returns:
the state of the server as a bit vector
Flag Description
JCO.STATE_STOPPED The server has been stopped
JCO.STATE_STARTED The server has been started
JCO.STATE_LISTENING The server is listening for incoming requests
JCO.STATE_BUSY The server is currently processing an incoming request
JCO.STATE_TRANSACTIONThe server incoming request is a transaction

getThread

public java.lang.Thread getThread()
Returns the thread this server is running in
Returns:
the thread this server is running in

getAttributes

public final JCO.Attributes getAttributes()
Returns the attributes object for this server.
Overrides:
getAttributes in class JCO.Connection
Returns:
the attributes object for this server.
Throws:
JCO.Exception - thrown if the attributes could not be retrieved.
See Also:
JCO.Attributes

getGWHost

public final java.lang.String getGWHost()
Returns the gateway server
Returns:
the gateway server

getGWServ

public final java.lang.String getGWServ()
Returns the gateway service
Returns:
the gateway service

getProgID

public final java.lang.String getProgID()
Returns the program id
Returns:
the program id

getTrace

public final boolean getTrace()
Returns whether trace is enabled or not.
Overrides:
getTrace in class JCO.Connection
Returns:
true if trace is enabled, false otherwise

setTrace

public final void setTrace(boolean trace)
Enables/disables trace
Overrides:
setTrace in class JCO.Connection
Parameters:
trace - if true enables the trace and disables it otherwise.

disconnect

public void disconnect()
Closes the connection to the remote system.
Overrides:
disconnect in class JCO.Connection

abort

public void abort(java.lang.String message)
Aborts the connection to the remote system, i.e. tries to send a final message to the host before it disconnects.
Overrides:
abort in class JCO.Connection
Parameters:
message - the final message which will be sent to the remote system.

start

public void start()
Starts or resumes execution of the server thread

stop

public void stop()
Forces the server and its underlying thread to stop execution The server can not be restarted after this method has been called. To temporarily stop a server use suspend() instead.
See Also:
suspend()

suspend

public void suspend()
Forces the server to temporarily stop execution. The server can be restarted using the start() method.
See Also:
start()

run

public void run()
Implements the run method from the runnable interface
Specified by:
run in interface java.lang.Runnable

isAlive

public boolean isAlive()
Checks whether the server is still alive
Overrides:
isAlive in class JCO.Connection
Returns:
true if the server is alive, false otherwise

handleRequest

protected void handleRequest(JCO.Function function)
Called after a request for a service has arrived.
Derived servers will override this function to actually implement a specific request handling.
When this routine exits without any pending exception the output parameters and tables will be sent back to the calling SAP system. If an exception has been thrown and is still pending, JCo handles it according to the following rules:
a) The exception is a JCO.AbapException or the message text of the exception is the name of one of the exceptions specified in the call interface of the ABAP module. JCo will raise a corresponding ABAP exception in such a case and pass the exception's message text into the SAP system variables SY-MSGV1 to SY-MSGV4.
b) The exception is not a JCO.AbapException and the message text does not correspond to one of the ABAP exceptions. In this case JCo will raise a system exception in the calling SAP system.
Parameters:
function - the function that has been called by a remote client

handleRequest

protected void handleRequest(JCO.Request request,
                          JCO.Response response)
Called after a request for a service has arrived.
Derived servers will override this function to actually implement a specific request handling.
When this routine exits without any pending exception the output parameters and tables will be sent back to the calling SAP system. If an exception has been thrown and is still pending, JCo handles it according to the following rules:
a) The exception is a JCO.AbapException or the message text of the exception is the name of one of the exceptions specified in the call interface of the ABAP module. JCo will raise a corresponding ABAP exception in such a case and pass the exception's message text into the SAP system variables SY-MSGV1 to SY-MSGV4.
b) The exception is not a JCO.AbapException and the message text does not correspond to one of the ABAP exceptions. In this case JCo will raise a system exception in the calling SAP system.
Parameters:
request - the request container filled with the data from the calling program
response - the response container whose contents will be send back to the calling SAP system.

onCheckTID

protected boolean onCheckTID(java.lang.String tid)
This function will be invoked when a transactional RFC is being called from a SAP system. The function has to store the TID in permanent storage and return true. The method has to return false if the a transaction with this ID has already been processed. Throw an exception if anything goes wrong. The transaction processing will be aborted thereafter.
Derived servers must override this method to actually implement the transaction ID management.
Parameters:
tid - the transaction ID
Returns:
true if the ID is valid and not in use, false otherwise

onConfirmTID

protected void onConfirmTID(java.lang.String tid)
This function will be called after the local transaction has been completed. All resources associated with this TID can be released.
Derived servers must override this method to actually implement the transaction ID management.
Parameters:
tid - the transaction ID

onCommit

protected void onCommit(java.lang.String tid)
This function will be called after all RFC functions belonging to a certain transaction have been successfully completed.
Derived servers can override this method to locally commit the transaction.
Parameters:
tid - the transaction ID

onRollback

protected void onRollback(java.lang.String tid)
This function will be called if an error in one of the RFC functions belonging to a certain transaction has occurred.
Derived servers can override this method to locally rollback the transaction.
Parameters:
tid - the transaction ID