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

Java Request类代码示例

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

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



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

示例1: act

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


示例2: act

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


示例3: act

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


示例4: act

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


示例5: act

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


示例6: act

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


示例7: act

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


示例8: act

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


示例9: act

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


示例10: act

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


示例11: act

import org.takes.Request; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    final String name = new RqFormBase(req).param("name")
        .iterator().next().trim();
    try {
        new SafeUser(this.base.user(new RqUser(req).name())).add(name);
    } catch (final SafeUser.InvalidNameException ex) {
        throw TkAdd.forward(new RsFlash(ex));
    }
    return TkAdd.forward(
        new RsFlash(
            String.format(
                "domain \"%s\" added", name
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:jare,代码行数:18,代码来源:TkAdd.java


示例12: request

import org.takes.Request; //导入依赖的package包/类
/**
 * The request to send.
 * @param req Original request
 * @param path Destination path
 * @return Request
 */
private static Request request(final Request req, final String path) {
    return new Request() {
        @Override
        public Iterable<String> head() throws IOException {
            return new Concat<String>(
                Collections.singleton(
                    String.format(
                        "GET %s HTTP/1.1",
                        path
                    )
                ),
                new Skipped<>(req.head(), 1)
            );
        }
        @Override
        public InputStream body() throws IOException {
            return req.body();
        }
    };
}
 
开发者ID:yegor256,项目名称:jare,代码行数:27,代码来源:TkRelay.java


示例13: act

import org.takes.Request; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    return new RsPage(
        "/xsl/domains.xsl",
        req,
        new XeAppend(
            "domains",
            new XeTransform<>(
                this.base.user(new RqUser(req).name()).mine(),
                TkDomains::source
            )
        ),
        new XeLink("add", "/add"),
        new XeLink("invalidate", "/invalidate")
    );
}
 
开发者ID:yegor256,项目名称:jare,代码行数:17,代码来源:TkDomains.java


示例14: fake

import org.takes.Request; //导入依赖的package包/类
/**
 * Fake request.
 * @param home Base URI
 * @param path Path
 * @return Request
 * @throws UnsupportedEncodingException If fails
 */
private static Request fake(final URI home, final String path)
    throws UnsupportedEncodingException {
    return new RqFake(
        Arrays.asList(
            String.format(
                "GET /?u=%s",
                URLEncoder.encode(
                    home.resolve(path).toString(),
                    "UTF-8"
                )
            ),
            "Host: localhost"
        ),
        ""
    );
}
 
开发者ID:yegor256,项目名称:jare,代码行数:24,代码来源:TkRelayTest.java


示例15: act

import org.takes.Request; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    final Iterable<Event> events = this.base.user(new RqUser(req).urn())
        .events()
        .iterate();
    return new RsPage(
        "/xsl/events.xsl",
        req,
        new XeAppend(
            "events",
            new XeChain(
                new XeTransform<>(
                    Iterables.limit(events, Tv.TWENTY),
                    TkEvents::source
                )
            ),
            new XeDirectives(
                new Directives().attr("total", Iterables.size(events))
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:wring,代码行数:23,代码来源:TkEvents.java


示例16: make

import org.takes.Request; //导入依赖的package包/类
/**
 * Make a request.
 *  Scans the origin request until the boundary reached. Caches
 *  the  content into a temporary file and returns it as a new request.
 * @param boundary Boundary
 * @param body Origin request body
 * @return Request
 * @throws IOException If fails
 */
private Request make(final byte[] boundary,
    final ReadableByteChannel body) throws IOException {
    final File file = File.createTempFile(
        RqMultipart.class.getName(), ".tmp"
    );
    try (WritableByteChannel channel = Files.newByteChannel(
        file.toPath(),
        StandardOpenOption.READ,
        StandardOpenOption.WRITE
    )
    ) {
        channel.write(
            ByteBuffer.wrap(
                this.head().iterator().next().getBytes(RqMtBase.ENCODING)
            )
        );
        channel.write(
            ByteBuffer.wrap(RqMtBase.CRLF.getBytes(RqMtBase.ENCODING))
        );
        this.copy(channel, boundary, body);
    }
    return new RqTemp(file);
}
 
开发者ID:yegor256,项目名称:takes,代码行数:33,代码来源:RqMtBase.java


示例17: wrap

import org.takes.Request; //导入依赖的package包/类
/**
 * Wrap the request.
 * @param req Request
 * @return New request
 */
private static Request wrap(final Request req) {
    final AtomicBoolean seen = new AtomicBoolean(false);
    return new Request() {
        @Override
        public Iterable<String> head() throws IOException {
            return req.head();
        }
        @Override
        public InputStream body() throws IOException {
            if (!seen.getAndSet(true)) {
                throw new IllegalStateException(
                    "It's not allowed to call body() more than once"
                );
            }
            return req.body();
        }
    };
}
 
开发者ID:yegor256,项目名称:takes,代码行数:24,代码来源:RqOnce.java


示例18: catchesExceptionThrownByResponse

import org.takes.Request; //导入依赖的package包/类
/**
 * TkForward can catch RsForward throws by Response.
 * @throws IOException If some problem inside
 */
@Test
public void catchesExceptionThrownByResponse() throws IOException {
    final Take take = new Take() {
        @Override
        public Response act(final Request request) {
            return new Response() {
                @Override
                public Iterable<String> head() {
                    return new RsEmpty().head();
                }
                @Override
                public InputStream body() throws IOException {
                    throw new RsForward("/b");
                }
            };
        }
    };
    MatcherAssert.assertThat(
        new RsPrint(
            new TkForward(take).act(new RqFake())
        ).print(),
        Matchers.startsWith("HTTP/1.1 303")
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:29,代码来源:TkForwardTest.java


示例19: retriesOnExceptionTillSuccess

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


示例20: extendsNotFoundException

import org.takes.Request; //导入依赖的package包/类
/**
 * TkVerbose can extend not-found exception.
 * @throws IOException If some problem inside
 */
@Test
public void extendsNotFoundException() throws IOException {
    final Take take = new Take() {
        @Override
        public Response act(final Request request) throws IOException {
            throw new HttpException(HttpURLConnection.HTTP_NOT_FOUND);
        }
    };
    try {
        new TkVerbose(take).act(new RqFake());
    } catch (final HttpException ex) {
        MatcherAssert.assertThat(
            ex.getLocalizedMessage(),
            Matchers.endsWith("GET http://www.example.com/")
        );
    }
}
 
开发者ID:yegor256,项目名称:takes,代码行数:22,代码来源:TkVerboseTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java GlobalConfigModule类代码示例发布时间:2022-05-22
下一篇:
Java Meta类代码示例发布时间: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