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

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

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

HttpRequest.getAttributes介绍

暂无

代码示例

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

@Override
public BindingResult<T> bind(ArgumentConversionContext<T> argument, HttpRequest<?> source) {
  MutableConvertibleValues<Object> parameters = source.getAttributes();
  AnnotationMetadata annotationMetadata = argument.getAnnotationMetadata();
  String parameterName = annotationMetadata.getValue(RequestAttribute.class, String.class).orElse(argument.getArgument().getName());
  return doBind(argument, parameters, parameterName);
}

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

@Override
public final Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
  String attributeKey = getKey(getClass());
  MutableConvertibleValues<Object> attrs = request.getAttributes();
  if (attrs.contains(attributeKey)) {
    return chain.proceed(request);
  } else {
    attrs.put(attributeKey, true);
    return doFilterOnce(request, chain);
  }
}

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

@Override
  public Publisher<? extends HttpResponse<?>> doFilter(HttpRequest<?> request, FilterChain chain) {
    request.getAttributes().put("first", true);
    Assert.that(!request.getAttributes().contains("authenticated"));
    Publisher<? extends HttpResponse<?>> publisher = chain.proceed(request);
    return Publishers.then(publisher, httpResponse -> {
      httpResponse.getHeaders();
    });
  }
}

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

if (!val.isPresent() && !hasAnnotation) {
  result = doBind(context, source.getAttributes(), parameterName);

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

@Override
  public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
    Assert.that(request.getAttributes().contains("first"));
    Assert.that(!request.getAttributes().contains("second"));
    if(request.getParameters().get("username") == null) {
      return Publishers.just(HttpResponse.status(HttpStatus.FORBIDDEN));
    }
    else {
      request.getAttributes().put("authenticated", true);
      return Publishers.map(
          chain.proceed(request),
          mutableHttpResponse -> mutableHttpResponse.header("X-Test", "Foo " + request.getAttributes().get("SomeServiceValue", String.class, "none"))
      );
    }
  }
}

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

@Override
public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
  SomeService someService = new SomeService();
  return someService
        .getSomething()
        .switchMap(s -> {
          request.getAttributes().put("SomeServiceValue", s);
          return chain.proceed(request);
        });
}

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

@Override
  public Publisher<? extends HttpResponse<?>> doFilter(HttpRequest<?> request, FilterChain chain) {
    MutableConvertibleValues<Object> attributes = request.getAttributes();
    Assert.that(attributes.contains("first"));
    Assert.that(!attributes.contains("second"));
    Assert.that(attributes.contains("authenticated"));
    attributes.put("second", true);
    return chain.proceed(request);
  }
}

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

@Override
public Optional<Object> getValue() {
  return source.getAttributes().get(name, context);
}

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

@Override
public final Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
  String attributeKey = getKey(getClass());
  MutableConvertibleValues<Object> attrs = request.getAttributes();
  if (attrs.contains(attributeKey)) {
    return chain.proceed(request);
  } else {
    attrs.put(attributeKey, true);
    return doFilterOnce(request, chain);
  }
}

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

if (!val.isPresent() && !hasAnnotation) {
  result = doBind(context, source.getAttributes(), parameterName);

相关文章