基于hessian协议调用java方法-一个map例子
来源:互联网 发布:类似maka软件 编辑:程序博客网 时间:2024/05/25 18:11
基于hessian协议调用java方法-一个map例子
map
map ::= M t b16 b8 type-string (object, object)* z
Map类型,同时支持对象Object。
type描述map类型,可为空
如果是对象,type表示类全名
先定义一个接口:
public interface TestService {
public void testMap(Map<String, Object> map);
}
实现这个接口:
public class TestServiceImpl implements TestService {
下载地址
public void testMap(Map<String, Object> map) {
if (map != null) {
for (Entry<String, Object> entry : map.entrySet()) {
System.out.println("key: " + entry.getKey());
System.out.println("value: " + entry.getValue());
}
} else {
System.out.println("null");
}
}
}
基于hessian模拟rpc怎么调用呢?
public class HessianSkeletonTest {
private static TestServiceImpl testService;
private static HessianSkeleton skeleton;
@BeforeClass
public static void initialize() {
testService = new TestServiceImpl();
skeleton = new HessianSkeleton(testService, TestService.class);
}
/**
* m 0x00 0x07 testMap
* M
* S 0x00 0x04 name
* S 0x00 0x06 whoami
* S 0x00 0x03 age
* I 0x00 0x00 0x02 0x0C #0000 0000 0010 1100 #44
* S 0x00 0x04 male
* T
* z #end of map
* z #end of method
*
* @throws IOException
*/
@Test
public void invokeTestMap() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String skey = null;
String svalue = null;
int ivalue = 0;
boolean bvalue = false;
// m 0x00 0x07 testMap
bos.write('m');
bos.write(0x00);
bos.write(0x07);
bos.write("testMap".getBytes());
下载
// M
bos.write('M');
// S 0x00 0x04 name
bos.write('S');
skey = "name";
int length = 4;
length = (length << 16) >>> 16;
bos.write(length >>> 8);
bos.write((length << 8) >>> 8);
bos.write(skey.getBytes());
// S 0x00 0x06 whoami
bos.write('S');
svalue = "whoami";
length = 6;
length = (length << 16) >>> 16;
bos.write(length >>> 8);
bos.write((length << 8) >>> 8);
bos.write(svalue.getBytes());
// S 0x00 0x03 age
bos.write('S');
skey = "age";
length = 3;
length = (length << 16) >>> 16;
bos.write(length >>> 8);
bos.write((length << 8) >>> 8);
bos.write(skey.getBytes());
// I 0x00 0x00 0x02 0x0C #0000 0000 0000 0000 0000 0000 0010 1100 #44
bos.write('I');
ivalue = 44;
bos.write(ivalue >>> 24);
ivalue = (ivalue << 8) >>> 8;
bos.write(ivalue >>> 16);
ivalue = (ivalue << 8) >>> 8;
bos.write(ivalue >>> 8);
ivalue = (ivalue << 8) >>> 8;
bos.write(ivalue);
// S 0x00 0x04 male
bos.write('S');
skey = "male";
length = 4;
length = (length << 16) >>> 16;
bos.write(length >>> 8);
bos.write((length << 8) >>> 8);
bos.write(skey.getBytes());
// T
bvalue = true;
bos.write(bvalue ? 'T' : 'F');
// z
bos.write('z');
// z
bos.write('z');
InputStream isToUse = new ByteArrayInputStream(bos.toByteArray());
OutputStream osToUse = new ByteArrayOutputStream();
AbstractHessianInput in = new HessianInput(isToUse);
AbstractHessianOutput out = new HessianOutput(osToUse);
try {
skeleton.invoke(in, out);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
m 0x00 0x07 testMap
M
S 0x00 0x04 name
S 0x00 0x06 whoami
S 0x00 0x03 age
I 0x00 0x00 0x02 0x0C #0000 0000 0010 1100 #44
S 0x00 0x04 male
T
z #end of map
z #end of method
运行输出:
key: name
value: whoami
key: age
value: 44
key: male
value: true
- 基于hessian协议调用java方法-一个map例子
- 基于Dubbo的Hessian协议实现远程调用
- 基于Dubbo的Hessian协议实现远程调用
- 基于Dubbo的Hessian协议实现远程调用
- 基于dubbo的hessian协议远程调用实例
- Hessian协议的使用例子
- Spring结合Hessian协议远程调用方法名不能重载
- hessian远程服务调用例子
- hessian调用重载方法
- hessian java调用
- java调用hessian配置
- [Java] 演示RMI(远程方法调用) 的一个例子
- Spring2.5远程调用Hessian的例子
- dwr例子6调用返回List、Set或者Map的java方法
- Hessian远程调用及序列化协议
- Hessian远程调用及序列化协议
- PHPHessian调用Java Spring Hessian
- Java远程调用之Hessian
- css之border/padding/margin
- 2.1 2722 和数
- servlet编码
- Sublime text追踪函数插件:ctags
- install opencv with linux
- 基于hessian协议调用java方法-一个map例子
- 写在最前面
- lightoj1097 lucky number 报数类问题 线段树的单点更新
- android 网络编程--socket tcp/ip udp http之间的关系
- 推送的设计
- T1外部计数输入
- 一个可以免费下载牛逼论文的网站Arxiv
- 26:滑雪
- MATLAB im2double、double、mat2gray、im2uint8和uint8的区别及使用