io.micronaut.http.HttpRequest.getAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(119)

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

HttpRequest.getAttribute介绍

暂无

代码示例

代码示例来源:origin: micronaut-projects/micronaut-core

@Override
public Optional<Principal> getUserPrincipal() {
  return originatingRequest.getAttribute("micronaut.AUTHENTICATION", Principal.class);
}

代码示例来源:origin: micronaut-projects/micronaut-core

boolean bindAll = source.getAttribute(HttpAttributes.ROUTE_MATCH, UriMatchInfo.class)
    .flatMap(umi -> umi.getVariables()
        .stream()

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * The user principal stored within the request.
 *
 * @return The principal
 * @since 1.0.4
 */
default @Nonnull Optional<Principal> getUserPrincipal() {
  return getAttribute(HttpAttributes.PRINCIPAL, Principal.class);
}

代码示例来源:origin: io.micronaut/micronaut-http

boolean bindAll = source.getAttribute(HttpAttributes.ROUTE_MATCH, UriMatchInfo.class)
    .flatMap(umi -> umi.getVariables()
        .stream()

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * The user principal stored within the request.
 *
 * @param principalType The principal type
 * @return The principal
 * @param <T> The principal type
 * @since 1.0.4
 */
default @Nonnull <T extends Principal> Optional<T> getUserPrincipal(Class<T> principalType) {
  return getAttribute(HttpAttributes.PRINCIPAL, principalType);
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * @param matcher A {@link OutgointRequestProcessorMatcher} implementation. Entity defining matching rules.
 * @param request The request
 * @return true if the request should be processed
 */
public boolean shouldProcessRequest(OutgointRequestProcessorMatcher matcher, HttpRequest<?> request) {
  Optional<String> serviceId = request.getAttribute(HttpAttributes.SERVICE_ID.toString(), String.class);
  String uri = request.getUri().toString();
  return shouldProcessRequest(matcher, serviceId.orElse(null), uri);
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * Creates a new netty web socket session.
 * @param id The ID
 * @param channel The channel
 * @param request The original request used to create the session
 * @param codecRegistry The codec registry
 * @param protocolVersion The protocol version
 * @param isSecure Whether the session is secure
 */
protected NettyRxWebSocketSession(
    String id,
    Channel channel,
    HttpRequest<?> request,
    MediaTypeCodecRegistry codecRegistry,
    String protocolVersion,
    boolean isSecure) {
  this.id = id;
  this.channel = channel;
  this.request = request;
  this.protocolVersion = protocolVersion;
  this.isSecure = isSecure;
  this.channel.attr(WEB_SOCKET_SESSION_KEY).set(this);
  this.codecRegistry = codecRegistry;
  this.messageEncoder = new WebSocketMessageEncoder(this.codecRegistry);
  this.attributes = request.getAttribute("micronaut.SESSION", MutableConvertibleValues.class).orElseGet(() -> new MutableConvertibleValuesMap());
}

代码示例来源:origin: micronaut-projects/micronaut-core

@Override
  public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
    Optional<Class> viewClass = request.getAttribute(HttpAttributes.ROUTE_MATCH, AnnotationMetadata.class)                                                          .flatMap(ann -> ann.classValue(JsonView.class));
    final Publisher<MutableHttpResponse<?>> responsePublisher = chain.proceed(request);
    if (viewClass.isPresent()) {
      return Flowable.fromPublisher(responsePublisher).switchMap(response -> {
        final Optional<?> body = response.getBody();
        if (body.isPresent()) {
          MediaTypeCodec codec = codecFactory.resolveJsonViewCodec(viewClass.get());
          return Flowable.fromCallable(() -> {
            final byte[] encoded = codec.encode(body.get());
            ((MutableHttpResponse) response).body(encoded);
            return response;
          }).subscribeOn(Schedulers.from(executorService));
        } else {
          return Flowable.just(response);
        }
      });
    } else {
      return responsePublisher;
    }
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

final Optional<UriMatchInfo> matchInfo = source.getAttribute(HttpAttributes.ROUTE_MATCH, UriMatchInfo.class);
boolean bindAll = matchInfo
    .flatMap(umi -> umi.getVariables()

代码示例来源:origin: io.micronaut/micronaut-http

/**
 * The user principal stored within the request.
 *
 * @param principalType The principal type
 * @return The principal
 * @param <T> The principal type
 * @since 1.0.4
 */
default @Nonnull <T extends Principal> Optional<T> getUserPrincipal(Class<T> principalType) {
  return getAttribute(HttpAttributes.PRINCIPAL, principalType);
}

代码示例来源:origin: io.micronaut/micronaut-http

/**
 * The user principal stored within the request.
 *
 * @return The principal
 * @since 1.0.4
 */
default @Nonnull Optional<Principal> getUserPrincipal() {
  return getAttribute(HttpAttributes.PRINCIPAL, Principal.class);
}

代码示例来源:origin: io.micronaut/router

/**
   * @param request The Http request
   * @return The optional route match
   */
  public static Optional<RouteMatch> findRouteMatchAtRequest(HttpRequest<?> request) {
    Optional<RouteMatch> routeMatchAttribute = request.getAttribute(HttpAttributes.ROUTE_MATCH, RouteMatch.class);
    if (routeMatchAttribute.isPresent()) {
      return routeMatchAttribute;
    } else {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Route match attribute for request ({}) not found", request.getPath());
      }
      return Optional.empty();
    }
  }
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
  public BindingResult<ModelMap> bind(ArgumentConversionContext<ModelMap> context, HttpRequest<?> source) {
    final Optional<ModelMap> attribute = source.getAttribute(ATTRIBUTE, ModelMap.class);
    if (!attribute.isPresent()) {
      final ModelMap modelMap = new ModelMap();
      source.setAttribute(ATTRIBUTE, modelMap);
      return () -> Optional.of(modelMap);
    }
    return () -> attribute;
  }
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public BindingResult<Model> bind(ArgumentConversionContext<Model> context, HttpRequest<?> source) {
  final Optional<Model> attribute = source.getAttribute(ATTRIBUTE, Model.class);
  if (!attribute.isPresent()) {
    final ConcurrentModel concurrentModel = new ConcurrentModel();
    source.setAttribute(ATTRIBUTE, concurrentModel);
    return () -> Optional.of(concurrentModel);
  }
  return () -> attribute;
}

代码示例来源:origin: io.micronaut/micronaut-http

/**
 * @param matcher A {@link OutgointRequestProcessorMatcher} implementation. Entity defining matching rules.
 * @param request The request
 * @return true if the request should be processed
 */
public boolean shouldProcessRequest(OutgointRequestProcessorMatcher matcher, HttpRequest<?> request) {
  Optional<String> serviceId = request.getAttribute(HttpAttributes.SERVICE_ID.toString(), String.class);
  String uri = request.getUri().toString();
  return shouldProcessRequest(matcher, serviceId.orElse(null), uri);
}

代码示例来源:origin: micronaut-projects/micronaut-spring

final Publisher<MutableHttpResponse<?>> responsePublisher = chain.proceed(request);
return Publishers.map(responsePublisher, mutableHttpResponse -> {
  final Optional<Model> attribute = request.getAttribute(ModelRequestArgumentBinder.ATTRIBUTE, Model.class);
  final Object body = mutableHttpResponse.body();
  final boolean isCharSeq = body instanceof CharSequence;
    final Optional<ModelMap> modelMap = request.getAttribute(ModelRequestArgumentBinder.ATTRIBUTE, ModelMap.class);

代码示例来源:origin: io.micronaut/micronaut-http

final Optional<UriMatchInfo> matchInfo = source.getAttribute(HttpAttributes.ROUTE_MATCH, UriMatchInfo.class);
boolean bindAll = matchInfo
    .flatMap(umi -> umi.getVariables()

相关文章