org.takes.facets.fallback.TkFallback Java Examples
The following examples show how to use
org.takes.facets.fallback.TkFallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TakesApp.java From tutorials with MIT License | 6 votes |
public static void main(final String... args) throws IOException, SQLException { new FtBasic( new TkFallback( new TkFork( new FkRegex("/", new TakesHelloWorld()), new FkRegex("/index", new TakesIndex()), new FkRegex("/contact", new TakesContact()) ), new FbChain( new FbStatus(404, new RsText("Page Not Found")), new FbStatus(405, new RsText("Method Not Allowed")), new Fallback() { @Override public Opt<Response> route(final RqFallback req) { return new Opt.Single<Response>(new RsText(req.throwable().getMessage())); } }) ), 6060 ).start(Exit.NEVER); }
Example #2
Source File: TkAppFallback.java From jare with MIT License | 5 votes |
/** * Authenticated. * @param take Takes * @return Authenticated takes */ private static Take make(final Take take) { return new TkFallback( take, new FbChain( new FbStatus( HttpURLConnection.HTTP_NOT_FOUND, new RsWithStatus( new RsText("Page not found"), HttpURLConnection.HTTP_NOT_FOUND ) ), new FbStatus( HttpURLConnection.HTTP_BAD_REQUEST, new RsWithStatus( new RsText("Bad request"), HttpURLConnection.HTTP_BAD_REQUEST ) ), req -> { Sentry.capture(req.throwable()); return new Opt.Empty<>(); }, req -> new Opt.Single<>(TkAppFallback.fatal(req)) ) ); }
Example #3
Source File: TkApp.java From jpeek with MIT License | 4 votes |
/** * 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) ); final BiFunc<String, String, Func<String, Response>> reports = new AsyncReports( // @checkstyle MagicNumber (1 line) new StickyFutures(futures, 100) ); return new TkSslOnly( 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( "/upload", (Take) req -> new RsPage(req, "upload") ), new FkRegex("/do-upload", new TkUpload(reports)), 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(reports, new Results()) ) ) ), 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 ) ); } ) ) ); }