documentation examples changes overview quick start installation command-line configuration admin amber clustering caching database deployment ejb 3.0 embedding filters hessian hmtp ioc jsp logging messaging performance quercus/php remoting scheduled tasks security server push servlets third-party troubleshooting virtual hosting watchdog webapp xml and xslt hessian hessian 1.0 spec hessian 2.0 draft spec java binding burlap burlap 1.0 spec burlap design notes hessian messaging | hessian 2.0 specification (draft 2)
Hessian is a compact binary protocol for cross-platform web services and messaging.
The Hessian home page contains the latest information about Hessian. Unlike older binary protocols, Hessian is both self-describing, compact, and portable across languages. The wire protocol for web services should be invisible to application writers, it should not require external schema or IDL. The Hessian protocol has the following design goals:
# starting production top ::= object # 8-bit binary data split into 64k chunks binary ::= 'b' b1 b0 <binary-data> binary # non-final chunk ::= 'B' b1 b0 <binary-data> # final chunk ::= [x20-x2f] <binary-data> # binary data of length 0-15 # boolean true/false boolean ::= 'T' ::= 'F' # time in UTC encoded as 64-bit long milliseconds since epoch date ::= 'd' b7 b6 b5 b4 b3 b2 b1 b0 # 64-bit IEEE double double ::= 'D' b7 b6 b5 b4 b3 b2 b1 b0 ::= x67 # 0.0 ::= x68 # 1.0 ::= x69 b0 # byte cast to double (-128.0 to 127.0) ::= x6a b1 b0 # short cast to double ::= x6b b3 b2 b1 b0 # 32-bit float cast to double # 32-bit signed integer int ::= 'I' b3 b2 b1 b0 ::= [x80-xbf] # -x10 to x3f ::= [xc0-xcf] b0 # -x800 to x7ff ::= [xd0-xd7] b1 b0 # -x40000 to x3ffff # list/vector length length ::= 'l' b3 b2 b1 b0 ::= x6e int # list/vector list ::= 'V' type? length? object* 'z' ::= 'v' int int object* # type-ref, length # 64-bit signed long integer long ::= 'L' b7 b6 b5 b4 b3 b2 b1 b0 ::= [xd8-xef] # -x08 to x0f ::= [xf0-xff] b0 # -x800 to x7ff ::= [x38-x3f] b1 b0 # -x40000 to x3ffff ::= x77 b3 b2 b1 b0 # 32-bit integer cast to long # map/object map ::= 'M' type? (object object)* 'z' # key, value map pairs ::= 'o' int object* # Object instance - type-ref # null value null ::= 'N' # main production for object serialization object ::= null ::= binary ::= boolean ::= date ::= double ::= int ::= list ::= long ::= map ::= object-def object ::= remote ::= ref ::= string ::= xml # definition for an object (compact map) object-def ::= 'O' type int string* # Object reference (e.g. circular trees and graphs) ref ::= 'R' b3 b2 b1 b0 # reference to nth map/list in stream ::= x4a b0 # reference to 1-255th map/list ::= x4b b1 b0 # reference to 1-65535th map/list # UTF-8 encoded character string split into 64k chunks string ::= 's' b1 b0 <string-data> string # non-final chunk ::= 'S' b1 b0 <string-data> # string of length 0-65535 ::= [x00-x1f] <string-data> # string of length 0-31 # map/list types for OO languages type ::= 't' b1 b0 <type-string> # type name ::= x75 int # type reference # UTF-8 encoded XML data xml ::= 'x' b1 b0 <xml-data> xml ::= 'X' b1 b0 <xml-data> top ::= call ::= envelope ::= message ::= reply # RPC-style call call ::= 'c' x02 x00 method object* 'z' # Envelope for encryption/headers envelope ::= 'E' x02 x00 env-chunk* 'z' # header, body, footer env-chunk ::= int (string object)* binary int (string object)* fault ::= 'f' (object object)* 'z' # message/streaming message message ::= 'p' x02 x00 object* 'z' ::= 'P' x02 x00 object* 'z' # RPC method name (possibly mangled for overloading) method ::= 'm' b1 b0 <method-string> # RPC reply reply ::= 'r' x02 x00 object 'z' # successful message/reply ::= 'r' x02 x00 fault 'z' # exception/fault reply Hessian's object serialization has 9 primitive types:
It has 2 combining constructs: Finally, it has 2 special contructs: Hessian 2.0 has 3 reference maps:
binary databinary ::= b b1 b0 <binary-data> binary ::= B b1 b0 <binary-data> ::= [x20-x2f] <binary-data> Binary data is encoded in chunks. represents the final chunk and represents any non-final chunk. Each chunk has a 16-bit length value.booleanboolean ::= T ::= F The byte represents false and the byte represents true.T # true F # false datedate ::= d b7 b6 b5 b4 b3 b2 b1 b0 Date represented by a 64-bit long of milliseconds since the epoch, GMT. d x00 x00 x00 xd0 x4b x92 x84 xb8 doubledouble ::= D b7 b6 b5 b4 b3 b2 b1 b0 ::= x67 ::= x68 ::= x69 b0 ::= x6a b1 b0 ::= x6b b3 b2 b1 b0 A 64-bit IEEE floating pointer number. Compact: double byteDoubles between -128.0 and 127.0 with no fractional component can be represented in two bytes by casting the byte value to a double. Compact: double shortDoubles between -32768.0 and 32767.0 with no fractional component can be represented in three bytes by casting the short value to a double. intint ::= 'I' b3 b2 b1 b0 ::= [x80-xbf] ::= [xc0-xcf] b0 ::= [xd0-xd7] b1 b0 A 32-bit signed integer. An integer is represented by the byte followed by the 4-bytes of the integer in big-endian orderCompact: single octet integersIntegers between -16 and 47 can be encoded by a single byte in the
range Compact: two octet integers (byte)Integers between -2048 and 2047 can be encoded in two bytes with
the leading byte in the range listlist ::= V type? length? object* z ::= v int int object* An ordered list, like an array. All lists have a type string, a length, a list of objects, and a trailing 'z'. The type string may be an arbitrary UTF-8 string understood by the service (often a Java class name, but this isn't required.) The length may be -1 to indicate that the list is variable length. Each item is added to the reference list to handle shared and circular elements. See the element.Any parser expecting a Note The valid values of must also accept a or a shared . are not specified in this document and may depend on the specific application. For example, a Java EJB server which exposes an Hessian interface can use the information to instantiate the specific array type. On the other hand, a Perl server would likely ignore the contents of entirely and create a generic array.Compact: repeated listHessian 2.0 allows a compact form of the list for successive lists of the same type where the length is known beforehand. The type and length are encoded by integers, where the type is a reference to an earlier specified type. list examplesV t x00 x04 [int # encoding of int[] type x6e x02 # length = 2 x90 # integer 0 x91 # integer 1 z V x90 # integer 0 x06 foobar # "foobar" z V t x00 x04 [int # type for int[] (save as type #1) x63 x02 # length 2 x90 # integer 0 x91 # integer 1 z v x91 # type reference to int[] (integer #1) x92 # length 2 x92 # integer 2 x93 # integer 3 longlong ::= L b7 b6 b5 b4 b3 b2 b1 b0 ::= [xd8-xef] ::= [xf0-xff] b0 ::= [x38-x3f] b1 b0 ::= x77 b3 b2 b1 b0 A 64-bit signed integer. An long is represented by the byte followed by the 8-bytes of the integer in big-endian orderCompact: single octet longsLongs between -8 and 15 are represented by a single byte in the
range Compact: two octet longs (byte)Longs between -2048 and 2047 are encoded in two bytes with
the leading byte in the range Compact: three octet longs (short)Longs between -262144 and 262143 are encoded in three bytes with
the leading byte in the range Compact: four octet longs (int)Longs between which fit into 32-bits are encoded in five bytes with
the leading byte xe0 # 0 xd8 # -8 xef # 15 xf8 x00 # 0 xf0 x00 # -2048 xf7 x00 # -256 xff xff # 2047 x3c x00 x00 # 0 x38 x00 x00 # -262144 x3f xff xff # 262143 x77 x00 x00 x00 x00 # 0 x77 x00 x00 x01 x2c # 300 L x00 x00 x00 x00 x00 x00 x01 x2c # 300 mapmap ::= M type? (object object)* z ::= 'o' int object* object-def ::= 'O' type int string* Represents serialized objects and Maps. The element describes the type of the map. Objects are represented by a map from field names to their values and is the class of the object itself.The may be empty, i.e. a zero length. The parser is responsible for choosing a type if one is not specified. For objects, unrecognized keys will be ignored.Each Note The is added to the reference list. Any time the parser expects a , it must also be able to support a or a . is chosen by the service. Often it may be the Java classname describing the service.Compact: object definitionHessian 2.0 has a compact object form where the field names are only serialized once. Following objects only need to serialize their values The object definition includes a mandatory type string, the number of fields, and the field names. The object definition is stored in the object definition map and will be referenced by object instances with an integer reference. Compact: object instantiationHessian 2.0 has a compact object form where the field names are only serialized once. Following objects only need to serialize their values The object instantiation creates a new object based on a previous definition. The integer value refers to the object definition. map examplesmap = new HashMap(); map.put(new Integer(1), "fee"); map.put(new Integer(16), "fie"); map.put(new Integer(256), "foe"); --- M x91 # 1 x03 fee # "fee" xa0 # 16 x03 fie # "fie" xb9 x00 # 256 x03 foe # "foe" z public class Car implements Serializable { String color = "aquamarine"; String model = "Beetle"; int mileage = 65536; } --- M t x00 x13 com.caucho.test.Car # type x05 color # color field x0a aquamarine x05 model # model field x06 Beetle x07 mileage # mileage field I x00 x01 x00 x00 z class Car { String color; String model; } out.writeObject(new Car("red", "corvette")); out.writeObject(new Car("green", "civic")); --- O # object definition (#0) t x00 x0b example.Car # type is example.Car x92 # two fields x05 color # color field name x05 model # model field name o x90 # object definition #0 x03 red # color field value x08 corvette # model field value o x90 # object definition #0 x05 green # color field value x05 civic # model field value enum Color { RED, GREEN, BLUE, } out.writeObject(Color.RED); out.writeObject(Color.GREEN); out.writeObject(Color.BLUE); out.writeObject(Color.GREEN); --- O # object definition #0 t x00 x0b example.Color # type is example.Color x91 # one field x04 name # enumeration field is "name" o # object #0 x90 # object definition ref #0 x03 RED # RED value o # object #1 x90 # object definition ref #0 x05 GREEN # GREEN value o # object #2 x90 # object definition ref #0 x04 BLUE # BLUE value x4a x01 # object ref #1, i.e. Color.GREEN nullnull ::= N Null represents a null pointer. The byte represents the null pointer.values are allowed in place of any , , , , , or . refAn integer referring to a previous or instance. As each or is read from the input stream, it is assigned the integer position in the stream, i.e. the first or is '0', the next is '1', etc. A later can then use the previous object. Writers are not required to generate , but parsers must be able to recognize them.ref ::= R b3 b2 b1 b0 can refer to incompletely-read items. For example, a circular linked-list will refer to the first link before the entire list has been read. A possible implementation would add each and to an array as it's read. The will return the corresponding object from the array. To support circular structures, the implementation would store the or immediately, before filling in the object's contents.Each <list> or <array> is stored into an array as it is parsed. <ref> selects one of the stored objects. The first object is numbered '0'. list = new LinkedList(); list.head = 1; list.tail = list; M t x00 x0a LinkedList S x00 x04 head I x00 x00 x00 x01 S x00 x04 tail R x00 x00 x00 x00 z remoteA reference to a remote object. The remote has a and a utf-8 string representing the object's URL.remote ::= r t b1 b0 <type-name> string r t x00 x0c test.TestObj S x00 x24 http://slytherin/ejbhome?id=69Xm8-zW stringstring ::= s b1 b0 <utf-8-data> string ::= S b1 b0 <utf-8-data> ::= [x00-x1f] <utf-8-data> A 16-bit unicode character string encoded in UTF-8. Strings are encoded in chunks. represents the final chunk and represents any non-final chunk. Each chunk has a 16-bit length value.The length is the number of characters, which may be different than the number of bytes. String chunks may not split surrogate pairs. xmlxml ::= x b1 b0 <utf-8-data> xml ::= X b1 b0 utf-8-data An XML document encoded as a 16-bit unicode character string encoded in UTF-8. XML data is encoded in chunks. represents the final chunk and represents any initial chunk.Each chunk has a 16-bit length value. The length is the number of characters, which may be different than the number of bytes. X x00 x10 <top>hello</top> Hessian message syntax organizes serialized data for messaging and RPC applications. The envelope syntax enables compression, encryption, signatures, and any routing or context headers to wrap a Hessian message.
Callcall ::= c x02 x00 m b1 b0 <method-string> object* z A Hessian call invokes a method on an object with an argument list. The object is specified by the container, e.g. for a HTTP request, it's the HTTP URL. The arguments are specified by Hessian serialization. Methods and OverloadingMethod names must be unique. Two styles of overloading are supported: overloading by number of argumetns and overloading by argument types. Overloading is permitted by encoding the argument types in the method names. The types of the actual arguments must not be used to select the methods. Method names beginning with are reserved.Servers should accept calls with either the mangled method name or the unmangled method name. Clients should send the mangled method name. Note See the Java binding for a possible overloading scheme.add(int a, int b) add_int_int add(double a, double b) add_double_double add(shopping.Cart cart, shopping.Item item) add_shopping.Cart_shopping.Item ArgumentsArguments immediately follow the method in positional order. Argument values use Hessian's serialization. All arguments share references, i.e. the reference list starts with the first argument and continues for all other arguments. This lets two arguments share values. bean = new qa.Bean("foo", 13); System.out.println(remote.eq(bean, bean)); c x02 x00 m x00 x02 eq M t x00 x07 qa.Bean S x00 x03 foo I x00 x00 x00 x0d z R x00 x00 x00 x00 z The number and type of arguments are fixed by the remote method. Variable length arguments are forbidden. Implementations may take advantage of the expected type to improve performance. Envelopeenvelope ::= E x02 x00 m b1 b0 <method-string> env-chunk* z env-chunk ::= int (string object)* binary int (string object)* A Hessian envelope wraps a Hessian message, adding headers and footers and possibly compressing or encrypting the wrapped message. The envelope type is identified by a method string, e.g. "com.caucho.hessian.io.Deflation" or "com.caucho.hessian.security.X509Encryption". Some envelopes may chunk the data, providing multiple header/footer chunks. For example, a signature envelope might chunk a large streaming message to reduce the amount of buffering required to validate the signatures. Envelope examplesE x02 x00 m x00 x08 Identity # "Identity" envelope does nothing to the body x90 # no headers B x00 x0a # binary wrapped body (12 bytes) p x02 x00 # wrapped message x05 hello # "hello" z # end of wrapped message x90 # no footers z # end of envelope E x02 x00 m x00 x08 Identity # "Identity" envelope does nothing to the body x90 # no headers B x00 x0c # binary header for wrapped body (10 bytes) p x02 x00 # wrapped message x07 hello, # "hello, " z # end of wrapped message x90 # no footers x90 # no headers B x00 x08 # binary wrapped body (10 bytes) p x02 x00 # wrapped message x05 world # world z x90 # no footers z # end of envelope E x02 x00 m x00 x09 Deflation # "Deflation" envelope compresses the body x90 # no headers B x00 x0a # binary wrapped body (32 bytes) x78 x9c x4b... # compressed message x90 # no footers z # end of envelope Messagemessage ::= p x02 x00 object* z A Hessian message contains a sequence of Hessian serialized objects. Messages can be used for multihop data transfer or simply for storing serialized data. Replyvalid-reply ::= r x02 x00 header* object z fault-reply ::= r x02 x00 header* fault z ValueA successful reply returns a single value and possibly some header information. r x01 x00 I x00 x00 x00 x05 z FaultsFailed calls return a .Each fault has a number of informative fields, expressed like <map> entries. The defined fields are , , and . is one of a short list of strings defined below. is a user-readable message. is an object representing the exception. In Java, will be a serialized exception.r x01 x00 f S x00 x04 code S x00 x10 ServiceException S x00 x07 message S x00 x0e File Not Found S x00 x06 detail M t x00 x1d java.io.FileNotFoundException z z
Hessian services are identified by URLs. Typically, these will be HTTP URLs, although protocols would be possible as well. Object Naming (non-normative)URLs are flexible enough to encode object instances as well as simple static service locations. The URL uniquely identifies the Hessian object. Thus, Hessian can support object-oriented services, e.g. naming services, entity beans, or session beans, specified by the URL without requiring extra method parameters or headers. Object naming may use the query string convention that "?id=XXX" names the object "XXX" in the given service. This convention is recommented, but not required. For example, a stock quote service might have a factory interface like http://foo.com/stock and object instances like http://foo.com?id=PEET. The factory interface would return valid object references through the factory methods. Object naming (non-normative)As an example, the following format is used for EJB: http://hostname/hessian?id= identifies the EJB container. In Resin-EJB, this will refer to the EJB Servlet. "/hessian" is the servlet prefix (url-pattern.) HTTP is just used as an example; Hessian does not require the use of HTTP. , the path info of the request, identifies the EJB name, specifically the home interface. EJB containers can contain several entity and session beans, each with its own EJB home. The corresponds to the ejb-name in the deployment descriptor. identifies the specific object. For entity beans, the object-id encodes the primary key. For session beans, the object-id encodes a unique session identifier. Home interfaces have no ";ejbid=..." portion. http://localhost/hessian/my-entity-bean http://localhost/hessian/my-entity-bean?ejbid=slytherin http://localhost/hessian/my-session-bean http://localhost/hessian/my-session-bean?ejbid=M9Zs1Zm Hessian is organized as a bytecode protocol. A Hessian implementation is essentially a big switch statement on the initial bytecode. x00 - x1f # utf-8 string length 0-32 x20 - x2f # binary data length 0-16 x30 - x37 # reserved x38 - x3f # long from -x40000 to x3ffff x40 - x41 # reserved x42 # 8-bit binary data final chunk ('B') x43 # reserved ('C' streaming call) x44 # 64-bit IEEE encoded double ('D') x45 # reserved ('E' envelope) x46 # boolean false ('F') x47 # reserved x48 # reserved ('H' header) x49 # 32-bit signed integer ('I') x4a # reference to 1-256th map/list x4b # reference to 1-65536th map/list x4c # 64-bit signed long integer ('L') x4d # map with optional type ('M') x4e # null ('N') x4f # object definition ('O') x50 # reserved ('P' streaming message/post) x51 # reserved x52 # reference to map/list - integer ('R') x53 # utf-8 string final chunk ('S') x54 # boolean true ('T') x55 # reserved x56 # list/vector ('V') x57 # reserved x58 # utf-8 xml final chunk ('X') x59 - x62 # reserved x62 # 8-bit binary data non-final chunk ('b') x63 # reserved ('c' call for RPC) x64 # UTC time encoded as 64-bit long milliseconds since epoch ('d') x65 # reserved x66 # reserved ('f' for fault for RPC) x67 # double 0.0 x68 # double 1.0 x69 # double represented as byte (-128.0 to 127.0) x6a # double represented as short (-32768.0 to 327676.0) x6b # double represented as float x6c # list/vector length ('l') x6d # reserved ('m' method for RPC call) x6e # list/vector compact length x6f # object instance ('o') x70 # reserved ('p' - message/post) x71 # reserved x72 # reserved ('r' reply for message/RPC) x73 # utf-8 string non-final chunk ('s') x74 # map/list type ('t') x75 # type-ref x76 # compact vector ('v') x77 # long encoded as 32-bit int x78 # utf-8 XML non-final chunk ('x') x79 # reserved x7a # list/map terminator ('z') x7b - x7f # reserved x80 - xbf # one-byte compact int (-x10 to x3f, x90 is 0) xc0 - xcf # two-byte compact int (-x800 to x3ff) xd0 - xd7 # three-byte compact int (-x40000 to x3ffff) Copyright 2000-2007 Caucho Technology, Inc. All Rights Reserved. Any party may implement this protocol for any purpose without royalty or license fee, provided that the implementation conforms to this specification. Caucho Technology reserves the right to create a test suite, freely available without royalty or license fee, to validate implementation conformance. The limited permissions granted herein are perpetual and may not be revoked by Caucho Technology or its successors or assigns. This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works. This document and the information contained herein is provided on an "AS IS" basis and CAUCHO TECHNOLOGY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. changes in 2.0 draft 2
changes in V3
changes in V2
|