mina服务端,c++客户端交互中中文问题? 400 报错
用mina作为服务端,对方客户端是C++.
报文定义:8位报文长度+报文体
对方发送不包含中文的报文时,一切没有问题,但是一旦带了中文就不对了,
在网上看了,说是要字符编码转换 然后也设置了acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("GBK"))));
本人菜鸟新手,请问这个问题怎么解决,是不是要自己写个解码器?
提示错误
org.apache.mina.filter.codec.ProtocolDecoderException: java.nio.charset.MalformedInputException: Input length = 1 (Hexdump: 30 30 30 30 30 34 35 36 3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 20 65 6E 63 6F 64 69 6E 67 3D 22 47 42 4B 22 3F 3E 3C 46 4F 52 4D 44 41 54 41 3E 3C 48 45 41 44 3E 3C 4A 4B 44 4D 3E 32 31 33 30 31 3C 2F 4A 4B 44 4D 3E 3C 46 53 44 57 3E 39 35 35 39 39 3C 2F 46 53 44 57 3E 3C 46 53 44 51 3E 33 32 30 34 30 30 3C 2F 46 53 44 51 3E 3C 4A 53 44 57 3E 53 42 58 54 3C 2F 4A 53 44 57 3E 3C 4A 53 44 51 3E 33 32 30 34 38 32 3C 2F 4A 53 44 51 3E 3C 43 5A 59 48 3E B3 A3 D6 DD C5 A9 D0 D0 3C 2F 43 5A 59 48 3E 3C 4A 59 58 48 3E 33 32 30 34 30 30 39 35 35 39 39 32 30 31 34 30 34 33 30 31 30 31 30 30 34 41 30 31 63 3C 2F 4A 59 58 48 3E 3C 4A 59 51 44 3E 31 3C 2F 4A 59 51 44 3E 3C 59 48 58 58 3E B3 A3 D6 DD C5 A9 D0 D0 B2 D9 D7 F7 C8 CB D4 B1 3C 2F 59 48 58 58 3E 3C 4B 4C 58 58 3E 31 32 33 34 35 36 37 38 3C 2F 4B 4C 58 58 3E 3C 4A 59 44 4D 3E 30 30 30 30 30 30 3C 2F 4A 59 44 4D 3E 3C 52 45 54 43 4F 44 45 3E 30 30 30 30 30 30 3C 2F 52 45 54 43 4F 44 45 3E 3C 52 45 54 49 4E 46 4F 3E B3 A3 D6 DD C5 A9 D0 D0 B7 A2 C6 F0 B8 F6 C8 CB B2 CE B1 A3 D0 C5 CF A2 B2 E9 D1 AF 3C 2F 52 45 54 49 4E 46 4F 3E 3C 2F 48 45 41 44 3E 3C 44 41 54 41 3E 3C 42 41 5A 38 30 35 3E 31 3C 2F 42 41 5A 38 30 35 3E 3C 4A 59 4C 53 48 3E 31 3C 2F 4A 59 4C 53 48 3E 3C 5A 4A 4C 58 3E 30 31 3C 2F 5A 4A 4C 58 3E 3C 5A 4A 48 4D 3E 31 3C 2F 5A 4A 48 4D 3E 3C 2F 44 41 54 41 3E 3C 2F 46 4F 52 4D 44 41 54 41 3E 0A)
at com.neusoft.si.bank.server.socket.SIBankProtocolCodecFilter.messageReceived(SIBankProtocolCodecFilter.java:112)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:793)
at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:119)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:426)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:638)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:598)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:587)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$400(AbstractPollingIoProcessor.java:61)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:969)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
at org.apache.mina.core.buffer.AbstractIoBuffer.getString(AbstractIoBuffer.java:1442)
at com.neusoft.si.bank.server.socket.SIBankTextLineDecoder.decodeAuto(SIBankTextLineDecoder.java:187)
at com.neusoft.si.bank.server.socket.SIBankTextLineDecoder.decode(SIBankTextLineDecoder.java:126)
at com.neusoft.si.bank.server.socket.SIBankProtocolCodecFilter.messageReceived(SIBankProtocolCodecFilter.java:102)
... 15 more
对方C++放过来应该是使用GBK编码,java在解析为字符串的时候要通过编码方式,如果直接获取C++发送的字符串肯定是不行的,而且java的字符串是unicode编码,需要进行转换。网上很多。。
######对方C++放过来应该是使用GBK编码,java在解析为字符串的时候要通过编码方式,如果直接获取C++发送的字符串肯定是不行的,而且java的字符串是unicode编码,需要进行转换。网上很多。。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。