本文整理了Java中io.vertx.ext.web.Route.produces
方法的一些代码示例,展示了Route.produces
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Route.produces
方法的具体详情如下:
包路径:io.vertx.ext.web.Route
类名称:Route
方法名:produces
[英]Add a content type produced by this route. Used for content based routing.
[中]添加此路由生成的内容类型。用于基于内容的路由。
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple7() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=1.0", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;a,application/json;q=1.0", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple6() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;a", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;a,application/json", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple8() throws Exception {
router.route().produces("application/json").produces("text/html").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=1.0", 200, "text/html");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;b,application/json;q=1.0", 200, "text/html");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;b,application/json;q=1.0;a", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesMultiple() throws Exception {
router.route().produces("text/html").produces("application/json").handler(rc -> rc.response().end());
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "application/json", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "something/html", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "application/blah", 404, "Not Found");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple4() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;a,application/json", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;a", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple9() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=0.8", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;d,application/json;q=0.8", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=0.8;s", 200, "text/plain");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple5() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;q=0.9", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;q=0.9;a", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;a;q=0.9", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;a,application/json;q=0.9", 200, "text/plain");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple3() throws Exception {
router.route().produces("application/json").produces("text/plain").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;a,text/plain", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain;a", 200, "text/plain");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;c,text/plain;a", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesWithParameter() throws Exception {
router.route().produces("text/html;boo=ya").handler(rc -> rc.response().end());
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProduces() throws Exception {
router.route().produces("text/html").handler(rc -> rc.response().end());
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "something/html", 404, "Not Found");
testRequest(HttpMethod.GET, "/foo", 200, "OK");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesAll2() throws Exception {
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "*", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesAll1() throws Exception {
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "*/*", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesTopLevelTypeWildcard() throws Exception {
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "*/json", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "*/html", 404, "Not Found");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesMissingSlash() throws Exception {
// will assume "*/json"
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "json", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text", 404, "Not Found");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesSubtypeWildcard() throws Exception {
router.route().produces("text/html").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/*", 200, "text/html");
testRequestWithAccepts(HttpMethod.GET, "/foo", "application/*", 404, "Not Found");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple1() throws Exception {
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;b,text/plain", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testProducesWithParameterKey() throws Exception {
router.route().produces("text/html;boo").handler(rc -> rc.response().end());
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo;itWorks", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 404, "Not Found");
testRequestWithAccepts(HttpMethod.GET, "/foo", "*/*", 200, "OK");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testAcceptsMultiple2() throws Exception {
router.route().produces("application/json").handler(rc -> {
rc.response().setStatusMessage(rc.getAcceptableContentType());
rc.response().end();
});
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/*,text/plain", 200, "application/json");
testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;a,application/*,text/plain", 200, "application/json");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testNoContent() {
testRoute.produces("application/json").handler(rc -> rc.response().end());
client.get(testRoute.getPath(), onSuccess(resp -> {
assertNull(contentType(resp));
assertEquals(Integer.valueOf(0), contentLength(resp));
testComplete();
})).putHeader(HttpHeaders.ACCEPT, "application/json").end();
await();
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testExistingHeader() {
testRoute.produces("application/json").handler(rc -> rc.response().putHeader(CONTENT_TYPE, "text/plain").end());
client.get(testRoute.getPath(), onSuccess(resp -> {
assertEquals("text/plain", contentType(resp));
testComplete();
})).putHeader(HttpHeaders.ACCEPT, "application/json").end();
await();
}
内容来源于网络,如有侵权,请联系作者删除!