@OnMessage(maxMessageSize = 111222)
 public String echoText(String msg) {
   switch (msg) {
     case "text-max":
       return String.format("%,d", session.getMaxTextMessageBufferSize());
     case "binary-max":
       return String.format("%,d", session.getMaxBinaryMessageBufferSize());
     case "decoders":
       return join(config.getDecoders(), ", ");
     case "encoders":
       return join(config.getEncoders(), ", ");
     case "subprotocols":
       if (serverConfig == null) {
         return "<not a ServerEndpointConfig>";
       } else {
         List<String> protocols = new ArrayList<>();
         protocols.addAll(serverConfig.getSubprotocols());
         Collections.sort(protocols);
         return join(protocols, ", ");
       }
     case "configurator":
       if (serverConfig == null) {
         return "<not a ServerEndpointConfig>";
       } else {
         return serverConfig.getConfigurator().getClass().getName();
       }
     default:
       // normal echo
       return msg;
   }
 }
Пример #2
0
 /**
  * @OnOpen allows us to intercept the creation of a new session. The session class allows us to
  * send data to the user. In the method onOpen, we'll let the user know that the handshake was
  * successful.
  */
 @OnOpen
 public void onOpen(Session session) {
   Logger logger = LogManager.getFormatterLogger(EchoService.class);
   logger.info(session.getId() + " has opened a connection");
   logger.info("MaxBinaryMessageBufferSize %d", session.getMaxBinaryMessageBufferSize());
   logger.info("MaxIdleTimeout %d", session.getMaxIdleTimeout());
   logger.info("MaxTextMessageBufferSize %d", session.getMaxTextMessageBufferSize());
   logger.info("Open sessions size %d", session.getOpenSessions().size());
   logger.info("Protocol %s", session.getProtocolVersion());
   logger.info("QueryString %s", session.getQueryString());
   try {
     session.getBasicRemote().sendText("Connection Established");
   } catch (IOException ex) {
     ex.printStackTrace();
     logger.error(ex.getMessage(), ex);
   }
 }