本文整理汇总了Java中org.takes.rq.RqHref类的典型用法代码示例。如果您正苦于以下问题:Java RqHref类的具体用法?Java RqHref怎么用?Java RqHref使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RqHref类属于org.takes.rq包,在下文中一共展示了RqHref类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
)
)
);
}
示例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());
}
示例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()
)
)
)
);
}
示例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;
}
示例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"
)
);
}
示例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;
}
示例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")
)
);
}
示例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
);
}
示例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);
}
}
);
}
示例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
);
}
}
}
);
}
示例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));
}
}
);
}
示例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()
);
}
示例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;
}
示例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;
}
}
};
}
示例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
)
)
)
)
)
);
}