本文整理汇总了Java中ratpack.handling.Context.byContent方法的典型用法代码示例。如果您正苦于以下问题:Java Context.byContent方法的具体用法?Java Context.byContent怎么用?Java Context.byContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ratpack.handling.Context
的用法示例。
在下文中一共展示了Context.byContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import ratpack.handling.Context; //导入方法依赖的package包/类
@Override
public void handle(Context ctx) throws Exception {
final RamlModelRepository ramlModelRepository = ctx.get(RamlModelRepository.class);
final Path filePath = ramlModelRepository.getFilePath();
final Path parent = ramlModelRepository.getParent();
final String path = ctx.getPathBinding().getPastBinding();
final Path resolvedFilePath = path.isEmpty() ? filePath : parent.resolve(path).normalize();
final File file = resolvedFilePath.toFile();
if (file.exists()) {
final String content;
if (QueryParams.resolveIncludes(ctx)) {
content = new IncludeResolver().preprocess(resolvedFilePath).toString();
} else {
content = Files.asByteSource(file).asCharSource(Charsets.UTF_8).read();
}
ctx.byContent(byContentSpec -> byContentSpec
.type("application/raml+yaml", () -> renderReplacedContent(ctx, content))
.html(() -> renderHtml(ctx, path, content))
.noMatch("application/raml+yaml"));
} else {
ctx.byContent(byContentSpec -> byContentSpec.noMatch(() -> ctx.render(ctx.file("api-raml/" + path))));
}
}
示例2: handle
import ratpack.handling.Context; //导入方法依赖的package包/类
@Override
public void handle(final Context ctx) throws Exception {
final RamlModelRepository ramlModelRepository = ctx.get(RamlModelRepository.class);
final Api api = ramlModelRepository.getApi();
final String path = ctx.getPathBinding().getPastBinding();
if (path.equals("Vrap-Extension.raml")) {
final Path filePath = ramlModelRepository.getFilePath();
List<ResourceExtension> resourceExtensions = resourceExtensions(api.resources(), "");
final Integer port = ctx.getServerConfig().getPort();
final String authProxyUri = "http://localhost:" + port.toString() + "/auth";
final String proxyUri = "http://localhost:" + port.toString() + "/" + apiUri + new URI(api.baseUri().value().replace("{", "%7B").replace("}", "%7D")).getPath().replace("%7B", "{").replace("%7D", "}");
List<SecurityScheme> oauthSchemes = api.securitySchemes().stream().filter(securityScheme -> securityScheme.type().equals("OAuth 2.0")).collect(Collectors.toList());
final ImmutableMap<String, Object> model =
ImmutableMap.<String, Object>builder()
.put("fileName", filePath.getFileName())
.put("queryParams", ctx.getRequest().getQuery())
.put("resourceExtensions", resourceExtensions)
.put("proxyUri", proxyUri)
.put("modes", Joiner.on(", ").join(VrapMode.values()))
.put("flags", Joiner.on(", ").join(ValidationFlag.values()))
.put("authProxyUri", authProxyUri)
.put("oauthSchemes", oauthSchemes.stream().map(securityScheme -> securityScheme.name()).collect(Collectors.toList()))
.build();
ctx.byContent(byContentSpec -> byContentSpec
.type("application/raml+yaml", () -> ctx.render(handlebarsTemplate(model, "api-raml/Vrap-Extension.raml")))
.html(() -> ctx.render(handlebarsTemplate(model, "api-raml/Vrap-Extension.html")))
.noMatch("application/raml+yaml"));
} else {
ctx.next();
}
}
示例3: handle
import ratpack.handling.Context; //导入方法依赖的package包/类
@Override
public void handle(final Context ctx) throws Exception {
final Method method = ctx.get(Method.class);
final List<TypeDeclaration> bodTypeDeclarations = method.responses().stream()
.flatMap(r -> r.body().stream()).collect(Collectors.toList());
final Map<String, ExampleSpec> contentTypeToExample = bodTypeDeclarations.stream()
.collect(Collectors.toMap(TypeDeclaration::name, TypeDeclaration::example));
ctx.byContent(byContentSpec ->
contentTypeToExample.entrySet().stream()
.forEach(e -> byContentSpec.type(e.getKey(), () -> ctx.render(e.getValue().value()))));
}
示例4: render
import ratpack.handling.Context; //导入方法依赖的package包/类
@Override
public void render(Context context, Book book) throws Exception {
context.byContent(byContentSpec -> byContentSpec
.json(() ->
context.render(Jackson.json(book))
)
.xml(() -> {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.configure(WRITE_XML_DECLARATION, true);
context.render(xmlMapper.writeValueAsString(book));
})
);
}