浏览模式: 标准 | 列表
7月
08

PHPRPC 3.0 for Java Beta 5

Beta 5 Update:

增加了 getEncryptMode 方法。
将日期序列化和反序列化做了修改,使其跟 PHPRPC for PHP 中的 PHPRPC_Date 类兼容。
增加了对 PHP6 中字符串转义序列化的反序列化支持。
优化 Base64 encode 算法。
为服务器增加了 setEnableGZIP 方法,默认把 GZIP 输出设为关闭。
取消了不必要的同步操作。
完善了错误处理。
修正了在 Resin,JRun 和 Jetty 上运行的一些小问题。
修正了客户端对 chunked 编码处理的一些错误。
修改了对 java.util.Date 类型对象的序列化和反序列化,使其可以与其它语言中所对应的日期时间类型直接交换。

Beta 4 Update:

改进了序列化递归对象的算法。
对将转型代码单独写成了 Cast 静态类,提供了 getBytes、toString 和 cast 三个方法,可以方便的用于类型转换。
对 byte[] 和 String 的处理做了进一步优化,ArrayList 和 HashMap 中保存的 String 和 byte[] 类型的对象在反序列化后都会变为 byte[] 类型,如果需要字符串类型可以使用,Cast.toString 方法或者 Cast.cast 方法来转型。

Beta 3 Update:

对代码做了进一步优化。
修正了 byte[] 反序列化时的错误。
优化了 char[] 和 StringBuffer 对象的传输,它们都将作为字符串进行序列化传递。并且提供了它们与其它基本类型之间的转换。
当用户在定义远程方法时,如果参数表最后有 javax.servlet.http.HttpSession session 参数,则服务器自动传输 session 对象。
当用户在定义远程方法时,如果参数表最后有 javax.servlet.ServletContext application 参数,则服务器自动传输 application 对象。
以上两个参数也可以跟 PrintStream out 或 PrintWriter out 组合使用。

Beta 2 Update:

实现了通过给定远程过程调用的接口来返回该接口的服务代理对象实例,通过该实例可以直接调用服务器端的远程过程。
提供了更广泛的类型转换(例如可将 Boolean 型数据转换为数字类型),与弱类型语言(如 PHP)进行交互更加方便。
实现了对所有可序列化类型,包括内部类的支持。并且序列化后的类名包括包名,例如 java.util.Date 类序列化后的名称为 java_util_Date,其他不支持名空间的语言可以使用该名称的类。
服务器端输出重定向除了支持 PrintStream out 参数外,还增加了对 PrintWriter out 参数的支持。但只能使用其中之一。

Beta 1 Update:

实现了 PHPRPC 3.0 协议升级描述中的内容。
实现了 PHPRPC 3.0 for Java API Draft 中的所有接口。
支持 Java 1.4.2 及其更高版本。
服务器和客户端均支持 HTTP gzip 压缩传输。
服务器端实现了加密传输中 Cookie-less 会话支持。
支持 Keep-Alive 连接。
支持更多可序列化对象的传输。
对 byte[] 类型的传输做了优化。
对输出重定向功能做了优化,现在不在把 System.out 的内容重定向到客户端。当用户定义远程方法时,如果参数表最后有 PrintStream out 参数,则服务器自动传输该对象,通过该对象输出的内容将重定向到客户端。
对 URL 参数和 session 处理做了优化,当用户在定义远程方法时,如果参数表最后有 javax.servlet.http.HttpServletRequest request 参数,则服务器自动传输该对象,用户可通过该对象来获取 URL 参数和 session。
以上两个参数顺序任意,也可只写一个或没有,但必须在所有用户传入参数的最后。
与 PHPRPC 2.1、2.0、1.1 的服务器和客户端有条件兼容。

Download: phprpc_3.0_java_beta_5.zip

» 阅读全文

7月
08

PHPRPC 3.0 for ASP API Draft

Server API:

constructor PHPRPC_Server();
constructor PHPRPC_Server.create();

Create the PHPRPC Server object. To use create method create PHPRPC Server object in VBScript.

add(String funcname);
add(String funcname, Object obj, String alias);
add(Function func, Object obj, String alias);
add(String[] funcnames);
add(String[] funcnames, Object obj, String[] aliases);
add(Function[] functions, Object obj, String[] aliases);

Add global functions to the server. The functions can have aliases. If functions if typeof Functon, it must have aliases. The obj is the execute context of the functions. This method must be called before start().

start();

Start the PHPRPC server. This method usually be called at the end of page. This method can NOT be called twice or more in one page.

Client API:

constructor PHPRPC_Client();
constructor PHPRPC_Client(String serverURL);
constructor PHPRPC_Client(String serverURL, Array functions);
constructor PHPRPC_Client.create();
constructor PHPRPC_Client.create(String serverURL);
constructor PHPRPC_Client.create(String serverURL, Array functions);

