com.linecorp.armeria.server.annotation.Param Java Examples
The following examples show how to use
com.linecorp.armeria.server.annotation.Param.
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: ArmeriaUserServiceServerImpl.java From rpc-benchmark with Apache License 2.0 | 6 votes |
@Get("/get-user") public HttpResponse getUser(@Param("id") long id) throws JsonProcessingException { User user = new User(); user.setId(id); user.setName("Doug Lea"); user.setSex(1); user.setBirthday(LocalDate.of(1968, 12, 8)); user.setEmail("[email protected]"); user.setMobile("18612345678"); user.setAddress("北京市 中关村 中关村大街1号 鼎好大厦 1605"); user.setIcon("https://www.baidu.com/img/bd_logo1.png"); user.setStatus(1); user.setCreateTime(LocalDateTime.now()); user.setUpdateTime(user.getCreateTime()); List<Integer> permissions = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6, 7, 8, 19, 88, 86, 89, 90, 91, 92)); user.setPermissions(permissions); return HttpResponse.of(objectMapper.writeValueAsString(user)); }
Example #2
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traces/:trace_id") public AggregatedHttpResponse getTrace(@Param("trace_id") String traceId) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<Span> spans = store.get(traceId); return AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON, SpanBytesEncoder.JSON_V2.encodeList(spans)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example #3
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traceMany") public AggregatedHttpResponse getTraces(@Param("traceIds") String traceIds) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<List<Span>> result = new ArrayList<>(); for (String traceId : traceIds.split(",", 1000)) { result.add(store.get(traceId)); } return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, writeTraces(result)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example #4
Source File: AnnotatedValueResolverTest.java From armeria with Apache License 2.0 | 6 votes |
void method1(@Param String var1, @Param String param1, @Param @Default("1") int param2, @Param @Default("1") List<Integer> param3, @Header List<String> header1, @Header("header1") Optional<List<ValueEnum>> optionalHeader1, @Header String header2, @Header @Default("defaultValue") List<String> header3, @Header @Default("defaultValue") String header4, @Param CaseInsensitiveEnum enum1, @Param @Default("enum2") CaseInsensitiveEnum enum2, @Param("sensitive") CaseSensitiveEnum enum3, @Param("SENSITIVE") @Default("SENSITIVE") CaseSensitiveEnum enum4, @Param @Default("P1Y2M3W4D") Period period, ServiceRequestContext ctx, HttpRequest request, @RequestObject OuterBean outerBean, Cookies cookies) {}
Example #5
Source File: RepositoryService.java From centraldogma with Apache License 2.0 | 6 votes |
/** * POST|PUT /projects/{projectName}/repositories/{repoName}/files/revisions/{revision} * Adds a new file or edits the existing file. */ @Post @Put @Path("/projects/{projectName}/repositories/{repoName}/files/revisions/{revision}") @RequiresWritePermission public CompletionStage<Object> addOrEditFile(@Param String projectName, @Param String repoName, @Param String revision, AggregatedHttpRequest request, ServiceRequestContext ctx) { final Entry<CommitMessageDto, Change<?>> p = commitMessageAndChange(request); final CommitMessageDto commitMessage = p.getKey(); final Change<?> change = p.getValue(); return push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), change) // This is so weird but there is no way to find a converter for 'null' with the current // Armeria's converter implementation. We will figure out a better way to improve it. .thenApply(unused -> VOID); }
Example #6
Source File: RepositoryService.java From centraldogma with Apache License 2.0 | 6 votes |
/** * POST /projects/{projectName}/repositories/{repoName}/delete/revisions/{revision}{path} * Deletes a file. */ @Post("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/delete/revisions/(?<revision>[^/]+)(?<path>/.*$)") @RequiresWritePermission public HttpResponse deleteFile(@Param String projectName, @Param String repoName, @Param String revision, @Param String path, AggregatedHttpRequest request, ServiceRequestContext ctx) { final CommitMessageDto commitMessage; try { final JsonNode node = Jackson.readTree(request.contentUtf8()); commitMessage = Jackson.convertValue(node.get("commitMessage"), CommitMessageDto.class); } catch (IOException e) { throw new IllegalArgumentException("invalid data to be parsed", e); } final CompletableFuture<?> future = push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), Change.ofRemoval(path)); return HttpResponse.from(future.thenApply(unused -> HttpResponse.of(HttpStatus.OK))); }
Example #7
Source File: RepositoryService.java From centraldogma with Apache License 2.0 | 6 votes |
/** * GET /projects/{projectName}/repositories/{repoName}/history{path}?from=x.x&to=x.x * Returns a history between the specified revisions. */ @Get("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/history(?<path>/.*$)") public CompletionStage<List<CommitDto>> getHistory(@Param String projectName, @Param String repoName, @Param String path, @Param @Default("-1") String from, @Param @Default("1") String to) { return projectManager().get(projectName).repos().get(repoName) .history(new Revision(from), new Revision(to), path + "**") .thenApply(commits -> commits.stream() .map(DtoConverter::convert) .collect(toList())); }
Example #8
Source File: ServiceRoutingTest.java From armeria with Apache License 2.0 | 6 votes |
@Override protected void configure(ServerBuilder sb) throws Exception { sb.annotatedService("/api/v0/", new Object() { @Get("/users/me") public String me() { return "me"; } }); sb.annotatedService("/api/v0/", new Object() { @Get("regex:/projects/(?<projectName>[^/]+)") public String project(@Param("projectName") String projectName) { return "project"; } }); sb.serviceUnder("/", (ctx, req) -> HttpResponse.of("fallback")); }
Example #9
Source File: AnnotatedElementNameUtil.java From armeria with Apache License 2.0 | 6 votes |
private static String getName(Object element) { if (element instanceof Parameter) { final Parameter parameter = (Parameter) element; if (!parameter.isNamePresent()) { throw new IllegalArgumentException( "cannot obtain the name of the parameter or field automatically. " + "Please make sure you compiled your code with '-parameters' option. " + "If not, you need to specify parameter and header names with @" + Param.class.getSimpleName() + " and @" + Header.class.getSimpleName() + '.'); } return parameter.getName(); } if (element instanceof Field) { return ((Field) element).getName(); } throw new IllegalArgumentException("cannot find the name: " + element.getClass().getName()); }
Example #10
Source File: ServiceRoutingTest.java From armeria with Apache License 2.0 | 6 votes |
@Override protected void configure(ServerBuilder sb) throws Exception { sb.serviceUnder("/", (ctx, req) -> HttpResponse.of("fallback")); sb.annotatedService("/api/v0/", new Object() { @Get("/users/me") public String me() { return "me"; } }); sb.annotatedService("/api/v0/", new Object() { @Get("regex:/projects/(?<projectName>[^/]+)") public String project(@Param("projectName") String projectName) { return "project"; } }); }
Example #11
Source File: AnnotatedValueResolver.java From armeria with Apache License 2.0 | 6 votes |
private static AnnotatedValueResolver ofQueryParam(String name, AnnotatedElement annotatedElement, AnnotatedElement typeElement, Class<?> type, @Nullable String description) { return new Builder(annotatedElement, type) .annotationType(Param.class) .httpElementName(name) .typeElement(typeElement) .supportDefault(true) .supportContainer(true) .description(description) .aggregation(AggregationStrategy.FOR_FORM_DATA) .resolver(resolver(ctx -> ctx.queryParams().getAll(name), () -> "Cannot resolve a value from a query parameter: " + name)) .build(); }
Example #12
Source File: TokenService.java From centraldogma with Apache License 2.0 | 6 votes |
/** * PATCH /tokens/{appId} * * <p>Activates or deactivates the token of the specified {@code appId}. */ @Patch("/tokens/{appId}") @Consumes("application/json-patch+json") public CompletableFuture<Token> updateToken(ServiceRequestContext ctx, @Param String appId, JsonNode node, Author author, User loginUser) { if (node.equals(activation)) { return getTokenOrRespondForbidden(ctx, appId, loginUser).thenCompose( token -> mds.activateToken(author, appId) .thenApply(unused -> token.withoutSecret())); } if (node.equals(deactivation)) { return getTokenOrRespondForbidden(ctx, appId, loginUser).thenCompose( token -> mds.deactivateToken(author, appId) .thenApply(unused -> token.withoutSecret())); } throw new IllegalArgumentException("Unsupported JSON patch: " + node + " (expected: " + activation + " or " + deactivation + ')'); }
Example #13
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/serviceNames/:service_name/spanNames") @ProducesJson public JsonNode getSpanNames(@Param("service_name") String serviceName) { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, Set<String>> store = storage.getTraceStorageStream() .store(SPAN_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore()); Set<String> names = store.get(serviceName); ArrayNode array = MAPPER.createArrayNode(); if (names != null) names.forEach(array::add); return array; } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #14
Source File: AnnotatedBeanFactoryRegistryTest.java From armeria with Apache License 2.0 | 5 votes |
void initParams(@Param("param1") String param1, String param2, @Header("header1") int header1, int header2) { this.param1 = param1; this.param2 = param2; this.header1 = header1; this.header2 = header2; }
Example #15
Source File: AnnotatedValueResolver.java From armeria with Apache License 2.0 | 5 votes |
private static AnnotatedValueResolver ofPathVariable(String name, AnnotatedElement annotatedElement, AnnotatedElement typeElement, Class<?> type, @Nullable String description) { return new Builder(annotatedElement, type) .annotationType(Param.class) .httpElementName(name) .typeElement(typeElement) .pathVariable(true) .description(description) .resolver(resolver(ctx -> ctx.context().pathParam(name))) .build(); }
Example #16
Source File: AnnotatedDocServicePlugin.java From armeria with Apache License 2.0 | 5 votes |
private static FieldLocation location(AnnotatedValueResolver resolver) { if (resolver.isPathVariable()) { return PATH; } if (resolver.annotationType() == Param.class) { return QUERY; } if (resolver.annotationType() == Header.class) { return HEADER; } return UNSPECIFIED; }
Example #17
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Get("/param/enum") public String paramEnum(RequestContext ctx, @Param("username") String username, @Param("level") UserLevel level) { validateContext(ctx); return username + '/' + level; }
Example #18
Source File: AnnotatedElementNameUtil.java From armeria with Apache License 2.0 | 5 votes |
/** * Returns the value of the {@link Param} annotation which is specified on the {@code element} if * the value is not blank. If the value is blank, it returns the name of the specified * {@code nameRetrievalTarget} object which is an instance of {@link Parameter} or {@link Field}. */ static String findName(Param param, Object nameRetrievalTarget) { requireNonNull(nameRetrievalTarget, "nameRetrievalTarget"); final String value = param.value(); if (DefaultValues.isSpecified(value)) { checkArgument(!value.isEmpty(), "value is empty."); return value; } return getName(nameRetrievalTarget); }
Example #19
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Get @Path("/path/ctx/async/:var") public static CompletableFuture<String> returnPathCtxAsync(@Param int var, ServiceRequestContext ctx, Request req) { validateContextAndRequest(ctx, req); return CompletableFuture.completedFuture(ctx.path()); }
Example #20
Source File: ArmeriaUserServiceServerImpl.java From rpc-benchmark with Apache License 2.0 | 5 votes |
@Get("/user-exist") public HttpResponse existUser(@Param("email") String email) { if (email == null || email.isEmpty()) { return HttpResponse.of(String.valueOf(Boolean.TRUE)); } if (email.charAt(email.length() - 1) < '5') { return HttpResponse.of(String.valueOf(Boolean.FALSE)); } return HttpResponse.of(String.valueOf(Boolean.TRUE)); }
Example #21
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * DELETE /metadata/{projectName}/repos/{repoName}/perm/tokens/{appId} * * <p>Removes {@link Permission}s of the specified {@code appId} from the specified {@code repoName} * in the specified {@code projectName}. */ @Delete("/metadata/{projectName}/repos/{repoName}/perm/tokens/{appId}") public CompletableFuture<Revision> removeSpecificTokenPermission(@Param String projectName, @Param String repoName, @Param String appId, Author author) { return mds.findTokenByAppId(appId) .thenCompose(token -> mds.removePerTokenPermission(author, projectName, repoName, appId)); }
Example #22
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * PATCH /metadata/{projectName}/repos/{repoName}/perm/tokens/{appId} * * <p>Updates {@link Permission}s for the specified {@code appId} of the specified {@code repoName} * in the specified {@code projectName}. */ @Patch("/metadata/{projectName}/repos/{repoName}/perm/tokens/{appId}") @Consumes("application/json-patch+json") public CompletableFuture<Revision> updateSpecificTokenPermission(@Param String projectName, @Param String repoName, @Param String appId, JsonPatch jsonPatch, Author author) { final ReplaceOperation operation = ensureSingleReplaceOperation(jsonPatch, "/permissions"); final Collection<Permission> permissions = Jackson.convertValue(operation.value(), permissionsTypeRef); return mds.findTokenByAppId(appId) .thenCompose(token -> mds.updatePerTokenPermission( author, projectName, repoName, appId, permissions)); }
Example #23
Source File: AnnotatedBeanFactoryRegistryTest.java From armeria with Apache License 2.0 | 5 votes |
BadRequestBeanSomeConstructorParamWithoutAnnotation(@Param("param1") String param1, String param2, @Header("header1") int header1, int header2) { this.param1 = param1; this.param2 = param2; this.header1 = header1; this.header2 = header2; }
Example #24
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * DELETE /metadata/{projectName}/repos/{repoName}/perm/users/{memberId} * * <p>Removes {@link Permission}s for the specified {@code memberId} from the specified {@code repoName} * in the specified {@code projectName}. */ @Delete("/metadata/{projectName}/repos/{repoName}/perm/users/{memberId}") public CompletableFuture<Revision> removeSpecificUserPermission(@Param String projectName, @Param String repoName, @Param String memberId, Author author) { final User member = new User(loginNameNormalizer.apply(urlDecode(memberId))); return mds.findPermissions(projectName, repoName, member) .thenCompose(unused -> mds.removePerUserPermission(author, projectName, repoName, member)); }
Example #25
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Get("/param/get") public String paramGet(RequestContext ctx, @Param("username") String username, @Param("password") String password) { validateContext(ctx); return username + '/' + password; }
Example #26
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * DELETE /metadata/{projectName}/tokens/{appId} * * <p>Removes the {@link Token} of the specified {@code appId} from the specified {@code projectName}. */ @Delete("/metadata/{projectName}/tokens/{appId}") public CompletableFuture<Revision> removeToken(@Param String projectName, @Param String appId, Author author) { return mds.findTokenByAppId(appId) .thenCompose(token -> mds.removeToken(author, projectName, token.appId())); }
Example #27
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * PATCH /metadata/{projectName}/tokens/{appId} * * <p>Updates the {@link ProjectRole} of the {@link Token} of the specified {@code appId} * in the specified {@code projectName}. */ @Patch("/metadata/{projectName}/tokens/{appId}") @Consumes("application/json-patch+json") public CompletableFuture<Revision> updateTokenRole(@Param String projectName, @Param String appId, JsonPatch jsonPatch, Author author) { final ReplaceOperation operation = ensureSingleReplaceOperation(jsonPatch, "/role"); final ProjectRole role = ProjectRole.of(operation.value()); return mds.findTokenByAppId(appId) .thenCompose(token -> mds.updateTokenRole(author, projectName, token, role)); }
Example #28
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * POST /metadata/{projectName}/tokens * * <p>Adds a {@link Token} to the specified {@code projectName}. */ @Post("/metadata/{projectName}/tokens") public CompletableFuture<Revision> addToken(@Param String projectName, IdentifierWithRole request, Author author) { final ProjectRole role = toProjectRole(request.role()); return mds.findTokenByAppId(request.id()) .thenCompose(token -> mds.addToken(author, projectName, token.appId(), role)); }
Example #29
Source File: MetadataApiService.java From centraldogma with Apache License 2.0 | 5 votes |
/** * DELETE /metadata/{projectName}/members/{memberId} * * <p>Removes the specified {@code memberId} from the specified {@code projectName}. */ @Delete("/metadata/{projectName}/members/{memberId}") public CompletableFuture<Revision> removeMember(@Param String projectName, @Param String memberId, Author author) { final User member = new User(loginNameNormalizer.apply(urlDecode(memberId))); return mds.getMember(projectName, member) .thenCompose(unused -> mds.removeMember(author, projectName, member)); }
Example #30
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Get @Path("/param/precedence/{username}") public String paramPrecedence(RequestContext ctx, @Param("username") String username, @Param("password") String password) { validateContext(ctx); return username + '/' + password; }