org.takes.rs.RsWithType Java Examples
The following examples show how to use
org.takes.rs.RsWithType.
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: TkAppFallback.java From jare with MIT License | 6 votes |
/** * Make fatal error page. * @param req Request * @return Response * @throws IOException If fails */ private static Response fatal(final RqFallback req) throws IOException { return new RsWithStatus( new RsWithType( new RsVelocity( TkAppFallback.class.getResource("error.html.vm"), new RsVelocity.Pair( "err", ExceptionUtils.getStackTrace(req.throwable()) ), new RsVelocity.Pair("rev", TkAppFallback.REV) ), "text/html" ), HttpURLConnection.HTTP_INTERNAL_ERROR ); }
Example #2
Source File: FbStatus.java From takes with MIT License | 6 votes |
/** * Ctor. * @param check HTTP status code predicate * @since 0.16.10 */ public FbStatus(final Iterable<Integer> check) { this(check, new Fallback() { @Override public Opt<Response> route(final RqFallback req) throws Exception { final Response res = new RsWithStatus(req.code()); return new Opt.Single<>( new RsWithType( new RsWithBody( res, String.format( "%s: %s", FbStatus.WHITESPACE.split( res.head().iterator().next(), 2 )[1], req.throwable().getLocalizedMessage() ) ), "text/plain" ) ); } }); }
Example #3
Source File: PsByFlagTest.java From takes with MIT License | 6 votes |
/** * PsByFlag wraps response with authenticated user. * @throws IOException If some problem inside */ @Test public void exitTest() throws IOException { final Response response = new RsWithStatus( new RsWithType( new RsWithBody("<html>This is test response</html>"), "text/html" ), HttpURLConnection.HTTP_OK ); MatcherAssert.assertThat( new PsByFlag( ImmutableMap.<Pattern, Pass>of( Pattern.compile("key"), new PsFake(true) ) ).exit(response, Mockito.mock(Identity.class)), Matchers.is(response) ); }
Example #4
Source File: TypedPages.java From jpeek with MIT License | 5 votes |
@Override public Response apply(final String path) throws IOException { String type = "text/plain"; if (path.endsWith(".html")) { type = "text/html"; } else if (path.endsWith(".xml")) { type = "application/xml"; } else if (path.endsWith(".svg")) { type = "image/svg+xml"; } return new RsWithType( new IoCheckedFunc<>(this.origin).apply(path), type ); }
Example #5
Source File: RsPage.java From jpeek with MIT License | 5 votes |
/** * Make it. * @param req Request * @param xsl XSL stylesheet * @param src Sources * @return Response */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") private static Response make(final Request req, final String xsl, final Scalar<Iterable<XeSource>> src) { final Response raw = new RsXembly( new XeChain( new XeStylesheet( String.format("/org/jpeek/web/%s.xsl", xsl) ), new XeAppend( "page", new XeChain( new XeMillis(), new XeDirectives(new Header()), new XeChain(src), new XeMillis(true) ) ) ) ); return new RsFork( req, new FkTypes( "text/html", new RsXslt(new RsWithType(raw, "text/html")) ), new FkTypes( "application/vnd.jpeek+xml", new RsPrettyXml(new RsWithType(raw, "text/xml")) ), new FkTypes("*/*", raw) ); }
Example #6
Source File: TkWithType.java From takes with MIT License | 5 votes |
/** * Ctor. * @param take Original take * @param type Content type */ public TkWithType(final Take take, final String type) { super( new Take() { @Override public Response act(final Request req) throws Exception { return new RsWithType(take.act(req), type); } } ); }
Example #7
Source File: RsXembly.java From takes with MIT License | 5 votes |
/** * Ctor. * @param dom DOM node to build upon * @param src Source */ public RsXembly(final Node dom, final XeSource src) { super( new ResponseOf( () -> new RsWithType( new RsWithStatus( new RsEmpty(), HttpURLConnection.HTTP_OK ), "text/xml" ).head(), () -> RsXembly.render(dom, src) ) ); }
Example #8
Source File: TakesContact.java From tutorials with MIT License | 5 votes |
@Override public Response act(Request req) throws IOException { return new RsWithStatus( new RsWithType( new RsWithBody("Contact us at https://www.baeldung.com"), "text/html"), 200); }
Example #9
Source File: RsPage.java From jare with MIT License | 4 votes |
/** * Make it. * @param xsl XSL * @param req Request * @param src Source * @return Response * @throws IOException If fails */ private static Response make(final String xsl, final Request req, final Iterable<XeSource> src) throws IOException { final Response raw = new RsXembly( new XeStylesheet(xsl), new XeAppend( "page", new XeMillis(false), new XeChain(src), new XeLinkHome(req), new XeLinkSelf(req), new XeMillis(true), new XeDate(), new XeSla(), new XeLocalhost(), new XeFlash(req), new XeWhen( new RqAuth(req).identity().equals(Identity.ANONYMOUS), new XeChain( new XeGithubLink(req, Manifests.read("Jare-GithubId")) ) ), new XeWhen( !new RqAuth(req).identity().equals(Identity.ANONYMOUS), new XeChain( new XeIdentity(req), new XeLogoutLink(req), new XeLink("domains", "/domains") ) ), new XeAppend( "version", new XeAppend("name", Manifests.read("Jare-Version")), new XeAppend("revision", Manifests.read("Jare-Revision")), new XeAppend("date", Manifests.read("Jare-Date")), new XeAppend("heroku", RsPage.heroku()) ) ) ); return new RsFork( req, new FkTypes( "application/xml,text/xml", new RsPrettyXml(new RsWithType(raw, "text/xml")) ), new FkTypes( "*/*", new RsXslt(new RsWithType(raw, "text/html")) ) ); }