コード例 #1
0
  private void testContinuationWriteFromConnectHandler(WebsocketVersion version) throws Exception {
    String path = "/some/path";
    String firstFrame = "AAA";
    String continuationFrame = "BBB";

    server =
        vertx
            .createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT))
            .requestHandler(
                req -> {
                  NetSocket sock = getUpgradedNetSocket(req, path);

                  // Let's write a Text frame raw
                  Buffer buff = Buffer.buffer();
                  buff.appendByte((byte) 0x01); // Incomplete Text frame
                  buff.appendByte((byte) firstFrame.length());
                  buff.appendString(firstFrame);
                  sock.write(buff);

                  buff = Buffer.buffer();
                  buff.appendByte((byte) (0x00 | 0x80)); // Complete continuation frame
                  buff.appendByte((byte) continuationFrame.length());
                  buff.appendString(continuationFrame);
                  sock.write(buff);
                });

    server.listen(
        ar -> {
          assertTrue(ar.succeeded());
          client.connectWebsocket(
              HttpTestBase.DEFAULT_HTTP_PORT,
              HttpTestBase.DEFAULT_HTTP_HOST,
              path,
              null,
              version,
              ws -> {
                AtomicBoolean receivedFirstFrame = new AtomicBoolean();
                ws.frameHandler(
                    received -> {
                      Buffer receivedBuffer = Buffer.buffer(received.textData());
                      if (!received.isFinal()) {
                        assertEquals(firstFrame, receivedBuffer.toString());
                        receivedFirstFrame.set(true);
                      } else if (receivedFirstFrame.get() && received.isFinal()) {
                        assertEquals(continuationFrame, receivedBuffer.toString());
                        ws.close();
                        testComplete();
                      }
                    });
              });
        });
    await();
  }
コード例 #2
0
 @Test
 public void testFileSystemReadFile() {
   assertTrue(vertx.fileSystem().existsBlocking("afile.html"));
   assertFalse(vertx.fileSystem().propsBlocking("afile.html").isDirectory());
   Buffer buffer = vertx.fileSystem().readFileBlocking("afile.html");
   assertNotNull(buffer);
   assertTrue(buffer.toString().startsWith("<html><body>afile</body></html>"));
 }
コード例 #3
0
  private void writeToTarget(String sendPacket, String cmd) {
    logger.debug(name_log + "writeToDCU(), Command: " + cmd);

    // Writing Data to The Socket
    Buffer outBuffer = Buffer.buffer();
    outBuffer.setString(0, sendPacket);
    logger.info(name_log + "SEND[" + outBuffer.length() + "]> \n" + outBuffer.toString() + "\n");

    netSocket.write(outBuffer);
  }