175 lines (128 with data), 3.5 kB
PHP/Java Bridge protocol version 1.0.2
Requests are marked with "->", responses with "<-". The server
continues to process requests until EOF. Only the first character is
significant.
The communication must begin with [C]reateInstance. After that
[I]nvoke may be used. The server responds with a single ARG which also
carries the last request context ID. The request context ID is your
request context, for example the location of a cell where the response
should be stored; a structure or something like that. In PHP for
example we allocate a pval and pass it as the ID to the Invoke or
Create request. When the response arrives, we receive our ID along
with the result so we know exactly where to store the result).
Example:
$o = new java("java.lang.Long", 6);
$o->toString(); // discard result
-> <CreateInstance value="java.lang.Long" predicate="Instance" id="78532">
<Long value="6"/>
</CreateInstance>
<- <Object value="1" id="78532"/>
-> <Invoke value="1" method="toString" predicate="Invoke" id="0">
</Invoke>
<- <String value="6" id="0"/>
Optional requests:
The optional M, F requests may be used to capture a method and invoke
it more than once. The M (GetMethod) request responds with a method
[O]bject which can be used as the argument for all further F
(CallMethod) requests. [I]nvoke should be used instead of M/F. It is a
little bit slower but easier to handle.
All aquired [O]bject handles may be destroyed by invoking U (destroy).
However, this isn't necessary either. The server tracks all handles
and automatically destroys them after EOF. It is an error to further
reference destroyed handles.
Main requests:
->
CreateInstance:
<C v=name p=C|I i=ID> ...ARGS...
</C>
v: string
p: char (Reference[C]lass, Create[I]nstance)
i: long
->
Invoke:
<I v=object m=method p=P|I i=ID> ...ARGS...
</I>
v: long
m: string
p: char (examine[P]roperty, [I]nvoke method)
i: long
When v=0, the call is directed to the current request-handling
instance of the java bridge.
ARGS or response:
<->
String:
<S v=str [i=ID] />
v: string
i: long (reply only)
<->
Boolean:
<B v=T|F [i=ID] />
v: char ([T]rue, [F]alse)
i: long (reply only)
<->
Long:
<L v=l [i=ID] />
v: long
i: long (reply only)
<->
Double:
<D v=d [i=ID] />
v: double
i: long (reply only)
<->
Object:
<O v=object [i=ID] />
v: long
i: long (reply only)
NULL values can be send as either v="" or v="0"
<-
Exception:
<E v=object m=stringRepresentation i=ID />
v: long
m: string
i: long
-> (or <->, see below)
Composite:
<X t=A|H [i=ID] /> ...PAIR...
</X>
t: char ([A]rray, [H]ashtable)
i: long (reply only)
-> (or <->, see below)
Pair:
<P [t=N|S v=key]> ...ARG...
</P>
t: char (key is [N]umeric, [S]tring or doesn't exist (if X=A))
v: long (if X=H and t=N)
v: string (if X=H and t=S)
OPTIONAL requests:
->
MethodGet:
<M v=object, m=method id=ID > ...ARGS...
</M>
v: long
m: string
i: long
->
CallMethod:
<F v=object m=method i=ID > ...ARGS...
</F>
v: long
m: long
i: long
->
Destroy:
<U v=object />
v: long
NOTES:
If the first byte is neither a "<" nor a space, bits [0,1], [2,4] and
[6,7] have a special meaning:
Bit 0: Reserved.
Bit 1: Client wants arrays as values. The server will return X and P
instead of O.
Bit 2,3,4: log level (from java.log_level)
Bit 5: always 0
Bit 6: set to 1 if bit[0,1] are used
Bit 7: set to 1 if bit[2,4] are used
The default is 0304 for PHP5 and 0306 for PHP4.
It is possible to "ping" the server by sending it the byte 0x0. If
alive it will send back a 0x0.