當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSocketServerHandshaker類代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketServerHandshaker類的具體用法?Java WebSocketServerHandshaker怎麽用?Java WebSocketServerHandshaker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebSocketServerHandshaker類屬於io.netty.handler.codec.http.websocketx包,在下文中一共展示了WebSocketServerHandshaker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: close

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void close() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(channel)
      .expect(close)
      .expect(unit -> {
        Attribute<NettyWebSocket> attr = unit.mock(Attribute.class);
        attr.set(null);

        Channel ctx = unit.get(Channel.class);
        expect(ctx.attr(NettyWebSocket.KEY)).andReturn(attr);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).close(1001, "normal");
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:21,代碼來源:NettyWebSocketTest.java

示例2: closeNoAttr

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void closeNoAttr() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(channel)
      .expect(close)
      .expect(unit -> {
        Channel ctx = unit.get(Channel.class);
        expect(ctx.attr(NettyWebSocket.KEY)).andReturn(null);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).close(1001, "normal");
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:18,代碼來源:NettyWebSocketTest.java

示例3: resume

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void resume() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(false);
        expect(chconf.setAutoRead(true)).andReturn(chconf);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).resume();
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:23,代碼來源:NettyWebSocketTest.java

示例4: resumeIgnored

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void resumeIgnored() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(true);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).resume();
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:22,代碼來源:NettyWebSocketTest.java

示例5: pause

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void pause() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(true);
        expect(chconf.setAutoRead(false)).andReturn(chconf);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).pause();
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:23,代碼來源:NettyWebSocketTest.java

示例6: pauseIgnored

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void pauseIgnored() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        ChannelConfig chconf = unit.mock(ChannelConfig.class);
        expect(chconf.isAutoRead()).andReturn(false);

        Channel ch = unit.mock(Channel.class);
        expect(ch.config()).andReturn(chconf);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).pause();
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:22,代碼來源:NettyWebSocketTest.java

示例7: terminate

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void terminate() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class,
      BiConsumer.class)
          .expect(unit -> {
            BiConsumer<Integer, Optional<String>> callback = unit.get(BiConsumer.class);
            callback.accept(1006, Optional.of("Harsh disconnect"));

            ChannelFuture future = unit.mock(ChannelFuture.class);
            expect(future.addListener(CLOSE)).andReturn(future);

            ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
            expect(ctx.disconnect()).andReturn(future);
          })
          .run(unit -> {
            NettyWebSocket ws = new NettyWebSocket(
                unit.get(ChannelHandlerContext.class),
                unit.get(WebSocketServerHandshaker.class),
                unit.get(Consumer.class));
            ws.onCloseMessage(unit.get(BiConsumer.class));
            ws.terminate();
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:25,代碼來源:NettyWebSocketTest.java

示例8: isOpen

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void isOpen() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        Channel ch = unit.mock(Channel.class);
        expect(ch.isOpen()).andReturn(true);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        assertEquals(true, new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).isOpen());
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:19,代碼來源:NettyWebSocketTest.java

示例9: isNoOpen

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void isNoOpen() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        Channel ch = unit.mock(Channel.class);
        expect(ch.isOpen()).andReturn(false);

        ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
        expect(ctx.channel()).andReturn(ch);
      })
      .run(unit -> {
        assertEquals(false, new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class)).isOpen());
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:19,代碼來源:NettyWebSocketTest.java

