@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;
   }
 }
 @Override
 public Configurator getConfigurator() {
   if (configurator == null) {
     configurator = new JavaxWebSocketConfigurator(delegate.getConfigurator());
   }
   return configurator;
 }
Esempio n. 3
0
 @OnOpen
 public void startChatChannel(EndpointConfig config, Session session) {
   this.endpointConfig = (ServerEndpointConfig) config;
   ChatServerConfigurator csc = (ChatServerConfigurator) endpointConfig.getConfigurator();
   this.transcript = csc.getTranscript();
   this.session = session;
   try {
     Class.forName("com.mysql.jdbc.Driver");
   } catch (ClassNotFoundException t) {
   }
 }
  @Override
  public void register(ServerEndpointConfig serverConfig, String contextPath)
      throws DeploymentException {

    TyrusEndpointWrapper ew;

    Class<?> endpointClass = serverConfig.getEndpointClass();
    boolean isEndpointClass = false;

    do {
      endpointClass = endpointClass.getSuperclass();
      if (endpointClass.equals(Endpoint.class)) {
        isEndpointClass = true;
      }
    } while (!endpointClass.equals(Object.class));

    if (isEndpointClass) {
      // we are pretty sure that endpoint class is javax.websocket.Endpoint descendant.
      //noinspection unchecked
      ew =
          new TyrusEndpointWrapper(
              (Class<? extends Endpoint>) serverConfig.getEndpointClass(),
              serverConfig,
              componentProviderService,
              webSocketContainer,
              contextPath,
              serverConfig.getConfigurator());
    } else {
      final ErrorCollector collector = new ErrorCollector();

      final AnnotatedEndpoint endpoint =
          AnnotatedEndpoint.fromClass(
              serverConfig.getEndpointClass(), componentProviderService, true, collector);
      final EndpointConfig config = endpoint.getEndpointConfig();

      ew =
          new TyrusEndpointWrapper(
              endpoint,
              config,
              componentProviderService,
              webSocketContainer,
              contextPath,
              config instanceof ServerEndpointConfig
                  ? ((ServerEndpointConfig) config).getConfigurator()
                  : null);

      if (!collector.isEmpty()) {
        throw collector.composeComprehensiveException();
      }
    }

    register(new TyrusEndpoint(ew));
  }
Esempio n. 5
0
  /**
   * Invoked when server side handshake is ready to send response.
   *
   * <p>Changes in response parameter will be reflected in data sent back to client.
   *
   * @param request original request which caused this handshake.
   * @param response response to be send.
   */
  public void onHandShakeResponse(UpgradeRequest request, UpgradeResponse response) {
    final EndpointConfig configuration = this.endpoint.getEndpointConfig();

    if (configuration instanceof ServerEndpointConfig) {

      // http://java.net/jira/browse/TYRUS-62
      final ServerEndpointConfig serverEndpointConfig = (ServerEndpointConfig) configuration;
      serverEndpointConfig
          .getConfigurator()
          .modifyHandshake(serverEndpointConfig, createHandshakeRequest(request), response);
    }
  }