Corba传值包含中文解决

分布式系统中,如果两个系统使用corba进行传值,一般来说服务器没有进行相应的特殊配置,传非中文是没有问题的,如果传输的参数中包含中文,那么就会报如下错误:

  
  
  
  
  1. com.sun.corba.se.impl.encoding.CodeSetConversion$JavaCTBConverter convertCharArray
  2. 警告: "IOP02400001: (DATA_CONVERSION) Character does not map to negotiated transmission code set"
  3. org.omg.CORBA.DATA_CONVERSION: vmcid: OMG minor code: 1 completed: No

后来在网上搜了搜,看见一个哥们说需要这么做:

  
  
  
  
  1. java.util.Properties p = new java.util.Properties();
  2. p.setProperty("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109"); // UTF-8, UTF-16
  3. p.setProperty("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001"); // UTF-16, UTF-8
  4. orb = org.omg.CORBA_2_3.ORB.init(args, p);

ALSO, for the ORB on the server side (OmniOrb) I also had to change the native code set from ISO-8859-1 to UTF-8, else the two would get together and negotiate themselves into talking ISO-8859-1.

Now everything seems to be working fine.


其实上面主要就是说进行转码的操作,以及设置服务器上面支持的语言,但是我愣是看的不是很爽,答案不明了呀!其实解决方法很简单,只要仔细看下错误,异常的堆栈中会告诉你你操作那个一个属性的时候出现了异常,也就表示这个属性在corba的传输过程中存在着中文,对其进行相应的转码即可。异常堆栈的提示信息如下:

  
  
  
  
  1. com.sun.corba.se.impl.encoding.CodeSetConversion$JavaCTBConverter convertCharArray
  2. 警告: "IOP02400001: (DATA_CONVERSION) Character does not map to negotiated transmission code set"
  3. org.omg.CORBA.DATA_CONVERSION: vmcid: OMG minor code: 1 completed: No
  4. at com.sun.corba.se.impl.logging.OMGSystemException.charNotInCodeset(OMGSystemException.java:2093)
  5. at com.sun.corba.se.impl.logging.OMGSystemException.charNotInCodeset(OMGSystemException.java:2111)
  6. at com.sun.corba.se.impl.encoding.CodeSetConversion$JavaCTBConverter.convertCharArray(CodeSetConversion.java:259)
  7. at com.sun.corba.se.impl.encoding.CodeSetConversion$JavaCTBConverter.convert(CodeSetConversion.java:206)
  8. at com.sun.corba.se.impl.encoding.CDROutputStream_1_0.writeString(CDROutputStream_1_0.java:478)
  9. at com.sun.corba.se.impl.encoding.CDROutputStream_1_0.write_string(CDROutputStream_1_0.java:467)
  10. at com.sun.corba.se.impl.encoding.CDROutputStream.write_string(CDROutputStream.java:153)
  11. at corba.ElementHelper.write(ElementHelper.java:346)
  12. at corba.ElementListHelper.write(ElementListHelper.java:61)
  13. at RemoteDB.dataSourcePOA._invoke(dataSourcePOA.java:648)
  14. at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:637)
  15. at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:189)
  16. at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1680)
  17. at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1540)
  18. at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:922)
  19. at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:181)
  20. at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:694)
  21. at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:451)
  22. at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1187)
  23. at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:398)
  24. Caused by: java.nio.charset.UnmappableCharacterException: Input length = 1
  25. at java.nio.charset.CoderResult.throwException(CoderResult.java:261)
  26. at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:781)
  27. at com.sun.corba.se.impl.encoding.CodeSetConversion$JavaCTBConverter.convertCharArray(CodeSetConversion.java:244)
  28. ... 17 more

根据idl生成的文件查看属性是否包含中文,对该字段进行转码即可,^_^。

 

 

你可能感兴趣的:(职场,中文,corba,休闲)