当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

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


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

示例1: route

import org.takes.Response; //导入依赖的package包/类
@Override
public final Opt<Response> route(final RqFallback req) throws IOException {
    return new Opt.Single<>(
        new RsWithStatus(
            new RsHtml(
                new RsVelocity(
                    TkApp.class.getResource("error.html.vm"),
                    new RsVelocity.Pair(
                        "err",
                        new TextOf(req.throwable()).asString()
                    ),
                    new RsVelocity.Pair(
                        "rev",
                        Manifests.read("Rehttp-Revision")
                    )
                )
            ),
            HttpURLConnection.HTTP_INTERNAL_ERROR
        )
    );
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:22,代码来源:TkFatal.java

示例2: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
    try {
        long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
        Category category = base.categories().category(number);

        JsonReader reader = Json.createReader(req.body());
        JsonObject json = reader.readObject();
        String name = json.getString("name");
        Optional<Category> parent = Optional.of(json.getInt("parent_id", 0))
                .filter(id -> id > 0)
                .map(id -> base.categories().category(id));

        Category result = category.update(name, parent);
        return new RsJson(result);
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:20,代码来源:TkCategoryUpdate.java

示例3: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
    try {
        long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
        Product product = base.products().product(number);

        JsonReader reader = Json.createReader(req.body());
        JsonObject json = reader.readObject();
        String name = json.getString("name");
        String desc = json.getString("desc");
        FastMoney price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");

        Product result = product.update(name, desc, price);
        return new RsJson(result);
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:19,代码来源:TkProductUpdate.java

示例4: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final String name = new RqHref.Smart(request).single("script");
    return new RsForward(
        String.format(
            "/log?name=%s",
            URLEncoder.encode(
                new RqUser(this.base, request).script(name).ocket(
                    Long.parseLong(
                        new RqHref.Smart(request).single("time")
                    )
                ),
                StandardCharsets.UTF_8.displayName()
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:18,代码来源:TkLogLink.java

示例5: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final User user = new RqUser(this.base, request);
    final RqFormSmart form = new RqFormSmart(new RqGreedy(request));
    final String name = form.single("script");
    final long cents = Long.parseLong(form.single("cents"));
    try {
        user.script(name).pay(
            cents, form.single("token"), form.single("email")
        );
    } catch (final IOException ex) {
        throw new RsForward(new RsFlash(ex));
    }
    return new RsForward(
        new RsFlash(
            String.format(
                "Script \"%s\" funded for $%.2f.",
                // @checkstyle MagicNumber (1 line)
                name, (double) cents / 100.0d
            )
        ),
        "/scripts"
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:25,代码来源:TkPay.java

示例6: fatal

import org.takes.Response; //导入依赖的package包/类
/**
 * 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 RsHtml(
            new RsVelocity(
                TkApp.class.getResource("error.html.vm"),
                new RsVelocity.Pair(
                    "err",
                    new TextOf(req.throwable()).asString()
                ),
                new RsVelocity.Pair("rev", TkApp.REV)
            )
        ),
        HttpURLConnection.HTTP_INTERNAL_ERROR
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:22,代码来源:TkApp.java

示例7: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    return new RsPage(
        "/xsl/logs.xsl",
        request,
        () -> new StickyList<>(
            new XeAppend("menu", "logs"),
            new XeDirectives(
                new Directives().add("logs").append(
                    new Joined<>(
                        new Limited<Iterable<Directive>>(
                            Tv.TWENTY,
                            new RqUser(this.base, request).logs()
                        )
                    )
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:21,代码来源:TkLogs.java

示例8: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    return new RsPage(
        "/xsl/scripts.xsl",
        request,
        () -> new StickyList<>(
            new XeAppend("menu", "scripts"),
            new XeAppend("stripe_cents", "500"),
            new XeAppend(
                "stripe_key",
                Manifests.read("ThreeCopies-StripeKey")
            ),
            new XeDirectives(
                new Directives().add("scripts").append(
                    new Joined<>(
                        new RqUser(this.base, request).scripts()
                    )
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:23,代码来源:TkScripts.java

示例9: act

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

示例10: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final User user = new RqUser(this.base, request);
    final RqHref href = new RqHref.Base(request);
    final Iterator<String> name = href.href().param("name").iterator();
    return new RsPage(
        "/xsl/script.xsl",
        request,
        () -> new StickyList<>(
            new XeAppend("menu", "scripts"),
            new XeWhen(
                name.hasNext(),
                () -> new XeDirectives(
                    user.script(name.next()).toXembly()
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:20,代码来源:TkScript.java

示例11: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request req) {
    return new RsPage(
        req, "mistakes",
        () -> new IterableOf<>(
            new XeAppend(
                "worst",
                new XeDirectives(
                    new Joined<>(
                        new Limited<>(
                            // @checkstyle MagicNumber (1 line)
                            20, new Mistakes().worst()
                        )
                    )
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:20,代码来源:TkMistakes.java

示例12: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final RqRegex req) throws IOException {
    final Matcher matcher = req.matcher();
    // @checkstyle MagicNumber (1 line)
    String path = matcher.group(3);
    if (path.isEmpty()) {
        throw new RsForward(
            String.format("%s/index.html", matcher.group(0))
        );
    }
    path = path.substring(1);
    return new IoCheckedFunc<>(
        new IoCheckedBiFunc<>(this.reports).apply(
            matcher.group(1),
            matcher.group(2)
        )
    ).apply(path);
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:19,代码来源:TkReport.java

示例13: act

import org.takes.Response; //导入依赖的package包/类
@Override
public Response act(final Request req) {
    return new RsPage(
        req, "all",
        () -> new IterableOf<>(
            new XeAppend(
                "recent",
                new XeDirectives(
                    new Joined<>(
                        new Results().all()
                    )
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:17,代码来源:TkAll.java

示例14: apply

import org.takes.Response; //导入依赖的package包/类
@Override
public Future<Func<String, Response>> apply(final String group,
    final String artifact) {
    final String target = String.format("%s:%s", group, artifact);
    this.queue.put(target, System.currentTimeMillis());
    // @checkstyle MagicNumber (1 line)
    if (this.times.size() > 1000) {
        this.times.clear();
    }
    return this.service.submit(
        new VerboseCallable<>(
            () -> {
                final Func<String, Response> func =
                    this.origin.apply(group, artifact);
                this.times.add(
                    System.currentTimeMillis() - this.queue.remove(target)
                );
                return func;
            },
            true, true
        )
    );
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:24,代码来源:Futures.java

示例15: pingsSimplePages

import org.takes.Response; //导入依赖的package包/类
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void pingsSimplePages() throws IOException {
    final String[] pages = {
        "/org/jpeek/web/layout.xsl",
        "/org/jpeek/web/index.xsl",
        "/jpeek.css",
        "/",
        "/mistakes",
        "/robots.txt",
    };
    final Take app = new TkApp(Files.createTempDirectory("x"));
    for (final String page : pages) {
        final Response response = app.act(new RqFake("GET", page));
        MatcherAssert.assertThat(
            new RsPrint(response).print(),
            response,
            new HmRsStatus(HttpURLConnection.HTTP_OK)
        );
    }
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:22,代码来源:TkAppTest.java


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