Exemplo n.º 1
0
 @Override
 public void action(AtmosphereResourceImpl r) {
   super.action(r);
   if (r.action().type() == Action.TYPE.RESUME && r.isInScope()) {
     HttpEvent event = (HttpEvent) r.getRequest(false).getAttribute(HTTP_EVENT);
     if (event != null && !r.transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) {
       close(event);
     }
   }
 }
Exemplo n.º 2
0
  @Override
  public Action inspect(final AtmosphereResource ar) {
    final AtmosphereResourceImpl r = AtmosphereResourceImpl.class.cast(ar);
    final AtmosphereRequest request = r.getRequest(false);
    final AtmosphereResponse response = r.getResponse(false);

    String uuid = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID);
    String handshakeUUID = request.getHeader(HeaderConfig.X_ATMO_PROTOCOL);
    if (uuid != null && uuid.equals("0") && handshakeUUID != null) {
      request.header(HeaderConfig.X_ATMO_PROTOCOL, null);
      // Since 1.0.10

      final StringBuffer message =
          new StringBuffer(r.uuid()).append(wsDelimiter).append(System.currentTimeMillis());

      // https://github.com/Atmosphere/atmosphere/issues/993
      boolean track = false;
      if (r.getBroadcaster().getBroadcasterConfig().hasFilters()) {
        for (BroadcastFilter bf : r.getBroadcaster().getBroadcasterConfig().filters()) {
          if (TrackMessageSizeFilter.class.isAssignableFrom(bf.getClass())) {
            track = true;
            break;
          }
        }
      }

      final AtomicReference<String> protocolMessage =
          new AtomicReference<String>(message.toString());
      if (track) {
        protocolMessage.set(
            (String) f.filter(r, protocolMessage.get(), protocolMessage.get()).message());
      }

      if (!Utils.resumableTransport(r.transport())) {
        OnSuspend a =
            new OnSuspend() {
              @Override
              public void onSuspend(AtmosphereResourceEvent event) {
                response.write(protocolMessage.get());
                try {
                  response.flushBuffer();
                } catch (IOException e) {
                  logger.trace("", e);
                }
              }
            };
        // Pass the information to Servlet Based Framework
        request.setAttribute(CALLBACK_JAVASCRIPT_PROTOCOL, a);
        r.addEventListener(a);
      } else {
        response.write(protocolMessage.get());
      }

      // We don't need to reconnect here
      if (r.transport() == AtmosphereResource.TRANSPORT.WEBSOCKET
          || r.transport() == AtmosphereResource.TRANSPORT.STREAMING
          || r.transport() == AtmosphereResource.TRANSPORT.SSE) {
        return Action.CONTINUE;
      } else {
        return Action.SKIP_ATMOSPHEREHANDLER;
      }
    }
    return Action.CONTINUE;
  }