content-length bytes were read and there was no trailing null byte
2017-10-29 15:28
369 查看
主要的就是编码问题,不支持中文,当我们发送中文的时候会报错。
为了解决这一问题,我们改动了源码,因为他把字符都存在了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);
}
为了解决这一问题,我们改动了源码,因为他把字符都存在了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);
}
相关文章推荐
- Azure 删除VHD时报错:There is currently a lease on the blob and no lease ID was specified in the request
- FAQ(15):A query was run and no Result Maps were found for the Mapped Statement 'com.smbms.dao.UserMa
- [uwsgi-body-read] Error reading 65536 bytes. Content-Length: 560903 consumed: 0 left: 560903 message
- A query was run and no Result Maps were found for the Mapped Statement
- A query was run and no Result Maps were found
- A query was run and no Result Maps were found for the Mapped Statement 'com.dao.CommentDao.reviewtot
- A query was run and no Result Maps were found
- A query was run and no Result Maps were found for the Mapped Statement
- A query was run and no Result Maps were found for the Mapped Statement
- mybatis报错:A query was run and no Result Maps were found for the Mapped Statement
- A query was run and no Result Maps were found for the Mapped Statement
- mybatis配置文件xxxx.xml中缺失返回类型的后果A query was run and no Result Maps were found
- org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the
- mybatis报错:A query was run and no Result Maps were found for the Mapped Statement
- org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the
- No valid signing identities (i.e. certificate and private key pair) matching the team ID “(null)” were found.
- A query was run and no Result Maps were found for the Mapped Statement 'com.atguigu.atcrowdfunding.p
- No valid signing identities (i.e. certificate and private key pair) matching the team ID “(null)” were found.
- Read PDF,Show “NullReferenceException was unhandled Object reference no
- A query was run and no Result Maps were found for the Mapped Statement