/** * Creates a new {@link CompositeServiceEntry} whose {@link Service} is bound at the specified exact path. * * @see PathMapping#ofExact(String) */ public static <I extends Request, O extends Response> CompositeServiceEntry<I, O> ofExact(String exactPath, Service<I, O> service) { return new CompositeServiceEntry<>(PathMapping.ofExact(exactPath), service); }
/** * Creates a new {@link PathMapping} that matches a {@linkplain ServiceRequestContext#path() path} with * the specified glob expression, where {@code "*"} matches a path component non-recursively and * {@code "**"} matches path components recursively. */ static PathMapping ofGlob(String glob) { requireNonNull(glob, "glob"); if (glob.startsWith("/") && !glob.contains("*")) { // Does not have a pattern matcher. return ofExact(glob); } return new GlobPathMapping(glob); }
this.signatureAlgorithm = requireNonNull(signatureAlgorithm, "signatureAlgorithm"); this.portConfigAutoFiller = requireNonNull(portConfigAutoFiller, "portConfigAutoFiller"); this.metadataPath = PathMapping.ofExact(requireNonNull(metadataPath, "metadataPath")); this.idpConfigs = ImmutableMap.copyOf(requireNonNull(idpConfigs, "idpConfigs")); this.defaultIdpConfig = defaultIdpConfig;
@Test public void pathMappings() throws Exception { assertThat(grpcService.pathMappings()) .containsExactlyInAnyOrder( PathMapping.ofExact("/armeria.grpc.testing.TestService/EmptyCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/UnaryCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/UnaryCall2"), PathMapping.ofExact("/armeria.grpc.testing.TestService/StreamingOutputCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/StreamingInputCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/FullDuplexCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/HalfDuplexCall"), PathMapping.ofExact("/armeria.grpc.testing.TestService/UnimplementedCall")); } }
/** * Constructs a new {@link GrpcService} that can be bound to * {@link ServerBuilder}. It is recommended to bind the service to a server * using {@link ServerBuilder#service(ServiceWithPathMappings)} to mount all * service paths without interfering with other services. */ public ServiceWithPathMappings<HttpRequest, HttpResponse> build() { final HandlerRegistry handlerRegistry = registryBuilder.build(); final GrpcService grpcService = new GrpcService( handlerRegistry, handlerRegistry .methods() .keySet() .stream() .map(path -> PathMapping.ofExact('/' + path)) .collect(ImmutableSet.toImmutableSet()), firstNonNull(decompressorRegistry, DecompressorRegistry.getDefaultInstance()), firstNonNull(compressorRegistry, CompressorRegistry.getDefaultInstance()), supportedSerializationFormats, maxOutboundMessageSizeBytes, useBlockingTaskExecutor, unsafeWrapRequestBuffers, maxInboundMessageSizeBytes); return enableUnframedRequests ? grpcService.decorate(UnframedGrpcService::new) : grpcService; } }
return PathMapping.ofExact(concatPaths( pathPrefix, pattern.substring(EXACT.length())));
@Bean public HttpServiceRegistrationBean okService() { return new HttpServiceRegistrationBean() .setServiceName("okService") .setService(new OkService()) .setPathMapping(PathMapping.ofExact("/ok")) .setDecorators(ImmutableList.of(LoggingService.newDecorator())); }
@Bean public HttpServiceRegistrationBean okService() { return new HttpServiceRegistrationBean() .setServiceName("okService") .setService(new AbstractHttpService() { @Override protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) { return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "ok"); } }) .setPathMapping(PathMapping.ofExact("/ok")) .setDecorators(LoggingService.newDecorator()); } }
@Bean public HttpServiceRegistrationBean okService() { return new HttpServiceRegistrationBean() .setServiceName("okService") .setService(new AbstractHttpService() { @Override protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) throws Exception { return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "ok"); } }) .setPathMapping(PathMapping.ofExact("/ok")) .setDecorators(LoggingService.newDecorator()); } }
this.signatureAlgorithm = requireNonNull(signatureAlgorithm, "signatureAlgorithm"); this.portConfigAutoFiller = requireNonNull(portConfigAutoFiller, "portConfigAutoFiller"); this.metadataPath = PathMapping.ofExact(requireNonNull(metadataPath, "metadataPath")); this.idpConfigs = ImmutableMap.copyOf(requireNonNull(idpConfigs, "idpConfigs")); this.defaultIdpConfig = defaultIdpConfig;
/** * Constructs a new {@link GrpcService} that can be bound to * {@link ServerBuilder}. It is recommended to bind the service to a server * using {@link ServerBuilder#service(ServiceWithPathMappings)} to mount all * service paths without interfering with other services. */ public ServiceWithPathMappings<HttpRequest, HttpResponse> build() { final HandlerRegistry handlerRegistry = registryBuilder.build(); final GrpcService grpcService = new GrpcService( handlerRegistry, handlerRegistry .methods() .keySet() .stream() .map(path -> PathMapping.ofExact('/' + path)) .collect(ImmutableSet.toImmutableSet()), firstNonNull(decompressorRegistry, DecompressorRegistry.getDefaultInstance()), firstNonNull(compressorRegistry, CompressorRegistry.getDefaultInstance()), supportedSerializationFormats, maxOutboundMessageSizeBytes, useBlockingTaskExecutor, unsafeWrapRequestBuffers, maxInboundMessageSizeBytes); return enableUnframedRequests ? grpcService.decorate(UnframedGrpcService::new) : grpcService; } }