• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RsText类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.takes.rs.RsText的典型用法代码示例。如果您正苦于以下问题:Java RsText类的具体用法?Java RsText怎么用?Java RsText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RsText类属于org.takes.rs包,在下文中一共展示了RsText类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: make

import org.takes.rs.RsText; //导入依赖的package包/类
private static Take make(final Take take) {
    return new TkFallback(
            take,
            new FbChain(
                    new FbStatus(
                            HttpURLConnection.HTTP_NOT_FOUND,
                            new RsWithStatus(
                                    new RsText("endpoint with this path not found"),
                                    HttpURLConnection.HTTP_NOT_FOUND
                            )
                    ),
                    new FbStatus(
                            HttpURLConnection.HTTP_BAD_REQUEST,
                            new RsWithStatus(
                                    new RsText("bad request"),
                                    HttpURLConnection.HTTP_BAD_REQUEST
                            )
                    ),
                    req -> new Opt.Empty<>(),
                    req -> new Opt.Single<>(fatal(req))
            )
    );
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:24,代码来源:TkAppFallback.java


示例2: act

import org.takes.rs.RsText; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final Identity identity = new RqAuth(request).identity();
    if (identity.equals(Identity.ANONYMOUS)) {
        throw new RsForward(
            new RsFlash("You must be logged in to view logs.")
        );
    }
    final String login = identity.properties().get("login");
    final String name = new RqHref.Smart(request).single("name");
    if (!name.startsWith(String.format("%s_", login))) {
        throw new RsForward(
            new RsFlash(
                String.format(
                    "Permission denied: \"%s\".", name
                )
            )
        );
    }
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    this.bucket.ocket(name).read(baos);
    return new RsText(baos.toByteArray());
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:24,代码来源:TkLog.java


示例3: rendersOneReport

import org.takes.rs.RsText; //导入依赖的package包/类
@Test
public void rendersOneReport() throws Exception {
    final ExecutorService service = Executors.newSingleThreadExecutor();
    final BiFunc<String, String, Func<String, Response>> bifunc =
        new AsyncReports(
            new SolidBiFunc<>(
                (first, second) -> service.submit(
                    () -> input -> {
                        TimeUnit.DAYS.sleep(1L);
                        return new RsText("done!");
                    }
                )
            )
        );
    final Response response =
        bifunc.apply("org.jpeek", "jpeek").apply("index.html");
    MatcherAssert.assertThat(
        response,
        new HmRsStatus(HttpURLConnection.HTTP_OK)
    );
    MatcherAssert.assertThat(
        XhtmlMatchers.xhtml(new RsPrint(response).printBody()),
        XhtmlMatchers.hasXPath("//xhtml:body")
    );
    service.shutdownNow();
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:27,代码来源:AsyncReportsTest.java


示例4: negotiatesContent

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * RsFork can route by the Accept header.
 * @throws IOException If some problem inside
 */
@Test
public void negotiatesContent() throws IOException {
    final Request req = new RqFake(
        Arrays.asList(
            "GET /hello.html",
            "Accept: text/xml; q=0.3, text/plain; q=0.1",
            "Accept: */*; q=0.05"
        ),
        ""
    );
    MatcherAssert.assertThat(
        new RsPrint(
            new RsFork(
                req,
                new FkTypes("text/plain", new RsText("it's a text")),
                new FkTypes("image/*", new RsText("it's an image"))
            )
        ).printBody(),
        Matchers.endsWith("a text")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:RsForkTest.java


示例5: negotiatesContentWithComplexHeader

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * RsFork can route by the Accept header.
 * @throws IOException If some problem inside
 */
@Test
public void negotiatesContentWithComplexHeader() throws IOException {
    final Request req = new RqFake(
        Arrays.asList(
            "GET /hell-1o.html",
            "Accept: text/xml"
        ),
        ""
    );
    MatcherAssert.assertThat(
        new RsPrint(
            new RsFork(
                req,
                new FkTypes(
                    "application/xml,text/xml",
                    new RsText("how are you?")
                )
            )
        ).printBody(),
        Matchers.endsWith("you?")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:RsForkTest.java


示例6: logsUserIn

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkAuth can login a user.
 * @throws IOException If some problem inside
 */
@Test
public void logsUserIn() throws IOException {
    final Pass pass = new PsFixed(new Identity.Simple("urn:test:1"));
    final Take take = Mockito.mock(Take.class);
    Mockito.doReturn(new RsText()).when(take)
        .act(Mockito.any(Request.class));
    new TkAuth(take, pass).act(new RqFake());
    final ArgumentCaptor<Request> captor =
        ArgumentCaptor.forClass(Request.class);
    Mockito.verify(take).act(captor.capture());
    MatcherAssert.assertThat(
        new RqHeaders.Base(captor.getValue()).header(
            TkAuth.class.getSimpleName()
        ),
        Matchers.hasItem("urn%3Atest%3A1")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:22,代码来源:TkAuthTest.java


示例7: logsUserOut

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkAuth can logout a user.
 * @throws IOException If some problem inside
 */
@Test
public void logsUserOut() throws IOException {
    final Pass pass = new PsLogout();
    final Take take = Mockito.mock(Take.class);
    Mockito.doReturn(new RsText()).when(take)
        .act(Mockito.any(Request.class));
    new TkAuth(take, pass).act(
        new RqWithHeader(
            new RqFake(),
            TkAuth.class.getSimpleName(),
            "urn%3Atest%3A2"
        )
    );
    final ArgumentCaptor<Request> captor =
        ArgumentCaptor.forClass(Request.class);
    Mockito.verify(take).act(captor.capture());
    MatcherAssert.assertThat(
        new RqHeaders.Base(captor.getValue()).header(
            TkAuth.class.getSimpleName()
        ),
        Matchers.emptyIterable()
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:28,代码来源:TkAuthTest.java


示例8: reactsToCondition

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * FbStatus can react to Condition.
 * @throws Exception If some problem inside
 */
@Test
public void reactsToCondition() throws Exception {
    final RqFallback req = new RqFallback.Fake(
        HttpURLConnection.HTTP_MOVED_PERM
    );
    MatcherAssert.assertThat(
        new RsPrint(
            new FbStatus(
                new Condition<Integer>() {
                    @Override
                    public boolean fits(final Integer status) {
                        return status == HttpURLConnection.HTTP_MOVED_PERM
                            || status == HttpURLConnection.HTTP_MOVED_TEMP;
                    };
                },
                new FbFixed(new RsText("response text"))
            ).route(req).get()
        ).printBody(),
        Matchers.startsWith("response")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:FbStatusTest.java


示例9: chainsFallbacks

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * FbChain can chain fallbacks.
 * @throws IOException If some problem inside
 */
@Test
public void chainsFallbacks() throws IOException {
    final RqFallback req = new RqFallback.Fake(
        HttpURLConnection.HTTP_NOT_FOUND
    );
    MatcherAssert.assertThat(
        new RsPrint(
            new FbChain(
                new FbEmpty(),
                new FbFixed(new RsText("first rs")),
                new FbFixed(new RsText("second rs"))
            ).route(req).get()
        ).printBody(),
        Matchers.startsWith("first")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:21,代码来源:FbChainTest.java


示例10: fallsBack

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkFallback can fall back.
 * @throws IOException If some problem inside
 */
@Test
public void fallsBack() throws IOException {
    final String err = "message";
    MatcherAssert.assertThat(
        new RsPrint(
            new TkFallback(
                new TkFailure(err),
                new Fallback() {
                    @Override
                    public Opt<Response> route(final RqFallback req) {
                        return new Opt.Single<Response>(
                            new RsText(req.throwable().getMessage())
                        );
                    }
                }
            ).act(new RqFake())
        ).printBody(),
        Matchers.endsWith(err)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:25,代码来源:TkFallbackTest.java


示例11: simplyWorks

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * FtRemote can work.
 * @throws Exception If some problem inside
 */
@Test
public void simplyWorks() throws Exception {
    new FtRemote(new TkFixed(new RsText("simple answer"))).exec(
        new FtRemote.Script() {
            @Override
            public void exec(final URI home) throws IOException {
                new JdkRequest(home)
                    .fetch()
                    .as(RestResponse.class)
                    .assertStatus(HttpURLConnection.HTTP_OK)
                    .assertBody(Matchers.startsWith("simple"));
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:FtRemoteTest.java


示例12: retriesOnExceptionTillSuccess

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkRetry can retry when initial take fails with IOException,
 * till get successful result.
 *
 * @throws Exception if something is wrong
 */
@Test
public void retriesOnExceptionTillSuccess() throws Exception {
    final int count = Tv.THREE;
    final int delay = Tv.THOUSAND;
    final String data = "data";
    final Take take = Mockito.mock(Take.class);
    Mockito
        .when(take.act(Mockito.any(Request.class)))
        .thenThrow(new IOException())
        .thenReturn(new RsText(data));
    final long start = System.nanoTime();
    final RsPrint response = new RsPrint(
        new TkRetry(count, delay, take).act(new RqFake(RqMethod.GET))
    );
    final long spent = System.nanoTime() - start;
    MatcherAssert.assertThat(
        new Long(delay - Tv.HUNDRED) * Tv.MILLION,
        Matchers.lessThanOrEqualTo(spent)
    );
    MatcherAssert.assertThat(
        response.print(),
        Matchers.containsString(data)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:31,代码来源:TkRetryTest.java


示例13: handleConnectionsWithCorrectDomainOnOrigin

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkCORS can handle connections with correct domain on origin.
 * @throws Exception If some problem inside
 */
@Test
public void handleConnectionsWithCorrectDomainOnOrigin() throws Exception {
    MatcherAssert.assertThat(
        "Invalid HTTP status for a request with correct domain.",
        new TkCors(
            new TkFixed(new RsText()),
            "http://teamed.io",
            "http://example.com"
        ).act(
            new RqWithHeaders(
                new RqFake(),
                "Origin: http://teamed.io"
            )
        ),
        new HmRsStatus(HttpURLConnection.HTTP_OK)
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:22,代码来源:TkCorsTest.java


示例14: cantHandleConnectionsWithWrongDomainOnOrigin

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkCors can't handle connections with wrong domain on origin.
 * @throws Exception If some problem inside
 */
@Test
public void cantHandleConnectionsWithWrongDomainOnOrigin()
    throws Exception {
    MatcherAssert.assertThat(
        "Wrong value on header.",
        new RsPrint(
            new TkCors(
                new TkFixed(new RsText()),
                "http://www.teamed.io",
                "http://sample.com"
            ).act(
                new RqWithHeaders(
                    new RqFake(),
                    "Origin: http://wrong.teamed.io"
                )
            )
        ).printHead(),
        Matchers.allOf(
            Matchers.containsString("HTTP/1.1 403"),
            Matchers.containsString(
                "Access-Control-Allow-Credentials: false"
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:30,代码来源:TkCorsTest.java


示例15: FbError

import org.takes.rs.RsText; //导入依赖的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


示例16: deck

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * Get deck.
 * @return The deck
 * @throws IOException If fails
 */
@SuppressWarnings("PMD.PreserveStackTrace")
public Deck deck() throws IOException {
    final User user = new RqUser(this, this.base).get();
    final String name = new RqHeaders.Smart(
        new RqHeaders.Base(this)
    ).single("X-Thindeck-Deck");
    try {
        return user.decks().get(name);
    } catch (final IOException ex) {
        throw new RsForward(
            new RsText(ex.getLocalizedMessage()),
            HttpURLConnection.HTTP_NOT_FOUND
        );
    }
}
 
开发者ID:yegor256,项目名称:thindeck,代码行数:21,代码来源:RqDeck.java


示例17: TkSafe

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * Ctor.
 * @param take Original take
 */
public TkSafe(final Take take) {
    this.take = 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 TkFatal().route(req)
        )
    );
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:31,代码来源:TkSafe.java


示例18: safe

import org.takes.rs.RsText; //导入依赖的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


示例19: make

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * 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))
        )
    );
}
 
开发者ID:yegor256,项目名称:jare,代码行数:32,代码来源:TkAppFallback.java


示例20: sendsRequestThroughToHome

import org.takes.rs.RsText; //导入依赖的package包/类
/**
 * TkRelay can send the request through.
 * @throws Exception If some problem inside
 */
@Test
public void sendsRequestThroughToHome() throws Exception {
    final Take target = new TkFork(
        new FkRegex(
            "/alpha/.*",
            (Take) req -> new RsText(
                new RqHref.Base(req).href().toString()
            )
        )
    );
    new FtRemote(target).exec(
        home -> MatcherAssert.assertThat(
            new RsPrint(
                new TkRelay(new FkBase()).act(
                    TkRelayTest.fake(
                        home, "/alpha/%D0%B4%D0%B0?abc=cde"
                    )
                )
            ).printBody(),
            Matchers.equalTo(
                String.format(
                    "%s/alpha/%%D0%%B4%%D0%%B0?abc=cde",
                    home
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:jare,代码行数:33,代码来源:TkRelayTest.java



注:本文中的org.takes.rs.RsText类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BytesReader类代码示例发布时间:2022-05-22
下一篇:
Java RefreshAdminAclsRequestPBImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap