《Hessian 接口 Java Python》由会员分享,可在线阅读,更多相关《Hessian 接口 Java Python(39页珍藏版)》请在金锄头文库上搜索。
1、http:/ http:/ http:/ Hessian and Burlap are compact binary and XML protocols for applications needing performance without protocol complexity. Hessian is a small binary protocol. 2.Burlap is a matching XML protocol. Providing a web service is as simple as creating a servlet. Using a service is as si
2、mple as a JDK Proxy interface. 3.Introduction4.Hessian 2.0 supports two types of network communication: remote procedure call (RPC) and message-based. 5.RPC communication is based on “methods“ invoked on a server. The method being invoked is specified in a Hessian 2.0 “call“. Arguments to these meth
3、ods are passed in the call and are serialized using the Hessian 2.0 serialization protocol. If the method was successfully invoked, the return value of the method is also serialized using Hessian 2.0 and sent to the client. If the method was not successfully invoked, a “fault“ is returned to the cli
4、ent. RPC communication can use any underlying network protocol for transport such as HTTP or TCP. 6.Message-based communication is asynchronous and does not necessarily involve the use of methods, clients, or servers. Messages may or may not receive a response message. Messages simply contain other
5、Hessian 2.0 objects. These may be simple types, aggregates like a list or map, or an “envelope“. Envelopes may have headers that specify routing or other special processing information. They may also contain encrypted, signed, and/or compressed data. Thus using messages with envelopes can be useful
6、in cases where end-to-end security is necessary. Message-based communication can also use any underlying network protocol such as HTTP or TCP and may be especially appropriate in queued message systems.7. Hessian GrammarRPC/Messaging Grammartop := version content:= call-1.0:= reply-1.0# RPC-style ca
7、ll call := C string int value*call-1.0 := c x01 x00 content := call # rpc callHessian Serialization ProtocolHessian MessageHessian RPC API Declare:= fault # rpc fault reply:= reply # rpc value reply:= packet+ # streaming packet data:= envelope+ # envelope wrapping contentenvelope := E string env-chu
8、nk* Z env-chunk := int (string value)* packet int (string value)*# RPC fault fault := F (value value)* Z# message/streaming message packet := (x4f b1 b0 )* packet:= P b1 b0 := x70 - x7f := x80 - xff # RPC reply reply := R valuereply-1.0 := r x01 x00 version := H x02 x00FigureFigure 1 1 4. Messages a
9、nd 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 (C): contains a Hessian RPC call, with a method name and arguments.Envel
10、ope (E): wraps a Hessian message for compression, encryption, etc. Envelopes can be nested.Hessian (H): introduces a Hessian stream and indicates its version.Packet (P): contains a sequence of serialized Hessian objects.Reply (R): contains a reply to a Hessian RPC call.Fault (F): contains a reply to
11、 a failed Hessian RPC call.Hessian 1.0 compatibility call (c): is a Hessian 1.0 call.Hessian 1.0 compatibility reply (cr): is a Hessian 2.0 call.4.1. CallTOCTOC Call Grammarcall := C string int value*FigureFigure 2 2 A Hessian call invokes a method on an object with an argument list. The object is s
12、pecified by the container, e.g. for a HTTP request, its the HTTP URL. The arguments are specified by Hessian serialization.8.重载4.1.1. Methods and Overloading 参数和类型不同参数和类型不同Method names must be unique. Two styles of overloading are supported: overloading by number of argumetns and overloading by argu
13、ment 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 _hessian_ are reserved.Servers should accept calls with either the mangled method name or the unmangled method
14、 name. Clients should send the mangled method name.4.1.1.1. Overloading examplesadd(int a, int b) - add_int_intadd(double a, double b) - add_double_doubleadd(shopping.Cart cart, shopping.Item item) -add_shopping.Cart_shopping.Item4.1.2. ArgumentsArguments immediately follow the method in positional
15、order. Argument values use Hessians 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.TOCTOC 4.1.2.1. Arguments examplebean = new qa.Bean(“foo“, 13);System.out.println(remote.eq(bean, bean);- H x02 x00 Cx02 eq # method name = “eq“x92 # two argumentsM x07 qa.Bean # first argumentx03 foox9dZQ x00