示例10: connect

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void connect() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class,
      CountDownLatch.class, Runnable.class)
          .expect(unit -> {
            CountDownLatch ready = unit.mockConstructor(CountDownLatch.class,
                new Class[]{int.class }, 1);
            ready.countDown();

            unit.get(Runnable.class).run();
          })
          .run(unit -> {
            NettyWebSocket ws = new NettyWebSocket(
                unit.get(ChannelHandlerContext.class),
                unit.get(WebSocketServerHandshaker.class),
                unit.get(Consumer.class));
            ws.onConnect(unit.get(Runnable.class));
            ws.connect();
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:22,代碼來源:NettyWebSocketTest.java

示例11: hankshake

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void hankshake() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class,
      CountDownLatch.class, Consumer.class)
          .expect(unit -> {

            unit.get(Consumer.class).accept(isA(NettyWebSocket.class));
          })
          .run(unit -> {
            NettyWebSocket ws = new NettyWebSocket(
                unit.get(ChannelHandlerContext.class),
                unit.get(WebSocketServerHandshaker.class),
                unit.get(Consumer.class));
            ws.hankshake();
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:18,代碼來源:NettyWebSocketTest.java

示例12: handleTextFrame

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void handleTextFrame() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class,
      TextWebSocketFrame.class)
          .expect(unit -> {
            CountDownLatch ready = unit.mockConstructor(CountDownLatch.class,
                new Class[]{int.class }, 1);
            ready.await();

            TextWebSocketFrame frame = unit.get(TextWebSocketFrame.class);
            expect(frame.text()).andReturn("text");

            Consumer<String> callback = unit.get(Consumer.class);
            callback.accept("text");
          })
          .run(unit -> {
            NettyWebSocket ws = new NettyWebSocket(
                unit.get(ChannelHandlerContext.class),
                unit.get(WebSocketServerHandshaker.class),
                unit.get(Consumer.class));
            ws.onTextMessage(unit.get(Consumer.class));
            ws.handle(unit.get(TextWebSocketFrame.class));
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:26,代碼來源:NettyWebSocketTest.java

示例13: handleInterruped

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void handleInterruped() throws Exception {
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class,
      WebSocketFrame.class)
          .expect(unit -> {
            CountDownLatch ready = unit.mockConstructor(CountDownLatch.class,
                new Class[]{int.class }, 1);
            ready.await();
            expectLastCall().andThrow(new InterruptedException("intentional err"));

            Thread thread = unit.mock(Thread.class);
            thread.interrupt();

            unit.mockStatic(Thread.class);
            expect(Thread.currentThread()).andReturn(thread);
          })
          .run(unit -> {
            NettyWebSocket ws = new NettyWebSocket(
                unit.get(ChannelHandlerContext.class),
                unit.get(WebSocketServerHandshaker.class),
                unit.get(Consumer.class));
            ws.handle(unit.get(WebSocketFrame.class));
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:26,代碼來源:NettyWebSocketTest.java

示例14: handleException

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void handleException() throws Exception {
  Throwable cause = new NullPointerException("intentional err");
  new MockUnit(ChannelHandlerContext.class, WebSocketServerHandshaker.class, Consumer.class)
      .expect(unit -> {
        CountDownLatch ready = unit.mockConstructor(CountDownLatch.class,
            new Class[]{int.class }, 1);
        ready.await();

        Consumer<Throwable> callback = unit.get(Consumer.class);
        callback.accept(cause);
      })
      .run(unit -> {
        NettyWebSocket ws = new NettyWebSocket(
            unit.get(ChannelHandlerContext.class),
            unit.get(WebSocketServerHandshaker.class),
            unit.get(Consumer.class));
        ws.onErrorMessage(unit.get(Consumer.class));
        ws.handle(cause);
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:23,代碼來源:NettyWebSocketTest.java

示例15: handshake

import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; //導入依賴的package包/類
private void handshake(final ChannelHandlerContext ctx, final FullHttpRequest req, final String requestPath) {
  WebSocketServerHandshakerFactory wsFactory =
      new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true, maxWebSocketFrameSize);
  WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
  if (handshaker != null) {
    handshaker.handshake(ctx.channel(), req).addListener(
        new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future) throws Exception {
            final String sessionId = PipelineUtils.getSessionId(requestPath);
            if (future.isSuccess()) {
              ctx.channel().pipeline().addBefore(
                  SocketIOChannelInitializer.SOCKETIO_WEBSOCKET_HANDLER,
                  SocketIOChannelInitializer.WEBSOCKET_FRAME_AGGREGATOR,
                  new WebSocketFrameAggregator(maxWebSocketFrameSize));
              connect(ctx, req, sessionId);
            } else {
              log.error("Can't handshake: {}", sessionId, future.cause());
            }
          }
        });
  } else {
    WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
  }
}
 
開發者ID:scalecube,項目名稱:socketio,代碼行數:26,代碼來源:WebSocketHandler.java


注:本文中的io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。