示例#1
0
 public Namespace(String name, Configuration configuration) {
   super();
   this.name = name;
   this.jsonSupport = configuration.getJsonSupport();
   this.storeFactory = configuration.getStoreFactory();
   this.exceptionListener = configuration.getExceptionListener();
   this.ackMode = configuration.getAckMode();
 }
 public ChatServiceSocketIOImpl() {
   String hostname = "localhost";
   int port = 8081;
   Configuration cfg = new Configuration();
   cfg.setHostname(hostname);
   cfg.setPort(port);
   server = new SocketIOServer(cfg);
   server.addConnectListener(this);
   server.addDisconnectListener(this);
   server.addEventListener(EVENT_CHAT, ChatMessage.class, this);
 }
  public ByteBuf allocateBuffer(ByteBufAllocator allocator) {
    if (configuration.isPreferDirectBuffer()) {
      return allocator.ioBuffer();
    }

    return allocator.heapBuffer();
  }
  public EncoderHandler(Configuration configuration, PacketEncoder encoder) throws IOException {
    this.encoder = encoder;
    this.configuration = configuration;

    if (configuration.isAddVersionHeader()) {
      readVersion();
    }
  }
  private void addOriginHeaders(Channel channel, HttpResponse res) {
    if (version != null) {
      res.headers().add(HttpHeaders.Names.SERVER, version);
    }

    if (configuration.getOrigin() != null) {
      HttpHeaders.addHeader(res, ACCESS_CONTROL_ALLOW_ORIGIN, configuration.getOrigin());
      HttpHeaders.addHeader(res, ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE);
    } else {
      String origin = channel.attr(ORIGIN).get();
      if (origin != null) {
        HttpHeaders.addHeader(res, ACCESS_CONTROL_ALLOW_ORIGIN, origin);
        HttpHeaders.addHeader(res, ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE);
      } else {
        HttpHeaders.addHeader(res, ACCESS_CONTROL_ALLOW_ORIGIN, "*");
      }
    }
  }