本文整理汇总了Java中org.takes.facets.fallback.Fallback类的典型用法代码示例。如果您正苦于以下问题:Java Fallback类的具体用法?Java Fallback怎么用?Java Fallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Fallback类属于org.takes.facets.fallback包,在下文中一共展示了Fallback类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: FbError
点赞 3
import org.takes.facets.fallback.Fallback; //导入依赖的package包/类
/**
* Ctor.
*/
public FbError() {
super(
new Fallback() {
@Override
public Opt<Response> route(final RqFallback req) {
final String exc = ExceptionUtils.getStackTrace(
req.throwable()
);
return new Opt.Single<Response>(
new RsWithStatus(
new RsText(
String.format(
"oops, something went wrong!\n%s",
exc
)
),
req.code()
)
);
}
}
);
}
开发者ID:libreio,
项目名称:libre,
代码行数:27,
代码来源:FbError.java
示例2: safe
点赞 2
import org.takes.facets.fallback.Fallback; //导入依赖的package包/类
/**
* With fallback.
* @param take Takes
* @return Safe takes
*/
private static Take safe(final Take take) {
return new TkFallback(
take,
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
(Fallback) req -> new Opt.Single<>(
new RsWithStatus(
new RsText(req.throwable().getLocalizedMessage()),
HttpURLConnection.HTTP_NOT_FOUND
)
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
(Fallback) req -> new Opt.Single<>(
new RsWithStatus(
new RsText(req.throwable().getLocalizedMessage()),
HttpURLConnection.HTTP_BAD_REQUEST
)
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Empty<>();
},
req -> new Opt.Single<>(TkApp.fatal(req))
)
);
}
开发者ID:yegor256,
项目名称:threecopies,
代码行数:36,
代码来源:TkApp.java
示例3: make
点赞 2
import org.takes.facets.fallback.Fallback; //导入依赖的package包/类
/**
* Ctor.
* @param home Home directory
* @return The take
* @throws IOException If fails
*/
private static Take make(final Path home) throws IOException {
final Futures futures = new Futures(new Reports(home));
return new TkFallback(
new TkForward(
new TkFork(
new FkRegex("/", new TkIndex()),
new FkRegex("/robots.txt", new TkText("")),
new FkRegex("/mistakes", new TkMistakes()),
new FkRegex(
"/flush",
(Take) req -> new RsText(
String.format("%d flushed", new Results().flush())
)
),
new FkRegex("/all", new TkAll()),
new FkRegex("/queue", new TkQueue(futures)),
new FkRegex(
".+\\.xsl",
new TkWithType(
new TkClasspath(),
"text/xsl"
)
),
new FkRegex(
"/jpeek\\.css",
new TkWithType(
new TkText(
new TextOf(
new ResourceOf("org/jpeek/jpeek.css")
).asString()
),
"text/css"
)
),
new FkRegex(
"/([^/]+)/([^/]+)(.*)",
new TkReport(
new AsyncReports(
// @checkstyle MagicNumber (1 line)
new SolidBiFunc<>(futures, 100)
)
)
)
)
),
new FbChain(
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
(Fallback) req -> new Opt.Single<>(
new RsWithStatus(
new RsText(req.throwable().getMessage()),
req.code()
)
)
),
req -> {
Sentry.capture(req.throwable());
return new Opt.Single<>(
new RsWithStatus(
new RsText(
new TextOf(req.throwable()).asString()
),
HttpURLConnection.HTTP_INTERNAL_ERROR
)
);
}
)
);
}
开发者ID:yegor256,
项目名称:jpeek,
代码行数:76,
代码来源:TkApp.java