io.vertx.core.MultiMap.get()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中io.vertx.core.MultiMap.get()方法的一些代码示例,展示了MultiMap.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultiMap.get()方法的具体详情如下:
包路径:io.vertx.core.MultiMap
类名称:MultiMap
方法名:get

MultiMap.get介绍

[英]Returns the value of with the specified name. If there are more than one values for the specified name, the first value is returned.
[中]返回具有指定名称的的值。如果指定名称有多个值,则返回第一个值。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testGetTest1()
  throws Exception {
 MultiMap mmap = newMultiMap();
 CharSequence name = String.valueOf(new Object());
 assertNull(mmap.get(name));
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
 public void testGetShouldReturnEntriesFromListInOrder() {
  MultiMap mmap = newMultiMap();
  mmap.add("header", Arrays.<CharSequence>asList("value1", "value2", "value3"));
  assertEquals("value1", mmap.get("header"));
  assertEquals(Arrays.asList("value1", "value2", "value3"), mmap.getAll("header"));
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
public void start() throws Exception {
 vertx.createHttpServer().requestHandler(req -> {
  System.out.println("Got request " + req.uri());
  for (String name : req.headers().names()) {
   System.out.println(name + ": " + req.headers().get(name));
  }
  req.handler(data -> System.out.println("Got data " + data.toString("ISO-8859-1")));
  req.endHandler(v -> {
   // Now send back a response
   req.response().setChunked(true);
   for (int i = 0; i < 10; i++) {
    req.response().write("server-data-chunk-" + i);
   }
   req.response().end();
  });
 }).listen(8282);
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testClientMultiThreaded() throws Exception {
 int numThreads = 10;
 Thread[] threads = new Thread[numThreads];
 CountDownLatch latch = new CountDownLatch(numThreads);
 server.requestHandler(req -> {
  req.response().putHeader("count", req.headers().get("count"));
  req.response().end();
 }).listen(ar -> {
  assertTrue(ar.succeeded());
  for (int i = 0; i < numThreads; i++) {
   int index = i;
   threads[i] = new Thread() {
    public void run() {
     client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(res -> {
      assertEquals(200, res.statusCode());
      assertEquals(String.valueOf(index), res.headers().get("count"));
      latch.countDown();
     })).putHeader("count", String.valueOf(index)).end();
    }
   };
   threads[i].start();
  }
 });
 awaitLatch(latch);
 for (int i = 0; i < numThreads; i++) {
  threads[i].join();
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testHeadHasNoContentLengthByDefault() {
 server.requestHandler(req -> {
  assertEquals(HttpMethod.HEAD, req.method());
  // By default HEAD does not have a content-length header
  req.response().end();
 });
 server.listen(onSuccess(s -> {
  client.request(HttpMethod.HEAD, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
   assertNull(resp.headers().get(HttpHeaders.CONTENT_LENGTH));
   resp.endHandler(v -> testComplete());
  })).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testSendFileOverrideHeaders() throws Exception {
 String content = TestUtils.randomUnicodeString(10000);
 File file = setupFile("test-send-file.html", content);
 server.requestHandler(req -> {
  req.response().putHeader("Content-Type", "wibble");
  req.response().sendFile(file.getAbsolutePath());
 });
 server.listen(onSuccess(s -> {
  client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
   assertEquals(file.length(), Long.parseLong(resp.headers().get("content-length")));
   assertEquals("wibble", resp.headers().get("content-type"));
   resp.bodyHandler(buff -> {
    assertEquals(content, buff.toString());
    file.delete();
    testComplete();
   });
  })).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

private void testResponseHeaders(boolean individually) {
 MultiMap headers = getHeaders(10);
 server.requestHandler(req -> {
  if (individually) {
   for (Map.Entry<String, String> header : headers) {
    req.response().headers().add(header.getKey(), header.getValue());
   }
  } else {
   req.response().headers().setAll(headers);
  }
  req.response().end();
 });
 server.listen(onSuccess(server -> {
  client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
   assertTrue(headers.size() < resp.headers().size());
   for (Map.Entry<String, String> entry : headers) {
    assertEquals(entry.getValue(), resp.headers().get(entry.getKey()));
    assertEquals(entry.getValue(), resp.getHeader(entry.getKey()));
   }
   testComplete();
  })).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

private void sendFile(String fileName, String contentExpected, boolean useHandler, Function<Handler<AsyncResult<HttpClientResponse>>, HttpClientRequest> requestFact) throws Exception {
 waitFor(2);
 File fileToSend = setupFile(fileName, contentExpected);
 server.requestHandler(req -> {
  if (useHandler) {
   Handler<AsyncResult<Void>> completionHandler = onSuccess(v -> complete());
   req.response().sendFile(fileToSend.getAbsolutePath(), completionHandler);
  } else {
   req.response().sendFile(fileToSend.getAbsolutePath());
   complete();
  }
 });
 startServer();
 requestFact.apply(onSuccess(resp -> {
  assertEquals(200, resp.statusCode());
  assertEquals("text/html", resp.headers().get("Content-Type"));
  resp.exceptionHandler(this::fail);
  resp.bodyHandler(buff -> {
   assertEquals(contentExpected, buff.toString());
   assertEquals(fileToSend.length(), Long.parseLong(resp.headers().get("content-length")));
   complete();
  });
 })).end();
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testFollowRedirectEncodedParams() throws Exception {
 String value1 = "\ud55c\uae00", value2 = "A B+C", value3 = "123 \u20ac";
     .setStatusCode(302)
     .putHeader("location", location.toString())
     .end();
    break;
   case "/redirected/from/client":
    assertEquals(value1, req.params().get("encoded1"));
    assertEquals(value2, req.params().get("encoded2"));
    assertEquals(value3, req.params().get("encoded3"));
    req.response().end();
    break;
   default:

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testGetConvertUpperCase() {
 map.set("foo", "foo_value");
 assertEquals("foo_value", map.get("Foo"));
 assertEquals("foo_value", map.get((CharSequence) "Foo"));
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testResponseHeadersWithCharSequence() {
 HashMap<CharSequence, String> headers = new HashMap<>();
 headers.put(HttpHeaders.TEXT_HTML, "text/html");
 headers.put(HttpHeaders.USER_AGENT, "User-Agent");
 headers.put(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded");
 server.requestHandler(req -> {
  headers.forEach((k, v) -> req.response().headers().add(k, v));
  req.response().end();
 });
 server.listen(onSuccess(server -> {
  client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
   assertTrue(headers.size() < resp.headers().size());
   headers.forEach((k,v) -> assertEquals(v, resp.headers().get(k)));
   headers.forEach((k,v) -> assertEquals(v, resp.getHeader(k)));
   testComplete();
  })).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testResponseEndHandlersSendFile() throws Exception {
 waitFor(2);
 AtomicInteger cnt = new AtomicInteger();
 String content = "iqdioqwdqwiojqwijdwqd";
 File toSend = setupFile("somefile.txt", content);
 server.requestHandler(req -> {
  req.response().headersEndHandler(v -> {
   // Insert another header
   req.response().putHeader("extraheader", "wibble");
   assertEquals(0, cnt.getAndIncrement());
  });
  req.response().bodyEndHandler(v -> {
   assertEquals(content.length(), req.response().bytesWritten());
   assertEquals(1, cnt.getAndIncrement());
   complete();
  });
  req.response().sendFile(toSend.getAbsolutePath());
 }).listen(onSuccess(server -> {
  client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(res -> {
   assertEquals(200, res.statusCode());
   assertEquals("wibble", res.headers().get("extraheader"));
   res.bodyHandler(buff -> {
    assertEquals(Buffer.buffer(content), buff);
    complete();
   });
  })).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testGetShouldReturnAddedEntriesInOrder() {
 MultiMap mmap = newMultiMap();
 mmap.add("header", "value1");
 mmap.add("header", "value2");
 mmap.add("header", "value3");
 assertEquals("value1", mmap.get("header"));
 assertEquals(Arrays.asList("value1", "value2", "value3"), mmap.getAll("header"));
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {
  vertx.createHttpServer().requestHandler(req -> {
   if (req.uri().equals("/")) {
    // Serve the index page
    req.response().sendFile("index.html");
   } else if (req.uri().startsWith("/form")) {
    req.response().setChunked(true);
    req.setExpectMultipart(true);
    req.endHandler((v) -> {
     for (String attr : req.formAttributes().names()) {
      req.response().write("Got attr " + attr + " : " + req.formAttributes().get(attr) + "\n");
     }
     req.response().end();
    });
   } else {
    req.response().setStatusCode(404).end();
   }
  }).listen(8080);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

String cnt = req.headers().get("count");
 req.response().headers().set("count", cnt);
 req.response().end();
});
  HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, path, onSuccess(resp -> {
   assertEquals(200, resp.statusCode());
   assertEquals(theCount, Integer.parseInt(resp.headers().get("count")));
   if (cnt.incrementAndGet() == numGets) {
    testComplete();

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testDefaultRequestHeaders() {
 server.requestHandler(req -> {
  if (req.version() == HttpVersion.HTTP_1_1) {
   assertEquals(1, req.headers().size());
   assertEquals("localhost:" + DEFAULT_HTTP_PORT, req.headers().get("host"));
  } else {
   assertEquals(4, req.headers().size());
   assertEquals("https", req.headers().get(":scheme"));
   assertEquals("GET", req.headers().get(":method"));
   assertEquals("some-uri", req.headers().get(":path"));
   assertEquals("localhost:" + DEFAULT_HTTP_PORT, req.headers().get(":authority"));
  }
  req.response().end();
 });
 server.listen(onSuccess(server -> {
  client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete()).end();
 }));
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testGetTest2()
  throws Exception {
 MultiMap mmap = newMultiMap();
 String name = "1";
 assertNull(mmap.get(name));
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testHeadButCanSetContentLength() {
 server.requestHandler(req -> {
  assertEquals(HttpMethod.HEAD, req.method());
  // By default HEAD does not have a content-length header but it can contain a content-length header
  // if explicitly set
  req.response().putHeader(HttpHeaders.CONTENT_LENGTH, "41").end();
 });
 server.listen(onSuccess(s -> {
  client.request(HttpMethod.HEAD, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
   assertEquals("41", resp.headers().get(HttpHeaders.CONTENT_LENGTH));
   resp.endHandler(v -> testComplete());
  })).end();
 }));
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testLastModifiedInGMT() throws Exception {
 testRequest(HttpMethod.GET, "/otherpage.html", null, res -> {
  String lastModified = res.headers().get("last-modified");
  assertTrue(lastModified.endsWith("GMT"));
 }, 200, "OK", "<html><body>Other page</body></html>");
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
public void start() throws Exception {
 SelfSignedCertificate certificate = SelfSignedCertificate.create();
 HttpServerOptions serverOptions = new HttpServerOptions()
  .setSsl(true)
  .setKeyCertOptions(certificate.keyCertOptions());
 vertx.createHttpServer(serverOptions).requestHandler(req -> {
  System.out.println("Got request " + req.uri());
  for (String name : req.headers().names()) {
   System.out.println(name + ": " + req.headers().get(name));
  }
  req.handler(data -> System.out.println("Got data " + data.toString("ISO-8859-1")));
  req.endHandler(v -> {
   // Now send back a response
   req.response().setChunked(true);
   for (int i = 0; i < 10; i++) {
    req.response().write("server-data-chunk-" + i);
   }
   req.response().end();
  });
 }).listen(8282);
}

相关文章