【Bug历练手册】Frame must be terminated with a null octet

stomp body 中文解析 问题

Spring 里边对于Stomp 通信解析通过StompEncoder实现,核心代码如下

    public byte[] encode(Map<String, Object> headers, byte[] payload) {
        Assert.notNull(headers, "'headers' is required");
        Assert.notNull(payload, "'payload' is required");

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(128 + payload.length);
            DataOutputStream output = new DataOutputStream(baos);

            if (SimpMessageType.HEARTBEAT.equals(SimpMessageHeaderAccessor.getMessageType(headers))) {
                if (logger.isTraceEnabled()) {
                    logger.trace("Encoding heartbeat");
                }
                output.write(StompDecoder.HEARTBEAT_PAYLOAD);
            }

            else {
                StompCommand command = StompHeaderAccessor.getCommand(headers);
                if (command == null) {
                    throw new IllegalStateException("Missing STOMP command: " + headers);
                }

                output.write(command.toString().getBytes(StompDecoder.UTF8_CHARSET));
                output.write(LF);
                writeHeaders(command, headers, payload, output);
                output.write(LF);
                writeBody(payload, output);
                output.write((byte) 0);
            }

            return baos.toByteArray();
        }
        catch (IOException ex) {
            throw new StompConversionException("Failed to encode STOMP frame, headers=" + headers,  ex);
        }
    }

字符集选用UTF-8解析

问题解决

出现这种问题主要是客户端序列化时对于UTF-8支持有问题, 之前我碰到的情况主要是 Socket Js客户端中,并未将web页面中的文字转化为UTF8格式

转载于:https://www.cnblogs.com/cunchen/p/9464104.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值