![]() | ![]() | ![]() |
| |||||||||||||||||||||||||||||||||||||||
![]() | ||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||
Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ Hessian Hessian 1.0 spec Hessian 2.0 draft spec Java Binding Burlap Burlap 1.0 Spec Burlap Design Notes Hessian Messaging |
Hessian is a compact binary protocol for cross-platform web services and messaging. Design GoalsThe 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:
Hessian 2.0 Grammar
SerializationHessian'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 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.Compact: short binaryBinary data with length less than 15 may be encoded with a single length byte [x20-x2f]. binary data examples
boolean
The byte represents false and the byte represents true.T # true F # false date
Date represented by a 64-bit long of milliseconds since the epoch, GMT. d x00 x00 x00 xd0 x4b x92 x84 xb8 double
A 64-bit IEEE floating pointer number. Compact: double zeroThe double 0.0 can be represented by the byte Compact: double oneThe double 1.0 can be represented by the byte 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. Compact: double floatDoubles which are equivalent to their 32-bit float representation can be represented as the 4-byte float and then cast to double. double examplesx67 # 0.0 x68 # 1.0 x69 x00 # 0.0 x69 x80 # -128.0 x69 xff # 127.0 x70 x00 x00 # 0.0 x70 x80 x00 # -32768.0 x70 xff xff # 32767.0 D x40 x28 x80 x00 x00 x00 x00 x00 # 12.25 int
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 Compact: three octet integers (short)Integers between -262144 and 262143 can be encoded in three bytes with
the leading byte in the range int examplesx90 # 0 x80 # -16 xbf # 47 xc8 x00 # 0 xc0 x00 # -2048 xc7 x00 # -256 xcf xff # 2047 xd4 x00 x00 # 0 xd0 x00 x00 # -262144 xd7 xff xff # 262143 I x00 x00 x00 x00 # 0 I x00 x00 x01 x2c # 300 list
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 long
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 map
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 null
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.
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.
r t x00 x0c test.TestObj S x00 x24 http://slytherin/ejbhome?id=69Xm8-zW string
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. Compact: short stringsStrings with length less than 32 may be encoded with a single byte length [x00-x1f]. string examplesx00 # "", empty string x05 hello # "hello" x01 xc3 x83 # "\u00c3" S x00 x05 hello # "hello" xml
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> Messages and EnvelopesHessian 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.
Call
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. Call examplesc x02 x00 # call for Hessian 2.0 m x00 x04 add2 # method "add2" x92 # 2 - argument 1 x93 # 3 - argument 2 z # end of argument marker r x02 x00 x95 z Envelope
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 Message
A Hessian message contains a sequence of Hessian serialized objects. Messages can be used for multihop data transfer or simply for storing serialized data. Reply
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
VersioningThe call and response tags include a major and minor byte. The current version is 2.0. Service Location (URLs)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:
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 Bytecode mapHessian is organized as a bytecode protocol. A Hessian implementation is essentially a big switch statement on the initial bytecode.
Copyright and LicensingCopyright 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. Changeschanges in 2.0 draft 2
changes in 2.0 draft 1
changes in 1.0.2
changes in 1.0
changes in V3
changes in V2
|