1 protocol overview
1.1 About SJOP
SJOP is full name is Sample Java ORB Protocol (Simple Java Object Request Agent Protocol). Similar protocols have DCOM, CORBA, SOAP, etc., compared to SJOP is an extremely simple and efficient object request agency protocol.
1.2 SJOP application
The SJOP protocol is implemented in the MiniJ2ee application server for calling the EJB components in the MiniJ2ee application server in PHP or other non-Java customers.
2 protocol content
2.1 Overview
SJOP is based on text-based protocol, which is exactly what he is simple. SJOP communication uses a flow-oriented communication protocol, such as TCP / IP, communication mode adopting request / response mode.
2.2 Data type
SJOP defines the following basic data types:
Java.lang.string: String
Java.lang.short: short integer
Java.lang.integer: Integer
Java.lang.long: Long integer
Java.lang.Boolean: Boolean, "True" or "False"
Java.lang.float: floating point
Java.lang.double: Double precision floating point
SJOP defines the following special data types:
Void: Use the VOID when the call does not return a value.
Phpext.objref: The Java object reference handle, used to return the created Java object, call the Java object to call or use the Java object as a parameter.
2.3 request
The request format of SJOP is:
Request: Function
Request Body
EOR
Where Function is the function of the request, the Request Body is different depending on the functionality of the request. EOR is the sign of the end of the request.
2.3.1 Parameter list
Request Body typically contains a parameter list parameter list, which is used to specify parameters for call constructor or methods. Parameter List consists of several row parameter entries, and the format of each parameter entry is as follows:
Param: Type: Value
E.g:
Param: java.lang.string: ABCD
Param: java.lang.integer: 1234
Since each parameter entry is a row, the parameters for java.lang.string types are enabled if the Value contains '/ n', it is coded.
2.3.2 Creating an object
The format of creating object requests is:
Request: New
Classname: Name of Java Class
Parameter List
EOR
The request will successfully return a phpext.objref type value in the response, which is the reference handle of the created Java object.
2.3.3 Delete Object
The format of the delete object request is:
Request: Delete
Objref: Object Reference
EOR
The request is successful, which will be deleted the proxy Java object specified by Object Reference. Object Reference is a reference handle for creating a Java object returned by an object request, or a method call or a static method call returned the phpext.objref type value.
In the implementation of the MiniJ2EE application server, the object that is not referenced within a certain period of time will be automatically deleted.
2.3.4 Method Call
The format of the method call request is:
REQUEST: CALL
Objref: Object Reference
MethodName: Name of Method
Parameter List
The EOR request returns the result or exception of the method call. Object Reference is a reference handle for creating a Java object returned by an object request, or a method call or a static method call returned the phpext.objref type value.
2.3.5 Static method call
The request format called the static method call is:
REQUEST: CALL
Classname: Name of Java Class
MethodName: Name of Method
Parameter List
EOR
The static method calls a similar method call, just change the Java object reference handler to the Java class name, because the statically method is not required for Java object instance.
2.4 response
The response is successful and abnormal.
The success response format is:
Responce: OK
Result: Type: Value
TYPE is the type of return value, and Value is the return value. If the request is not returned, Type is Void, Value is NULL.
The abnormal response format is:
Responce: Error
Exception: Type: Value
TYPE is an exception class name, such as java.io ioException, value is an exception description.
3 SJOP API
The MINIJ2EE application server package provides the API implementation of the MiniJ2ee Sjop implementation, in the PHP / SJOP directory, can be used to ask the EJB components on the MiniJ2ee application server in the C / C program.
The SJOP API provides the following functions (macro):
u SJOP_GET_CONNECTION
Function prototype:
HCOMM_CONNECTION SJOP_GET_CONNECTION (Char * IP, CHAR * Port);
description:
SJOP_GET_CONNECTION Gets a connection with the MiniJ2ee SJOP server for requests. IP is the IP address of the server, and Port is the port number of the server. A connection can be used for multiple requests.
u SJOP_FREE_CONNECTION
Function prototype:
Void sjop_free_connection (hcomm_connection hconn);
description:
SJOP_FREE_CONNECTION releases a connection to the Minij2ee SJOP server.
u SJOP_MINIJ2EE_NEW_JAVAOBJ
Function prototype:
PhpextResponce * sjop_minij2ee_new_javaobj (hcomm_connection conn, char * classname, ...);
description:
The SJOP_MINIJ2EE_NEW_JAVAOBJ function sends a request to create an object. Conn is a connection to the Minij2ee SJOP server. The function returns a phpextResponce structure pointer contains the content of the answer.
example:
PhpextResponce * r = sjop_minij2ee_new_javaobj (hconn, "java.io.fileinputstream", "java.lang.string", "c: / somefile");
u SJOP_MINIJ2EE_DELETE_JAVAOBJ
Function prototype:
PhpextResponce * sjop_minij2ee_delete_javaobj (hcomm_connection conn, hjavaobj jobj);
description:
The SJOP_MINIJ2EE_DELETE_JAVAOBJ function sends a request to delete an object. Conn is a connection to the Minij2ee SJOP server. The function returns a phpextResponce structure pointer contains the content of the answer.
u SJOP_MINIJ2EE_CALL_JAVAOBJ function prototype:
PhpextResponce * sjop_minij2ee_call_javaobj (hcomm_connection conn, hjavaobj jobj, char * methodname, ...);
description:
SJOP_MINIJ2EE_CALL_JAVAOBJ function Send method call request. Conn is a connection to the Minij2ee SJOP server. The function returns a phpextResponce structure pointer contains the content of the answer.
example:
PhpextResponce * r = sjop_minij2ee_call_javaobj (hconn, objref, "skip", "java.lang.long", 16);
u SJOP_MINIJ2EE_CALLSTATIC_JAVAOBJ
Function prototype:
PhpextResponce * sjop_minij2ee_callstatic_javaobj (hcomm_connection conn, char * classname, char * methodname, ...);
description:
The SJOP_MINIJ2EE_CallStatic_javaobj function sends a request for static method calls. Conn is a connection to the Minij2ee SJOP server. The function returns a phpextResponce structure pointer contains the content of the answer.
example:
PhpextResponce * r = sjop_minij2ee_callstatic_javaobj (hconn, "java.lang.system", "getproperty", "java.lang.string", "java.version");
u sjop_free_response
Function prototype:
Void sjop_free_responce (phpextResponce * resp);
description:
SJOP_FREE_RESPONSE releases the PhpeTResponce structure pointer that the send request returns.
The PhpextResponce structure is defined as follows:
Typedef struct
{
Int succ; // request is successful
CHAR * EXPTYPE; // If the exception, EXPTYPE indicates the name of the abnormality class.
CHAR * EXPVALUE; // If an exception, EXPVALUE indicates an exception description.
Char * resultType; // Return value type, see data type
union
{
INT INT_VALUE;
CHAR * STRING_VALUE;
Double Double_Value;
INT Objref_Value;
} Result; // The combination of the return value is different from the return value type, plus the table:
Return result value type in the corresponding member java.lang.Short java.lang.Integer java.lang.Long java.lang.Boolean int_value java.lang.String string_value java.lang.Float java.lang.Double double_value phpext.objref Objref_Value Void No
PHPEXTRESPONCE;
The following macros can be used to access the phpextResponce structure pointer:
#define sjop_resp_ok (resp) -> SUCC)
#define sjop_resp_error (! (r) -> SUCC)
#define sjop_resp_exp_type (resp) ((res) -> EXPTYPE) #define sjop_resp_exp_value ((resp) -> expValue
#define sjop_resp_result_type (resp) ((ResP) -> ResultType)
#define sjop_resp_result_int (resp) ((resp) -> Result.InT_Value)
#define sjop_resp_result_string (resp) ((res) -> Result.String_Value)
#define sjop_resp_result_double (resp) ((res) -> Result.double_Value)
#define sjop_resp_result_javaobj (resp) -> Result.objref_Value
http://www.minij2ee.com/