Compress or send gzip data over stomp websocket springboot with embeded tomcat

Viewed 380

I have json data which have more the 1 mb of size and needs to be sent over stomp websocket. We are using spring boot embedded tomcat .

I compressed my data into gzip and then converted to string to send over websocket. i modified the stomp header to send Content-Encoding as part of response but browser is not able to decompress and read it.

How to read the json in client in react/redux/js.

     SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);

accessor.setNativeHeader("content-encoding", "gzip");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
this.template.convertAndSend("/topic/Default", compress("{Dummy Json}"),headers);

public static String compress(String str) {
   try {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   GZIPOutputStream gzip = new GZIPOutputStream(out);
   gzip.write(str.getBytes());
   gzip.close();
   String outStr = out.toString("UTF-8");
   return outStr;
   }

0 Answers
Related