Hessain调用expected end of map ('z') at '?'错误原因

本文探讨了Hessian接口调用中出现的各种异常问题,包括接口参数不匹配导致的运行时异常、方法重载问题及Hessian版本不一致引发的错误。提供了具体的异常堆栈信息,并给出了相应的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用的接口与实际的接口参数个数、类型不一样

Java代码 收藏代码
  1. com.caucho.hessian.client.HessianRuntimeException:com.caucho.hessian.io.HessianProtocolException:expectedendofmap('z')at'?'
  2. atcom.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java)
  3. at$Proxy4.checkLogin(UnknownSource)
  4. atcom.msd.test.marketing.MarketingHession.testLogin(MarketingHession.java:91)
  5. atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
  6. atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  7. atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  8. atjava.lang.reflect.Method.invoke(Method.java:597)
  9. atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  10. atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  11. atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  12. atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  13. atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
  14. atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  15. atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  16. atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  17. atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  18. atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  19. atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  20. atorg.junit.runners.ParentRunner.run(ParentRunner.java:236)
  21. atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
  22. atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  23. atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  24. atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  25. atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  26. atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  27. Causedby:com.caucho.hessian.io.HessianProtocolException:expectedendofmap('z')at'?'
  28. atcom.caucho.hessian.io.HessianInput.error(HessianInput.java:1642)
  29. atcom.caucho.hessian.io.HessianInput.readMapEnd(HessianInput.java:1220)
  30. atcom.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:190)
  31. atcom.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:127)
  32. atcom.caucho.hessian.io.AbstractMapDeserializer.readObject(AbstractMapDeserializer.java:81)
  33. atcom.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
  34. atcom.caucho.hessian.io.HessianInput.readReply(HessianInput.java:285)
  35. ...25more

hessain接口方法不能重载(方法名一样参数不一样)会报找不到方法

hessain方法重载解决的办法:

HessianProxyFactory factory = new HessianProxyFactory();
factory.setOverloadEnabled(true);

另外一种异情况:

Java代码 收藏代码
  1. Causedby:com.caucho.hessian.io.HessianProtocolException:expectedintegerat0x63
  2. atcom.caucho.hessian.io.Hessian2Input.error(Hessian2Input.java:2705)
  3. atcom.caucho.hessian.io.Hessian2Input.expect(Hessian2Input.java:2686)
  4. atcom.caucho.hessian.io.Hessian2Input.readInt(Hessian2Input.java:845)
  5. atcom.caucho.hessian.io.Hessian2Input.readObjectDefinition(Hessian2Input.java:2024)
  6. atcom.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1674)
  7. atcom.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:220)
  8. ...2more
com.caucho.hessian.io.HessianProtocolException:expected integer at 0x63

请检查接口编写端与调用端Hessian版本是否一致

#include "unity.h" #include "etl.h" #include <stdlib.h> void setUp(void) { } void tearDown(void) { } static int compare_map(new_map *a, new_map *b, int len) { if (a == NULL) return (b == NULL) ? 0 : 1; if (b == NULL) return 1; while (--len >= 0) if ((a[len].key != b[len].key) || (a[len].value != b[len].value)) return 1; return !(len == -1); } static void test_a_single_letter(void) { legacy_map input[] = { { 1, "A" } }; int input_len = 1; new_map expected_map[] = { { 'a', 1 } }; int expected_length = 1; new_map *output = NULL; int actual_length = convert(input, input_len, &output); TEST_ASSERT_EQUAL_INT(expected_length, actual_length); TEST_ASSERT_EQUAL_INT(0, compare_map(expected_map, output, actual_length)); free(output); } static void test_single_score_with_multiple_letters(void) { TEST_IGNORE(); // delete this line to run test legacy_map input[] = { { 1, "AEIOU" } }; int input_len = 1; new_map expected_map[] = { { 'a', 1 }, { 'e', 1 }, { 'i', 1 }, { 'o', 1 }, { 'u', 1 } }; int expected_length = 5; new_map *output = NULL; int actual_length = convert(input, input_len, &output); TEST_ASSERT_EQUAL_INT(expected_length, actual_length); TEST_ASSERT_EQUAL_INT(0, compare_map(expected_map, output, actual_length)); free(output); } static void test_multiple_scores_with_multiple_letters(void) { TEST_IGNORE(); legacy_map input[] = { { 1, "AE" }, { 2, "DG" } }; int input_len = 2; new_map expected_map[] = { { 'a', 1 }, { 'd', 2 }, { 'e', 1 }, { 'g', 2 } }; int expected_length = 4; new_map *output = NULL; int actual_length = convert(input, input_len, &output); TEST_ASSERT_EQUAL_INT(expected_length, actual_length); TEST_ASSERT_EQUAL_INT(0, compare_map(expected_map, output, actual_length)); free(output); } static void test_multiple_scores_with_differing_numbers_of_letters(void) { TEST_IGNORE(); legacy_map input[] = { { 10, "QZ" }, { 1, "AEIOULNRST" }, { 3, "BCMP" }, { 2, "DG" }, { 5, "K" }, { 4, "FHVWY" }, { 8, "JX" } }; int input_len = 7; new_map expected_map[] = { { 'a', 1 }, { 'b', 3 }, { 'c', 3 }, { 'd', 2 }, { 'e', 1 }, { 'f', 4 }, { 'g', 2 }, { 'h', 4 }, { 'i', 1 }, { 'j', 8 }, { 'k', 5 }, { 'l', 1 }, { 'm', 3 }, { 'n', 1 }, { 'o', 1 }, { 'p', 3 }, { 'q', 10 }, { 'r', 1 }, { 's', 1 }, { 't', 1 }, { 'u', 1 }, { 'v', 4 }, { 'w', 4 }, { 'x', 8 }, { 'y', 4 }, { 'z', 10 } }; int expected_length = 26; new_map *output = NULL; int actual_length = convert(input, input_len, &output); TEST_ASSERT_EQUAL_INT(expected_length, actual_length); TEST_ASSERT_EQUAL_INT(0, compare_map(expected_map, output, actual_length)); free(output); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_a_single_letter); RUN_TEST(test_single_score_with_multiple_letters); RUN_TEST(test_multiple_scores_with_multiple_letters); RUN_TEST(test_multiple_scores_with_differing_numbers_of_letters); return UNITY_END(); } 测试函数长这样,修改上面生成的代码来符合测试结果
最新发布
08-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值