Create PHPRPC Client object. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. To use create method create PHPRPC Client object in VBScript.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

setProxy(String address);
setProxy(String host, String port);
setProxy(String host, String port, String username, String password);

Set the proxy server for the transfer. The address supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You can set the address to null to cancel the proxy server.

useService(String serverURL);
useService(String serverURL, String username, String password);
useService(String serverURL, String username, String password, Array functions);

Set the URL of the PHPRPC Server. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You’d better to set username and password alone.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

Boolean setKeyLength(Integer keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

Integer getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

setEncryptMode(Integer encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console.

Integer getEncryptMode();

Get the encrypt mode.

invoke(String funcname, Object[] args);
invoke(String funcname, Object[] args, Boolean byRef);

Invoke the server function with the function name and arguments array. if you want to transfer the arguments by reference, set byRef to be true.

remoteFunctionName(arg1, arg2, ..., argN);

Invoke the server function directly. You can’t transfer the arguments by reference in this mode.

String getOutput();

Get the output of the server console after invoke the server function.

PHPRPC_Error getWarning();

Get the warning of the server function after invoke the server function.

» 阅读全文

constructor PHPRPC_Client();
constructor PHPRPC_Client(string serverURL);
constructor PHPRPC_Client(string serverURL, array functions);
constructor PHPRPC_Client.create();
constructor PHPRPC_Client.create(string serverURL);
constructor PHPRPC_Client.create(string serverURL, array functions);

Create PHPRPC Client object. The username and password can be contained in serverURL for HTTP Basic Authorization, but it is NOT recommended (see also useService method for the recommended usage). To use create method create PHPRPC Client object in VBScript.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

useService(string serverURL);
useService(string serverURL, string username, string password);
useService(string serverURL, string username, string password, array functions);

Set the URL of the PHPRPC Server. The username and password can be contained in serverURL for HTTP Basic Authorization, but it is NOT recommended. It is recommended to specify the username and password by parameters.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

boolean setKeyLength(int keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

int getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(int encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

int getEncryptMode();

Get the encrypt mode.

string remoteFunctionName(arg1, arg2, ..., argN);
string remoteFunctionName(arg1, arg2, ..., argN, callbackFunction);
string remoteFunctionName(arg1, arg2, ..., argN, callbackFunction, byRef);

Invoke the server function directly. The return value is remoteFunctionID, you can use abort method to abort the remoteFunction with this value. You can specify a callbackFunction, when the remote function completed, this callbackFunction will be call automatically. If you want to transfer the arguments by reference, set byRef to be true. If you didn’t specify a callbackFunction, the default callback function is remoteFunctionName_callback(), You can define it separately. the callbackFunction can be defined like this:

callbackFunction = function (result, args, output, warning) {
   ...
}

The parameter result is the remote function result, when an error occurred during invoking remote function, this parameter is a PHPRPC_Error object. The parameter args is the remote function arguments, you can get the changed arguments with it when transfering the arguments by reference. The parameter output is the output of the server console after invoke the remote function. The parameter warning is the warning of the server function after invoke the remote function, it is a PHPRPC_Error object.

onready();

This is a event. When the useService method completes, this event will be fired.

boolean getReady();

When the useService method completes, this method return true, otherwise return false.

string invoke(remoteFunctionName, arg1, arg2, ..., argN);
string invoke(remoteFunctionName, arg1, arg2, ..., argN, callbackFunction);
string invoke(remoteFunctionName, arg1, arg2, ..., argN, callbackFunction, byRef);

This method is similar to remoteFunctionName in calling remote function. The difference is the invoke method is available before the ready property becomes true, that is to say, this method can be called immediately after using useService method.

abort();
abort(string remoteFunctionID);

If you used this method without parameter, it would stop all of the remote functions. If you specified the remoteFunctionID, it would only stop the remote function you specified.

setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of milliseconds. Default value is 30 seconds. If you want to disable timeout, set timeout to 0 or null.

int getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of milliseconds.

constructor PHPRPC_Error(int errno, string errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of callback function.

int getNumber();

return error number.

string getMessage();

return error message.

string toString();

return a string which include the error number and error message.

» 阅读全文

7月
08

PHPRPC 3.0 for PHP API Draft

Server API:

constructor PHPRPC_Server();

Create the PHPRPC Server object.

add(string funcname);
add(string funcname, null, string alias);
add(string[] funcnames);
add(string[] funcnames, null, string[] aliases);
 
add(string funcname, object obj);
add(string funcname, object obj, string alias);
add(string[] funcnames, object obj);
add(string[] funcnames, object obj, string[] aliases);
 
add(string funcname, string classname);
add(string funcname, string classname, string alias);
add(string[] funcnames, string classname);
add(string[] funcnames, string classname, string[] aliases);

Add global functions, instance methods or static methods to the server. The functions or the methods can have aliases. This method must be called before start().

add(object obj);

Add all methods from obj to the server. This method must be called before start().

setCharset(string charset);

Set the charset of the server. This method must be called before start();

setDebugMode(boolean debug);

Set the debug mode of the server. This method must be called before start();

start();

Start the PHPRPC server. This method usually be called at the end of page. This method can NOT be called twice or more in one page.

Client API:

constructor PHPRPC_Client();
constructor PHPRPC_Client(string serverURL);

Create PHPRPC Client object. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend.

setProxy(string address);
setProxy(string host, string port);
setProxy(string host, string port, string username, string password);

Set the proxy server for the transfer. The address supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You can set the address to NULL to cancel the proxy server.

useService(string serverURL);
useService(string serverURL, string username, string password);

Set the URL of the PHPRPC Server. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You’d better to set username and password alone.

boolean setKeyLength(integer keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

integer getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(integer encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

integer getEncryptMode();

Get the encrypt mode.

setCharset(string charset);

Set the request charset. Use it before invoke the remote function. The default value is “UTF-8″ or as the response charset.

string getCharset();

Get the response charset. Use it after invoke the remote function.

setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of seconds. Default value is 30 seconds.

integer getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of seconds.

invoke(string funcname, object[] args);
invoke(string funcname, object[] args, boolean byRef);

Invoke the server function with the function name and arguments array. if you want to transfer the arguments by reference, set byRef to be true.

remoteFunctionName(arg1, arg2, ..., argN);

Invoke the server function directly. You can’t transfer the arguments by reference in this mode.

string getOutput();

Get the output of the server console after invoke the server function.

PHPRPC_Error getWarning();

Get the warning of the server function after invoke the server function.

constructor PHPRPC_Error(int errno, string errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of remote function.

integer getNumber();

return error number.

string getMessage();

return error message.

string toString();

return a string which include the error number and error message.

» 阅读全文

Server API:

constructor PHPRPC_Server();

Create the PHPRPC Server object.

boolean add(String funcname, Object obj);
boolean add(String funcname, Object obj, String alias);
boolean add(String[] funcnames, Object obj);
boolean add(String[] funcnames, Object obj, String[] aliases);
 
boolean add(String funcname, Class cls);
boolean add(String funcname, Class cls, String alias);
boolean add(String[] funcnames, Class cls);
boolean add(String[] funcnames, Class cls, String[] aliases);

Add instance methods or static methods to the server. The methods can have aliases. This method must be called before start().

boolean add(Object obj);

Add all instance methods from obj to the server. This method must be called before start().

boolean add(Class cls);

Add all static methods from cls to the server. This method must be called before start().

void setCharset(String charset);

Set the charset of the server. This method must be called before start();

void setDebugMode(boolean debug);

Set the debug mode of the server. This method must be called before start();

void setEnableGZIP(boolean enableGZIP);

Set enable GZIP of the server. This method must be called before start();

void start(HttpServletRequest request, HttpServletResponse response);

Start the PHPRPC server. This method usually be called at the end of page. This method can NOT be called twice or more in one page.

Client API:

constructor PHPRPC_Client();
constructor PHPRPC_Client(String serverURL);

Create PHPRPC Client object. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend.

void setProxy(String address) throws MalformedURLException;
void setProxy(String host, int port);
void setProxy(String host, int port, String username, String password);

Set the proxy server for the transfer. The address supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You can set the address to null to cancel the proxy server.

boolean useService(String serverURL);
boolean useService(String serverURL, String username, String password);

Set the URL of the PHPRPC Server. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You’d better to set username and password alone.

Object useService(Class type);
Object useService(Class[] interfaces);

Get a service proxy object instance. The type Class is a interface or a class implements a group of interfaces. The interfaces is a group of interfaces which the service proxy object instance implements.

Object useService(String serverURL, Class type);
Object useService(String serverURL, Class[] interfaces);
Object useService(String serverURL, String username, String password, Class type);
Object useService(String serverURL, String username, String password, Class[] interfaces);

Set the URL of the PHPRPC Server and get a service proxy object instance.

boolean setKeyLength(int keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

int getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(int encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

int getEncryptMode();

Get the encrypt mode.

void setCharset(String charset);

Set the request charset. Use it before invoke the remote function. The default value is “UTF-8″ or as the response charset.

String getCharset();

Get the response charset. Use it after invoke the remote function.

void setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of milliseconds. Default value is 30 seconds.

int getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of milliseconds.

Object invoke(String funcname, Object[] args);
Object invoke(String funcname, Object[] args, boolean byRef);

Invoke the server function with the function name and arguments array. if you want to transfer the arguments by reference, set byRef to be true.

String getOutput();

Get the output of the server console after invoke the server function.

PHPRPC_Error getWarning();

Get the warning of the server function after invoke the server function.

constructor PHPRPC_Error(int errno, String errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of remote function.

int getNumber();

return error number.

String getMessage();

return error message.

String toString();

return a string which include the error number and error message.

» 阅读全文