com.linecorp.armeria.server.Route Java Examples
The following examples show how to use
com.linecorp.armeria.server.Route.
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: EurekaUpdatingListener.java From armeria with Apache License 2.0 | 6 votes |
@Nullable private static String healthCheckUrl(String hostnameOrIpAddr, @Nullable String oldHealthCheckUrl, PortWrapper portWrapper, Optional<ServiceConfig> healthCheckService, SessionProtocol sessionProtocol) { if (oldHealthCheckUrl != null) { return oldHealthCheckUrl; } if (!portWrapper.isEnabled() || !healthCheckService.isPresent()) { return null; } final ServiceConfig healthCheckServiceConfig = healthCheckService.get(); final Route route = healthCheckServiceConfig.route(); if (route.pathType() != RoutePathType.EXACT && route.pathType() != RoutePathType.PREFIX) { return null; } return sessionProtocol.uriText() + "://" + hostnameOrIpAddr(hostnameOrIpAddr) + ':' + portWrapper.getPort() + route.paths().get(0); }
Example #2
Source File: ThriftDocServicePluginTest.java From armeria with Apache License 2.0 | 6 votes |
private static Map<String, ServiceInfo> services(DocServiceFilter include, DocServiceFilter exclude) { final Server server = Server.builder() .service(Route.builder() .exact("/hello") .build(), THttpService.of(mock(AsyncIface.class))) .service(Route.builder() .exact("/foo") .build(), THttpService.ofFormats(mock(FooService.AsyncIface.class), ThriftSerializationFormats.COMPACT)) .build(); // Generate the specification with the ServiceConfigs. final ServiceSpecification specification = generator.generateSpecification( ImmutableSet.copyOf(server.serviceConfigs()), unifyFilter(include, exclude)); // Ensure the specification contains all services. return specification.services() .stream() .collect(toImmutableMap(ServiceInfo::name, Function.identity())); }
Example #3
Source File: CorsPolicy.java From armeria with Apache License 2.0 | 6 votes |
static String toString(Object obj, @Nullable Set<String> origins, List<Route> routes, boolean nullOriginAllowed, boolean credentialsAllowed, long maxAge, @Nullable Set<AsciiString> exposedHeaders, @Nullable Set<HttpMethod> allowedRequestMethods, @Nullable Set<AsciiString> allowedRequestHeaders, @Nullable Map<AsciiString, Supplier<?>> preflightResponseHeaders) { return MoreObjects.toStringHelper(obj) .omitNullValues() .add("origins", origins) .add("routes", routes) .add("nullOriginAllowed", nullOriginAllowed) .add("credentialsAllowed", credentialsAllowed) .add("maxAge", maxAge) .add("exposedHeaders", exposedHeaders) .add("allowedRequestMethods", allowedRequestMethods) .add("allowedRequestHeaders", allowedRequestHeaders) .add("preflightResponseHeaders", preflightResponseHeaders).toString(); }
Example #4
Source File: AnnotatedDocServicePlugin.java From armeria with Apache License 2.0 | 6 votes |
private static void addMethodInfo(Map<Class<?>, Set<MethodInfo>> methodInfos, String hostnamePattern, AnnotatedService service) { final Route route = service.route(); final EndpointInfo endpoint = endpointInfo(route, hostnamePattern); final Method method = service.method(); final String name = method.getName(); final TypeSignature returnTypeSignature = toTypeSignature(method.getGenericReturnType()); final List<FieldInfo> fieldInfos = fieldInfos(service.annotatedValueResolvers()); final Class<?> clazz = service.object().getClass(); route.methods().forEach( httpMethod -> { final MethodInfo methodInfo = new MethodInfo( name, returnTypeSignature, fieldInfos, ImmutableList.of(), // Ignore exceptions. ImmutableList.of(endpoint), httpMethod, AnnotatedServiceFactory .findDescription(method)); methodInfos.computeIfAbsent(clazz, unused -> new HashSet<>()).add(methodInfo); }); }
Example #5
Source File: GrpcServiceBuilder.java From armeria with Apache License 2.0 | 6 votes |
/** * Constructs a new {@link GrpcService} that can be bound to * {@link ServerBuilder}. It is recommended to bind the service to a server using * {@linkplain ServerBuilder#service(HttpServiceWithRoutes, Function[]) * ServerBuilder.service(HttpServiceWithRoutes)} to mount all service paths * without interfering with other services. */ public GrpcService build() { final HandlerRegistry handlerRegistry = registryBuilder.build(); final GrpcService grpcService = new FramedGrpcService( handlerRegistry, handlerRegistry .methods() .keySet() .stream() .map(path -> Route.builder().exact('/' + path).build()) .collect(ImmutableSet.toImmutableSet()), firstNonNull(decompressorRegistry, DecompressorRegistry.getDefaultInstance()), firstNonNull(compressorRegistry, CompressorRegistry.getDefaultInstance()), supportedSerializationFormats, jsonMarshallerFactory, protoReflectionServiceInterceptor, maxOutboundMessageSizeBytes, useBlockingTaskExecutor, unsafeWrapRequestBuffers, useClientTimeoutHeader, maxInboundMessageSizeBytes); return enableUnframedRequests ? new UnframedGrpcService(grpcService) : grpcService; }
Example #6
Source File: AnnotatedDocServicePlugin.java From armeria with Apache License 2.0 | 6 votes |
private static String normalizeParameterized(Route route) { final String path = route.paths().get(0); int beginIndex = 0; final StringBuilder sb = new StringBuilder(); for (String paramName : route.paramNames()) { final int colonIndex = path.indexOf(':', beginIndex); assert colonIndex != -1; sb.append(path, beginIndex, colonIndex); sb.append('{'); sb.append(paramName); sb.append('}'); beginIndex = colonIndex + 1; } if (beginIndex < path.length()) { sb.append(path, beginIndex, path.length()); } return sb.toString(); }
Example #7
Source File: ArmeriaReactiveWebServerFactory.java From armeria with Apache License 2.0 | 6 votes |
private static ServerBuilder configureService(ServerBuilder sb, HttpHandler httpHandler, DataBufferFactoryWrapper<?> factoryWrapper, @Nullable String serverHeader) { final ArmeriaHttpHandlerAdapter handler = new ArmeriaHttpHandlerAdapter(httpHandler, factoryWrapper); return sb.service(Route.ofCatchAll(), (ctx, req) -> { final CompletableFuture<HttpResponse> future = new CompletableFuture<>(); final HttpResponse response = HttpResponse.from(future); final Disposable disposable = handler.handle(ctx, req, future, serverHeader).subscribe(); response.whenComplete().handle((unused, cause) -> { if (cause != null) { if (ctx.method() != HttpMethod.HEAD) { logger.debug("{} Response stream has been cancelled.", ctx, cause); } disposable.dispose(); } return null; }); return response; }); }
Example #8
Source File: AnnotatedServiceFactoryTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void testMultiPathAnnotations() { final List<AnnotatedServiceElement> getServiceElements = getServiceElements( new MultiPathSuccessService(), "multiPathAnnotations", HttpMethod.GET); final Set<Route> getRoutes = getServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(getRoutes).containsOnly(Route.builder().path("/path1").methods(HttpMethod.GET).build(), Route.builder().path("/path2").methods(HttpMethod.GET).build()); final List<AnnotatedServiceElement> postServiceElements = getServiceElements( new MultiPathSuccessService(), "multiPathAnnotations", HttpMethod.POST); final Set<Route> postRoutes = postServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(postRoutes).containsOnly(Route.builder().path("/path1").methods(HttpMethod.POST).build(), Route.builder().path("/path2").methods(HttpMethod.POST).build()); }
Example #9
Source File: RoutingConfigLoader.java From curiostack with MIT License | 6 votes |
Map<Route, WebClient> load(Path configPath) { final RoutingConfig config; try { config = OBJECT_MAPPER.readValue(configPath.toFile(), RoutingConfig.class); } catch (IOException e) { throw new UncheckedIOException("Could not read routing config.", e); } Map<String, WebClient> clients = config.getTargets().stream() .collect( toImmutableMap( Target::getName, t -> clientBuilderFactory .create(t.getName(), addSerializationFormat(t.getUrl())) .build(WebClient.class))); return config.getRules().stream() .collect( toImmutableMap( r -> Route.builder().path(r.getPathPattern()).build(), r -> clients.get(r.getTarget()))); }
Example #10
Source File: AnnotatedServiceFactoryTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void testDuplicatePathAnnotations() { final List<AnnotatedServiceElement> getServiceElements = getServiceElements( new MultiPathSuccessService(), "duplicatePathAnnotations", HttpMethod.GET); Assertions.assertThat(getServiceElements).hasSize(2); final Set<Route> getRoutes = getServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(getRoutes).containsOnly(Route.builder().path("/path").methods(HttpMethod.GET).build(), Route.builder().path("/path").methods(HttpMethod.GET).build()); final List<AnnotatedServiceElement> postServiceElements = getServiceElements( new MultiPathSuccessService(), "duplicatePathAnnotations", HttpMethod.POST); Assertions.assertThat(getServiceElements).hasSize(2); final Set<Route> postRoutes = postServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(postRoutes).containsOnly(Route.builder().path("/path").methods(HttpMethod.POST).build(), Route.builder().path("/path").methods(HttpMethod.POST).build()); }
Example #11
Source File: SamlServiceProvider.java From armeria with Apache License 2.0 | 5 votes |
/** * A class which helps a {@link Server} have a SAML-based authentication. */ SamlServiceProvider(Authorizer<HttpRequest> authorizer, String entityId, @Nullable String hostname, Credential signingCredential, Credential encryptionCredential, String signatureAlgorithm, SamlPortConfigAutoFiller portConfigAutoFiller, String metadataPath, Map<String, SamlIdentityProviderConfig> idpConfigs, @Nullable SamlIdentityProviderConfig defaultIdpConfig, SamlIdentityProviderConfigSelector idpConfigSelector, Collection<SamlAssertionConsumerConfig> acsConfigs, Collection<SamlEndpoint> sloEndpoints, SamlRequestIdManager requestIdManager, SamlSingleSignOnHandler ssoHandler, SamlSingleLogoutHandler sloHandler) { this.authorizer = requireNonNull(authorizer, "authorizer"); this.entityId = requireNonNull(entityId, "entityId"); this.hostname = hostname; this.signingCredential = requireNonNull(signingCredential, "signingCredential"); this.encryptionCredential = requireNonNull(encryptionCredential, "encryptionCredential"); this.signatureAlgorithm = requireNonNull(signatureAlgorithm, "signatureAlgorithm"); this.portConfigAutoFiller = requireNonNull(portConfigAutoFiller, "portConfigAutoFiller"); metadataRoute = Route.builder().exact(requireNonNull(metadataPath, "metadataPath")).build(); this.idpConfigs = ImmutableMap.copyOf(requireNonNull(idpConfigs, "idpConfigs")); this.defaultIdpConfig = defaultIdpConfig; this.idpConfigSelector = requireNonNull(idpConfigSelector, "idpConfigSelector"); this.acsConfigs = ImmutableList.copyOf(requireNonNull(acsConfigs, "acsConfigs")); this.sloEndpoints = ImmutableList.copyOf(requireNonNull(sloEndpoints, "sloEndpoints")); this.requestIdManager = requireNonNull(requestIdManager, "requestIdManager"); this.ssoHandler = requireNonNull(ssoHandler, "ssoHandler"); this.sloHandler = requireNonNull(sloHandler, "sloHandler"); defaultAcsConfig = acsConfigs.stream().filter(SamlAssertionConsumerConfig::isDefault).findFirst() .orElseThrow(() -> new IllegalArgumentException( "no default assertion consumer config")); }
Example #12
Source File: ServerRequestContextAdapterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void route() { final HttpServerRequest res = newRouteRequest(Route.builder() .path("/foo/:bar/hoge") .build()); assertThat(res.route()).isEqualTo("/foo/:/hoge"); }
Example #13
Source File: ArmeriaSpringActuatorAutoConfiguration.java From armeria with Apache License 2.0 | 5 votes |
private static Route route( String method, String path, Collection<String> consumes, Collection<String> produces) { return Route.builder() .path(path) .methods(ImmutableSet.of(HttpMethod.valueOf(method))) .consumes(convertMediaTypes(consumes)) .produces(convertMediaTypes(produces)) .build(); }
Example #14
Source File: ServerRequestContextAdapterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void route_prefix() { final HttpServerRequest res = newRouteRequest(Route.builder() .path("exact:/foo") .build()); assertThat(res.route()).isEqualTo("/foo"); }
Example #15
Source File: SamlService.java From armeria with Apache License 2.0 | 5 votes |
SamlService(SamlServiceProvider sp) { this.sp = requireNonNull(sp, "sp"); portConfigHolder = sp.portConfigAutoFiller(); final ImmutableMap.Builder<String, SamlServiceFunction> builder = new Builder<>(); sp.acsConfigs().forEach( cfg -> builder.put(cfg.endpoint().uri().getPath(), new SamlAssertionConsumerFunction(cfg, sp.entityId(), sp.idpConfigs(), sp.defaultIdpConfig(), sp.requestIdManager(), sp.ssoHandler()))); sp.sloEndpoints().forEach( cfg -> builder.put(cfg.uri().getPath(), new SamlSingleLogoutFunction(cfg, sp.entityId(), sp.signingCredential(), sp.signatureAlgorithm(), sp.idpConfigs(), sp.defaultIdpConfig(), sp.requestIdManager(), sp.sloHandler()))); final Route route = sp.metadataRoute(); if (route.pathType() == RoutePathType.EXACT) { builder.put(route.paths().get(0), new SamlMetadataServiceFunction(sp.entityId(), sp.signingCredential(), sp.encryptionCredential(), sp.idpConfigs(), sp.acsConfigs(), sp.sloEndpoints())); } serviceMap = builder.build(); routes = serviceMap.keySet() .stream() .map(path -> Route.builder().exact(path).build()) .collect(toImmutableSet()); }
Example #16
Source File: CorsPolicy.java From armeria with Apache License 2.0 | 5 votes |
CorsPolicy(Set<String> origins, List<Route> routes, boolean credentialsAllowed, long maxAge, boolean nullOriginAllowed, Set<AsciiString> exposedHeaders, Set<AsciiString> allowedRequestHeaders, EnumSet<HttpMethod> allowedRequestMethods, boolean preflightResponseHeadersDisabled, Map<AsciiString, Supplier<?>> preflightResponseHeaders) { this.origins = ImmutableSet.copyOf(origins); this.routes = ImmutableList.copyOf(routes); this.credentialsAllowed = credentialsAllowed; this.maxAge = maxAge; this.nullOriginAllowed = nullOriginAllowed; this.exposedHeaders = ImmutableSet.copyOf(exposedHeaders); this.allowedRequestMethods = ImmutableSet.copyOf(allowedRequestMethods); this.allowedRequestHeaders = ImmutableSet.copyOf(allowedRequestHeaders); joinedExposedHeaders = HEADER_JOINER.join(this.exposedHeaders); joinedAllowedRequestMethods = this.allowedRequestMethods .stream().map(HttpMethod::name).collect(Collectors.joining(DELIMITER)); joinedAllowedRequestHeaders = HEADER_JOINER.join(this.allowedRequestHeaders); if (preflightResponseHeadersDisabled) { this.preflightResponseHeaders = Collections.emptyMap(); } else if (preflightResponseHeaders.isEmpty()) { this.preflightResponseHeaders = ImmutableMap.of( HttpHeaderNames.DATE, HttpTimestampSupplier::currentTime, HttpHeaderNames.CONTENT_LENGTH, ConstantValueSupplier.ZERO); } else { this.preflightResponseHeaders = ImmutableMap.copyOf(preflightResponseHeaders); } }
Example #17
Source File: FramedGrpcServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Test public void routes() throws Exception { assertThat(grpcService.routes()) .containsExactlyInAnyOrder( Route.builder().exact("/armeria.grpc.testing.TestService/EmptyCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/UnaryCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/UnaryCall2").build(), Route.builder().exact("/armeria.grpc.testing.TestService/StreamingOutputCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/StreamingInputCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/FullDuplexCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/HalfDuplexCall").build(), Route.builder().exact("/armeria.grpc.testing.TestService/UnimplementedCall").build()); }
Example #18
Source File: GrpcDocServicePluginTest.java From armeria with Apache License 2.0 | 5 votes |
private static Map<String, ServiceInfo> services(DocServiceFilter include, DocServiceFilter exclude) { final ServerBuilder serverBuilder = Server.builder(); // The case where a GrpcService is added to ServerBuilder without a prefix. final HttpServiceWithRoutes prefixlessService = GrpcService.builder() .addService(mock(TestServiceImplBase.class)) .build(); serverBuilder.service(prefixlessService); // The case where a GrpcService is added to ServerBuilder with a prefix. serverBuilder.service( Route.builder().pathPrefix("/test").build(), GrpcService.builder().addService(mock(UnitTestServiceImplBase.class)).build()); // Another GrpcService with a different prefix. serverBuilder.service( Route.builder().pathPrefix("/reconnect").build(), GrpcService.builder().addService(mock(ReconnectServiceImplBase.class)).build()); // Make sure all services and their endpoints exist in the specification. final ServiceSpecification specification = generator.generateSpecification( ImmutableSet.copyOf(serverBuilder.build().serviceConfigs()), unifyFilter(include, exclude)); return specification .services() .stream() .collect(toImmutableMap(ServiceInfo::name, Function.identity())); }
Example #19
Source File: ArmeriaOkServiceConfiguration.java From armeria with Apache License 2.0 | 5 votes |
@Bean public HttpServiceRegistrationBean okService() { return new HttpServiceRegistrationBean() .setServiceName("okService") .setService(new OkService()) .setRoute(Route.builder().path("/ok").build()) .setDecorators(ImmutableList.of(LoggingService.newDecorator())); }
Example #20
Source File: FileService.java From armeria with Apache License 2.0 | 5 votes |
@Override public boolean shouldCachePath(String path, @Nullable String query, Route route) { // No good way of propagating the first vs second decision to the cache decision, so just make a // best effort, it should work for most cases. return first.shouldCachePath(path, query, route) && second.shouldCachePath(path, query, route); }
Example #21
Source File: RoutingService.java From curiostack with MIT License | 5 votes |
@SuppressWarnings("ConstructorLeaksThis") RoutingService(Map<Route, WebClient> clients) { this.clients = clients; if (Flags.parsedPathCacheSpec() != null) { cachePaths = true; pathClients = Caffeine.from(Flags.parsedPathCacheSpec()).build(this::find); } else { cachePaths = false; pathClients = null; } }
Example #22
Source File: CorsConfig.java From armeria with Apache License 2.0 | 5 votes |
private static boolean isPathMatched(CorsPolicy policy, RoutingContext routingContext) { final List<Route> routes = policy.routes(); // We do not consider the score of the routing result for simplicity. It'd be enough to find // whether the path is matched or not. return routes.isEmpty() || routes.stream().anyMatch(route -> route.apply(routingContext).isPresent()); }
Example #23
Source File: AbstractCompositeService.java From armeria with Apache License 2.0 | 5 votes |
@Override public void serviceAdded(ServiceConfig cfg) throws Exception { checkState(server == null, "cannot be added to more than one server"); server = cfg.server(); final Route route = cfg.route(); if (route.pathType() != RoutePathType.PREFIX) { throw new IllegalStateException("The path type of the route must be " + RoutePathType.PREFIX + ", path type: " + route.pathType()); } router = Routers.ofCompositeService(services); final MeterRegistry registry = server.meterRegistry(); final MeterIdPrefix meterIdPrefix; if (Flags.useLegacyMeterNames()) { meterIdPrefix = new MeterIdPrefix("armeria.server.router.compositeServiceCache", "hostnamePattern", cfg.virtualHost().hostnamePattern(), "route", route.meterTag()); } else { meterIdPrefix = new MeterIdPrefix("armeria.server.router.composite.service.cache", "hostname.pattern", cfg.virtualHost().hostnamePattern(), "route", route.meterTag()); } router.registerMetrics(registry, meterIdPrefix); for (CompositeServiceEntry<T> e : services()) { ServiceCallbackInvoker.invokeServiceAdded(cfg, e.service()); } }
Example #24
Source File: AnnotatedDocServicePlugin.java From armeria with Apache License 2.0 | 5 votes |
@VisibleForTesting static EndpointInfo endpointInfo(Route route, String hostnamePattern) { final EndpointInfoBuilder builder; final RoutePathType pathType = route.pathType(); final List<String> paths = route.paths(); switch (pathType) { case EXACT: builder = EndpointInfo.builder(hostnamePattern, RouteUtil.EXACT + paths.get(0)); break; case PREFIX: builder = EndpointInfo.builder(hostnamePattern, RouteUtil.PREFIX + paths.get(0)); break; case PARAMETERIZED: builder = EndpointInfo.builder(hostnamePattern, normalizeParameterized(route)); break; case REGEX: builder = EndpointInfo.builder(hostnamePattern, RouteUtil.REGEX + paths.get(0)); break; case REGEX_WITH_PREFIX: builder = EndpointInfo.builder(hostnamePattern, RouteUtil.REGEX + paths.get(0)); builder.regexPathPrefix(RouteUtil.PREFIX + paths.get(1)); break; default: // Should never reach here. throw new Error(); } builder.availableMimeTypes(availableMimeTypes(route)); return builder.build(); }
Example #25
Source File: AnnotatedDocServicePlugin.java From armeria with Apache License 2.0 | 5 votes |
private static Set<MediaType> availableMimeTypes(Route route) { final ImmutableSet.Builder<MediaType> builder = ImmutableSet.builder(); final Set<MediaType> consumeTypes = route.consumes(); builder.addAll(consumeTypes); if (!consumeTypes.contains(MediaType.JSON_UTF_8)) { builder.add(MediaType.JSON_UTF_8); } return builder.build(); }
Example #26
Source File: AnnotatedServiceElement.java From armeria with Apache License 2.0 | 5 votes |
AnnotatedServiceElement(Route route, AnnotatedService service, Function<? super HttpService, ? extends HttpService> decorator) { this.route = requireNonNull(route, "route"); this.service = requireNonNull(service, "service"); this.decorator = requireNonNull(decorator, "decorator"); }
Example #27
Source File: CompositeServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Override protected void configure(ServerBuilder sb) throws Exception { sb.meterRegistry(PrometheusMeterRegistries.newRegistry()); sb.serviceUnder("/qux/", composite); // Should not hit the following services sb.serviceUnder("/foo/", otherService); sb.serviceUnder("/bar/", otherService); sb.service(Route.builder().glob("/*").build(), otherService); }
Example #28
Source File: AnnotatedServiceFactoryTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testMultiPathSuccessGetMapping() { final List<AnnotatedServiceElement> getServiceElements = getServiceElements(new MultiPathSuccessService(), "getMapping", HttpMethod.GET); final Set<Route> routes = getServiceElements.stream().map(AnnotatedServiceElement::route).collect( Collectors.toSet()); assertThat(routes).containsOnly(Route.builder().path("/getMapping").methods(HttpMethod.GET).build()); }
Example #29
Source File: AnnotatedServiceFactoryTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testMultiPathSuccessGetPostMapping() { final List<AnnotatedServiceElement> getServiceElements = getServiceElements( new MultiPathSuccessService(), "getPostMapping", HttpMethod.GET); final Set<Route> getRoutes = getServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(getRoutes).containsOnly(Route.builder().path("/getMapping").methods(HttpMethod.GET).build()); final List<AnnotatedServiceElement> postServiceElements = getServiceElements( new MultiPathSuccessService(), "getPostMapping", HttpMethod.POST); final Set<Route> postRoutes = postServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(postRoutes).containsOnly(Route.builder().path("/postMapping").methods(HttpMethod.POST) .build()); }
Example #30
Source File: AnnotatedServiceFactoryTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testMultiPathSuccessGetPostMappingByPath() { final List<AnnotatedServiceElement> getServiceElements = getServiceElements( new MultiPathSuccessService(), "getPostMappingByPath", HttpMethod.GET); final Set<Route> getRoutes = getServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(getRoutes).containsOnly(Route.builder().path("/path").methods(HttpMethod.GET).build()); final List<AnnotatedServiceElement> postServiceElements = getServiceElements( new MultiPathSuccessService(), "getPostMappingByPath", HttpMethod.POST); final Set<Route> postRoutes = postServiceElements.stream().map(AnnotatedServiceElement::route) .collect(Collectors.toSet()); assertThat(postRoutes).containsOnly(Route.builder().path("/path").methods(HttpMethod.POST).build()); }