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

Java RqHref类代码示例

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

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



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

示例1: act

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


示例2: act

import org.takes.rq.RqHref; //导入依赖的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: act

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


示例4: route

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Opt<Response> route(final Request req) throws IOException {
    String path = new RqHref.Base(req).href().path();
    if (path.length() > 1 && path.charAt(path.length() - 1) == '/') {
        path = path.substring(0, path.length() - 1);
    }
    final Matcher matcher = this.pattern.matcher(path);
    final Opt<Response> resp;
    if (matcher.matches()) {
        resp = new Opt.Single<>(
            this.target.get().act(
                new RqMatcher(matcher, req)
            )
        );
    } else {
        resp = new Opt.Empty<>();
    }
    return resp;
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:FkRegex.java


示例5: make

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Ctor.
 * @param req Request
 * @param app Google application ID
 * @param rel Related
 * @param redir Redirect URI
 * @return Source
 * @throws IOException If fails
 * @since 0.14
 * @checkstyle ParameterNumberCheck (4 lines)
 */
private static XeSource make(final Request req, final CharSequence app,
    final CharSequence rel, final CharSequence redir) throws IOException {
    return new XeLink(
        rel,
        new Href("https://accounts.google.com/o/oauth2/auth")
            .with("client_id", app)
            .with("redirect_uri", redir)
            .with("response_type", "code")
            .with("state", new RqHref.Base(req).href())
            .with(
                "scope",
                "https://www.googleapis.com/auth/userinfo.profile"
            )
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:XeGoogleLink.java


示例6: enter

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Opt<Identity> enter(final Request req) throws IOException {
    final Iterator<String> flg = new RqHref.Base(req).href()
        .param(this.flag).iterator();
    Opt<Identity> user = new Opt.Empty<>();
    if (flg.hasNext()) {
        final String value = flg.next();
        for (final Map.Entry<Pattern, Pass> ent : this.passes.entrySet()) {
            if (ent.getKey().matcher(value).matches()) {
                user = ent.getValue().enter(req);
                break;
            }
        }
    }
    return user;
}
 
开发者ID:yegor256,项目名称:takes,代码行数:17,代码来源:PsByFlag.java


示例7: log

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Log this request.
 * @param req Request
 * @throws IOException If fails
 */
private static void log(final RqFallback req) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final Throwable error = req.throwable();
    try (PrintStream stream = new Utf8PrintStream(baos, false)) {
        error.printStackTrace(stream);
    }
    Logger.getLogger(FbLog4j.class).error(
        String.format(
            "%s %s failed with %s: %s",
            new RqMethod.Base(req).method(),
            new RqHref.Base(req).href(),
            req.code(),
            baos.toString("UTF-8")
        )
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:22,代码来源:FbLog4j.java


示例8: error

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Create an error.
 * @param exp Exception original
 * @param req Request we're processing
 * @param msec Milliseconds it took
 * @return Error
 * @throws IOException If fails
 */
private static Throwable error(final Throwable exp, final Request req,
    final long msec) throws IOException {
    final String time;
    if (msec < TimeUnit.SECONDS.toMillis(1L)) {
        time = String.format("%dms", msec);
    } else {
        time = String.format(
            "%ds",
            msec / TimeUnit.SECONDS.toMillis(1L)
        );
    }
    return new IllegalStateException(
        String.format(
            "[%s %s] failed in %s: %s",
            new RqMethod.Base(req).method(),
            new RqHref.Base(req).href(),
            time, exp.getLocalizedMessage()
        ),
        exp
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:30,代码来源:TkFallback.java


示例9: TkClasspath

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Ctor.
 * @param prefix Prefix
 */
public TkClasspath(final String prefix) {
    super(
        new Take() {
            @Override
            public Response act(final Request request) throws IOException {
                final String name = String.format(
                    "%s%s", prefix, new RqHref.Base(request).href().path()
                );
                final InputStream input = this.getClass()
                    .getResourceAsStream(name);
                if (input == null) {
                    throw new HttpException(
                        HttpURLConnection.HTTP_NOT_FOUND,
                        String.format("%s not found in classpath", name)
                    );
                }
                return new RsWithBody(input);
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:TkClasspath.java


示例10: TkVerbose

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Ctor.
 * @param take Original take
 */
public TkVerbose(final Take take) {
    super(
        new Take() {
            @Override
            public Response act(final Request request) throws IOException {
                try {
                    return take.act(request);
                } catch (final HttpException ex) {
                    throw new HttpException(
                        ex.code(),
                        String.format(
                            "%s %s",
                            new RqMethod.Base(request).method(),
                            new RqHref.Base(request).href()
                        ),
                        ex
                    );
                }
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:27,代码来源:TkVerbose.java


示例11: TkFiles

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Ctor.
 * @param base Base directory
 */
public TkFiles(final File base) {
    super(
        new Take() {
            @Override
            public Response act(final Request request) throws IOException {
                final File file = new File(
                    base, new RqHref.Base(request).href().path()
                );
                if (!file.exists()) {
                    throw new HttpException(
                        HttpURLConnection.HTTP_NOT_FOUND,
                        String.format(
                            "%s not found", file.getAbsolutePath()
                        )
                    );
                }
                return new RsWithBody(new FileInputStream(file));
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:26,代码来源:TkFiles.java


示例12: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    MatcherAssert.assertThat(
        new RqHref.Base(req).href()
            .param(PsGithubTest.ACCESS_TOKEN)
            .iterator().next(),
        Matchers.containsString(PsGithubTest.GIT_HUB_TOKEN)
    );
    return new RsJson(
        Json.createObjectBuilder()
            .add(PsGithubTest.LOGIN, PsGithubTest.OCTOCAT)
            .add("id", 1)
            .add(
                "avatar_url",
                PsGithubTest.OCTOCAT_GIF_URL
            )
            .build()
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:20,代码来源:PsGithubTest.java


示例13: enter

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Opt<Identity> enter(final Request req) throws IOException {
    final Opt<Identity> user;
    if (TkAppAuth.TESTING) {
        final Iterator<String> login =
            new RqHref.Base(req).href().param("user").iterator();
        final String name;
        if (login.hasNext()) {
            name = login.next();
        } else {
            name = "tester";
        }
        user = new Opt.Single<Identity>(
            new Identity.Simple(
                String.format("urn:test:%s", name),
                new ArrayMap<String, String>().with("login", name)
            )
        );
    } else {
        user = new Opt.Empty<>();
    }
    return user;
}
 
开发者ID:yegor256,项目名称:thindeck,代码行数:24,代码来源:TkAppAuth.java


示例14: redirect

import org.takes.rq.RqHref; //导入依赖的package包/类
/**
 * Redirect to the bout.
 * @param deck Deck name
 * @param take Take
 * @return New take
 */
private static Take redirect(final String deck, final Take take) {
    return new Take() {
        @Override
        public Response act(final Request req) throws IOException {
            try {
                return take.act(req);
            } catch (final RsForward ex) {
                if (ex.code() == HttpURLConnection.HTTP_SEE_OTHER) {
                    throw new RsForward(
                        ex,
                        new RqHref.Smart(
                            new RqHref.Base(req)
                        ).home().path("d").path(deck)
                    );
                }
                throw ex;
            }
        }
    };
}
 
开发者ID:yegor256,项目名称:thindeck,代码行数:27,代码来源:FkDeck.java


示例15: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    final URL url = new URL(new RqHref.Smart(req).single("u"));
    return new RsPage(
        "/xsl/info.xsl",
        req,
        () -> new ListOf<>(
            new XeAppend("url", url.toString()),
            new XeAppend(
                "encoded_url",
                URLEncoder.encode(
                    url.toString(), StandardCharsets.UTF_8.name()
                )
            ),
            new XeAppend(
                "targets",
                new XeDirectives(
                    new Joined<>(
                        new Limited<>(
                            this.base.status(url).failures(Long.MAX_VALUE),
                            Tv.TWENTY
                        )
                    )
                )
            ),
            new XeAppend(
                "history",
                new XeDirectives(
                    new Joined<>(
                        new Limited<>(
                            this.base.status(url).history(Long.MAX_VALUE),
                            Tv.TEN
                        )
                    )
                )
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:40,代码来源:TkInfo.java


示例16: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    final URL url = new URL(new RqHref.Smart(req).single("u"));
    return new RsWithType(
        new RsWithHeaders(
            new RsWithBody(
                TkBadge.SVG.with("style", "round").applyTo(
                    new XMLDocument(
                        new Xembler(
                            new Directives()
                                .add("info")
                                .add("url")
                                .set(url)
                                .up()
                                .add("total")
                                .set(
                                    this.base.status(url).history(
                                        Long.MAX_VALUE
                                    ).size()
                                )
                                .up()
                                .add("failures")
                                .set(
                                    this.base.status(url).failures(
                                        Long.MAX_VALUE
                                    ).size()
                                )
                                .up()
                        ).xmlQuietly()
                    )
                )
            ),
            "Cache-Control: no-cache"
        ),
        "image/svg+xml"
    );
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:38,代码来源:TkBadge.java


示例17: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
    final URL url = new URL(new RqHref.Smart(req).single("u"));
    final long time = Long.parseLong(new RqHref.Smart(req).single("t"));
    return new RsPage(
        "/xsl/details.xsl",
        req,
        () -> new ListOf<>(
            new XeDirectives(
                this.base.status(url).details(time)
            )
        )
    );
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:15,代码来源:TkDetails.java


示例18: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final User user = new RqUser(this.base, request);
    final String name = new RqHref.Smart(request).single("name");
    user.script(name).flush();
    return new RsForward(
        new RsFlash(
            String.format("Script \"%s\" flushed, it will start now.", name)
        ),
        "/scripts"
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:13,代码来源:TkFlush.java


示例19: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final User user = new RqUser(this.base, request);
    final String name = new RqHref.Smart(request).single("name");
    user.script(name).delete();
    return new RsForward(
        new RsFlash(
            String.format("Script \"%s\" deleted.", name)
        ),
        "/scripts"
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:13,代码来源:TkDelete.java


示例20: act

import org.takes.rq.RqHref; //导入依赖的package包/类
@Override
public Response act(final Request request) throws IOException {
    final User user = new RqUser(this.base, request);
    final String group = new RqHref.Smart(request).single("group");
    final long start = Long.parseLong(
        new RqHref.Smart(request).single("start")
    );
    user.delete(group, start);
    return new RsForward(
        new RsFlash(
            String.format("Log \"%[email protected]%d\" deleted.", group, start)
        ),
        "/logs"
    );
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:16,代码来源:TkDeleteLog.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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