content-length bytes were read and there was no trailing null byte

主要的就是编码问题,不支持中文,当我们发送中文的时候会报错。

为了解决这一问题,我们改动了源码,因为他把字符都存在了byte数组中,英文的话一个英文占一个字节,但是中文的话一个汉字需要占用两个字节,对于中文来说长度不够,所以会报错。

最后我们改动了activemq-stomp-5.12.1.jar里面的StompWireformat文件,改动了unmarshal方法,

原来的判断:

 if (((action.equals("SEND")) || (action.equals("MESSAGE"))) && (contentLength != null))

      {

        int length = parseContentLength(contentLength, this.frameSize);

 

        data = new byte[length];

        in.readFully(data);

 

        if (in.readByte() != 0) {

          throw new ProtocolException("content-length bytes were read and there was no trailing null byte", true);

        }

 

      }

      else

      {

        ByteArrayOutputStream baos = null;

        while ((b = in.readByte()) != 0) {

          if (baos == null) {

            baos = new ByteArrayOutputStream(); } else {

            if (baos.size() > getMaxDataLength()) {

              throw new ProtocolException("The maximum data length was exceeded", true);

            }

            if (this.frameSize.incrementAndGet() > getMaxFrameSize()) {

              throw new ProtocolException("The maximum frame size was exceeded", true);

            }

          }

 

          baos.write(b);

        }

 

现在我们将判断去掉之后就可以发送中文了。

try {

            // parse action

            String action = parseAction(in, frameSize);

            // Parse the headers

            HashMap<String, String> headers = parseHeaders(in, frameSize);

 

            // Read in the data part.

            byte[] data = NO_DATA;

            //String contentLength = headers.get(Stomp.Headers.CONTENT_LENGTH);

            byte b;

            ByteArrayOutputStream baos = null;

            while ((b = in.readByte()) != 0) {

                if (baos == null) {

                    baos = new ByteArrayOutputStream();

                } else if (baos.size() > getMaxDataLength()) {

                    throw new ProtocolException("The maximum data length was exceeded"true);

                } else {

                    if (frameSize.incrementAndGet() > getMaxFrameSize()) {

                        throw new ProtocolException("The maximum frame size was exceeded"true);

                    }

                }

 

                baos.write(b);

            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值