io.micronaut.http.HttpMethod Java Examples
The following examples show how to use
io.micronaut.http.HttpMethod.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomLoginHandlerTest.java From micronaut-microservices-poc with Apache License 2.0 | 6 votes |
@Test public void customLoginHandler() { //when: HttpRequest request = HttpRequest.create(HttpMethod.POST, "/login") .accept(MediaType.APPLICATION_JSON_TYPE) .body(new UsernamePasswordCredentials("jimmy.solid", "secret")); HttpResponse<CustomBearerAccessRefreshToken> rsp = httpClient.toBlocking().exchange(request, CustomBearerAccessRefreshToken.class); //then: assertThat(rsp.getStatus().getCode()).isEqualTo(200); assertThat(rsp.body()).isNotNull(); assertThat(rsp.body().getAccessToken()).isNotNull(); assertThat(rsp.body().getRefreshToken()).isNotNull(); assertThat(rsp.body().getAvatar()).isNotNull(); assertThat(rsp.body().getAvatar()).isEqualTo("static/avatars/jimmy_solid.png"); }
Example #2
Source File: RequestMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 6 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { List<AnnotationValue<?>> annotations = new ArrayList<>(); final String path = computePath(annotation); final Optional<HttpMethod> method = annotation.get("method", HttpMethod.class); annotations.add(newBuilder(method.orElse(null), annotation).value(path).build()); final String[] consumes = annotation.get("consumes", String[].class).orElse(null); final String[] produces = annotation.get("produces", String[].class).orElse(null); if (ArrayUtils.isNotEmpty(consumes)) { annotations.add(AnnotationValue.builder(Consumes.class).member("value", consumes).build()); } if (ArrayUtils.isNotEmpty(produces)) { annotations.add(AnnotationValue.builder(Produces.class).member("value", produces).build()); } if (isHttpMethodMapping(method.orElse(null))) { annotations.add(AnnotationValue.builder(HttpMethodMapping.class).value(path).build()); } return annotations; }
Example #3
Source File: GoogleMethodRouteBuilder.java From micronaut-gcp with Apache License 2.0 | 5 votes |
@Override protected UriRoute buildBeanRoute(String httpMethodName, HttpMethod httpMethod, String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) { String cp = contextPathProvider.getContextPath(); if (cp != null) { uri = StringUtils.prependUri(cp, uri); } return super.buildBeanRoute(httpMethodName, httpMethod, uri, beanDefinition, method); }
Example #4
Source File: CustomClaimsTest.java From micronaut-microservices-poc with Apache License 2.0 | 5 votes |
@Test public void testCustomClaimsArePresentInJwt() { //when: HttpRequest request = HttpRequest.create(HttpMethod.POST, "/login") .accept(MediaType.APPLICATION_JSON_TYPE) .body(new UsernamePasswordCredentials("jimmy.solid", "secret")); HttpResponse<AccessRefreshToken> rsp = httpClient.toBlocking().exchange(request, AccessRefreshToken.class); //then: assertThat(rsp.getStatus().getCode()).isEqualTo(200); assertThat(rsp.body()).isNotNull(); assertThat(rsp.body().getAccessToken()).isNotNull(); assertThat(rsp.body().getRefreshToken()).isNotNull(); //when: String accessToken = rsp.body().getAccessToken(); JwtTokenValidator tokenValidator = server.getApplicationContext().getBean(JwtTokenValidator.class); Authentication authentication = Flowable.fromPublisher(tokenValidator.validateToken(accessToken)).blockingFirst(); //then: assertThat(authentication.getAttributes()).isNotNull(); assertThat(authentication.getAttributes()).containsKey("roles"); assertThat(authentication.getAttributes()).containsKey("iss"); assertThat(authentication.getAttributes()).containsKey("exp"); assertThat(authentication.getAttributes()).containsKey("iat"); assertThat(authentication.getAttributes()).containsKey("avatar"); assertThat(authentication.getAttributes().get("avatar")).isEqualTo("static/avatars/jimmy_solid.png"); }
Example #5
Source File: RequestMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
/** * Construct a new builder for the given http method. * @param httpMethod The method * @param annotation The annotation * @return The builder */ protected @Nonnull AnnotationValueBuilder<?> newBuilder( @Nullable HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { if (httpMethod != null) { switch (httpMethod) { case TRACE: return AnnotationValue.builder(Trace.class); case DELETE: return AnnotationValue.builder(Delete.class); case GET: return AnnotationValue.builder(Get.class); case HEAD: return AnnotationValue.builder(Head.class); case POST: return AnnotationValue.builder(Post.class); case PUT: return AnnotationValue.builder(Put.class); case PATCH: return AnnotationValue.builder(Patch.class); case OPTIONS: return AnnotationValue.builder(Options.class); default: return AnnotationValue.builder("io.micronaut.http.annotation.UriMapping"); } } else { return AnnotationValue.builder("io.micronaut.http.annotation.UriMapping"); } }
Example #6
Source File: PatchMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected AnnotationValueBuilder<?> newBuilder(HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { return AnnotationValue.builder(Patch.class); }
Example #7
Source File: PatchMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected boolean isHttpMethodMapping(HttpMethod method) { return true; }
Example #8
Source File: DeleteMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected AnnotationValueBuilder<?> newBuilder(HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { return AnnotationValue.builder(Delete.class); }
Example #9
Source File: DeleteMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected boolean isHttpMethodMapping(HttpMethod method) { return true; }
Example #10
Source File: GetMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected AnnotationValueBuilder<?> newBuilder(HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { return AnnotationValue.builder(Get.class); }
Example #11
Source File: GetMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected boolean isHttpMethodMapping(HttpMethod method) { return true; }
Example #12
Source File: PutMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected AnnotationValueBuilder<?> newBuilder(HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { return AnnotationValue.builder(Put.class); }
Example #13
Source File: PutMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected boolean isHttpMethodMapping(HttpMethod method) { return true; }
Example #14
Source File: PostMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected AnnotationValueBuilder<?> newBuilder(HttpMethod httpMethod, AnnotationValue<Annotation> annotation) { return AnnotationValue.builder(Post.class); }
Example #15
Source File: PostMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 4 votes |
@Override protected boolean isHttpMethodMapping(HttpMethod method) { return true; }
Example #16
Source File: RequestMappingAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 2 votes |
/** * Whether the given method is an HTTP method mapping. * @param method The method, can be null * @return True if it is */ protected boolean isHttpMethodMapping(@Nullable HttpMethod method) { return method != null; }