org.jooby.Request.ifGet()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(431)

本文整理了Java中org.jooby.Request.ifGet方法的一些代码示例,展示了Request.ifGet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.ifGet方法的具体详情如下:
包路径:org.jooby.Request
类名称:Request
方法名:ifGet

Request.ifGet介绍

[英]Get a request local attribute.
[中]获取请求本地属性。

代码示例

代码示例来源:origin: jooby-project/jooby

@Override
public <T> Optional<T> ifGet(final String name) {
 return req.ifGet(name);
}

代码示例来源:origin: jooby-project/jooby

@Override
public Object getRequestAttribute(final String name) {
 Optional<Object> attr = req.ifGet(name);
 return attr.orElse(null);
}

代码示例来源:origin: jooby-project/jooby

/**
 * @param name Attribute's name.
 * @return True if the local attribute is set.
 */
default boolean isSet(final String name) {
 return ifGet(name).isPresent();
}

代码示例来源:origin: jooby-project/jooby

@Override
public Object resolve(final Object context, final String name) {
 Object value = null;
 if (context instanceof Request) {
  value = ((Request) context).ifGet(name).orElse(null);
 }
 return value == null ? UNRESOLVED : value;
}

代码示例来源:origin: jooby-project/jooby

@Override public Object getRequestAttribute(String name) {
 return req.ifGet(name).orElse(null);
}

代码示例来源:origin: jooby-project/jooby

/**
 * Get a request local attribute.
 *
 * @param name Attribute's name.
 * @param def A default value.
 * @param <T> Target type.
 * @return A local attribute.
 */
@Nonnull
default <T> T get(final String name, final T def) {
 Optional<T> opt = ifGet(name);
 return opt.orElse(def);
}

代码示例来源:origin: jooby-project/jooby

@Override public String getRequestParameter(String name) {
 String value  = req.ifGet("pac4j." + name)
   .map(Objects::toString)
   .orElse(params.getOrDefault(name, NO_PARAM)[0]);
 return value;
}

代码示例来源:origin: jooby-project/jooby

/**
 * Get a request local attribute.
 *
 * @param name Attribute's name.
 * @param <T> Target type.
 * @return A local attribute.
 * @throws Err with {@link Status#BAD_REQUEST}.
 */
@Nonnull
default <T> T get(final String name) {
 Optional<T> opt = ifGet(name);
 return opt.orElseThrow(
   () -> new Err(Status.BAD_REQUEST, "Required local attribute: " + name + " is not present"));
}

代码示例来源:origin: jooby-project/jooby

/**
 * Give you access to flash scope. Usage:
 *
 * <pre>{@code
 * {
 *   use(new FlashScope());
 *
 *   get("/", req -> {
 *     Map<String, String> flash = req.flash();
 *     return flash;
 *   });
 * }
 * }</pre>
 *
 * As you can see in the example above, the {@link FlashScope} needs to be install it by calling
 * {@link Jooby#use(org.jooby.Jooby.Module)} otherwise a call to this method ends in
 * {@link Err BAD_REQUEST}.
 *
 * @return A mutable map with attributes from {@link FlashScope}.
 * @throws Err Bad request error if the {@link FlashScope} was not installed it.
 */
@Nonnull
default Flash flash() throws Err {
 Optional<Flash> flash = ifGet(FlashScope.NAME);
 return flash.orElseThrow(() -> new Err(Status.BAD_REQUEST,
   "Flash scope isn't available. Install via: use(new FlashScope());"));
}

代码示例来源:origin: jooby-project/jooby

private String profileID(final boolean useSession, final Request req) {
 return req.<String>ifGet(Auth.ID)
   .orElseGet(() -> useSession ? req.session().get(Auth.ID).value(null) : null);
}

代码示例来源:origin: jooby-project/jooby

@Override public void handle(Request req, Response rsp) {
  WebContext context = req.require(WebContext.class);
  String redirectTo = req.<String>ifGet("pac4j.logout.redirectTo").orElse(defaultUrl);
  conf.getLogoutLogic()
    .perform(context, conf, conf.getHttpActionAdapter(), redirectTo, logoutUrlPattern,
      localLogout, destroySession, centralLogout);
 }
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("unchecked")
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
 // DON'T create a session for JWT/param/header auth (a.k.a stateless)
 Optional<Session> ifSession = req.ifSession();
 if (ifSession.isPresent()) {
  Session session = ifSession.get();
  Optional<String> profileId = session.unset(Auth.ID).toOptional();
  if (profileId.isPresent()) {
   Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get());
   log.debug("logout {}", profile);
   session.destroy();
  }
 } else {
  log.debug("nothing to logout from session");
 }
 String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo);
 rsp.redirect(redirectTo);
}

代码示例来源:origin: org.jooby/jooby

@Override
public <T> Optional<T> ifGet(final String name) {
 return req.ifGet(name);
}

代码示例来源:origin: org.jooby/jooby-hbs

@Override
public Object resolve(final Object context, final String name) {
 Object value = null;
 if (context instanceof Request) {
  value = ((Request) context).ifGet(name).orElse(null);
 }
 return value == null ? UNRESOLVED : value;
}

代码示例来源:origin: org.jooby/jooby

/**
 * @param name Attribute's name.
 * @return True if the local attribute is set.
 */
default boolean isSet(final String name) {
 return ifGet(name).isPresent();
}

代码示例来源:origin: org.jooby/jooby-pac4j

@Override
public Object getRequestAttribute(final String name) {
 Optional<Object> attr = req.ifGet(name);
 return attr.orElse(null);
}

代码示例来源:origin: org.jooby/jooby

/**
 * Get a request local attribute.
 *
 * @param name Attribute's name.
 * @param def A default value.
 * @param <T> Target type.
 * @return A local attribute.
 */
@Nonnull
default <T> T get(final String name, final T def) {
 Optional<T> opt = ifGet(name);
 return opt.orElse(def);
}

代码示例来源:origin: org.jooby/jooby

/**
 * Get a request local attribute.
 *
 * @param name Attribute's name.
 * @param <T> Target type.
 * @return A local attribute.
 * @throws Err with {@link Status#BAD_REQUEST}.
 */
@Nonnull
default <T> T get(final String name) {
 Optional<T> opt = ifGet(name);
 return opt.orElseThrow(
   () -> new Err(Status.BAD_REQUEST, "Required local attribute: " + name + " is not present"));
}

代码示例来源:origin: org.jooby/jooby-pac4j

private String profileID(final boolean useSession, final Request req) {
 return req.<String>ifGet(Auth.ID)
   .orElseGet(() -> useSession ? req.session().get(Auth.ID).value(null) : null);
}

代码示例来源:origin: org.jooby/jooby-pac4j

@SuppressWarnings("unchecked")
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
 // DON'T create a session for JWT/param/header auth (a.k.a stateless)
 Optional<Session> ifSession = req.ifSession();
 if (ifSession.isPresent()) {
  Session session = ifSession.get();
  Optional<String> profileId = session.unset(Auth.ID).toOptional();
  if (profileId.isPresent()) {
   Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get());
   log.debug("logout {}", profile);
   session.destroy();
  }
 } else {
  log.debug("nothing to logout from session");
 }
 String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo);
 rsp.redirect(redirectTo);
}

相关文章