一、问题来源

  最近做一个机场闸机管理系统的后台程序,程序与闸机之间的数据交互方式使用websocket协议,闸机会实时传闸机通行数据给我的后台,数据中包含图片的base64数据,这就导致数据报文非常大,使用过程中出现如下报错:

1009 The decoded text message was too big for the output buffer and the endpoint does not support partial messages true

显然是报文过大导致的。

二、解决方法

  springboot启动时重新设置org.apache.tomcat.websocket.textBufferSize参数的大小,该参数默认大小为8192 bytes,因此改大点问题便解决了,代码修改如下:

@Slf4j
@SpringBootApplication
@EnableScheduling
public class GatemanagerApplication implements ServletContextInitializer {

public static void main(String[] args) {
SpringApplication.run(GatemanagerApplication.class, args);
log.info("闸机管理平台启动成功!");
}

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addListener(WebAppRootListener.class);
servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","1024000");
}
}

三、总结

  网上资料显示如上配置假如是以springboot内置tomcat启动是没有问题的,但是打成war后使用外置tomcat运行却不生效,最终发现是因为外置tomcat版本问题,出问题的版本是tomcat8.0.xx,而使用tomcat8.5.xx就没有这个问题了。我暂时还没遇到该问题,遇到再说。