Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
}
"editor.formatOnSave": true,
"java.configuration.updateBuildConfiguration": "interactive"
}
50 changes: 27 additions & 23 deletions src/main/java/com/senzing/sdk/grpc/server/SzGrpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,21 +422,12 @@ protected SzGrpcServer(SzEnvironment env,
}
}

// build the GRPC service
GrpcService grpcService = GrpcService.builder()
.useBlockingTaskExecutor(true)
.addService(new SzGrpcProductImpl(this))
.addService(new SzGrpcConfigImpl(this))
.addService(new SzGrpcConfigManagerImpl(this))
.addService(new SzGrpcDiagnosticImpl(this))
.addService(new SzGrpcEngineImpl(this))
.build();

// create the server builder
ServerBuilder serverBuilder = Server.builder()
.http(new InetSocketAddress(bindAddress, port))
.blockingTaskExecutor(concurrency);

// create a CORS decorator if we need to decorate the server
// NOTE: we decorate the ENTIRE server rather than the GrpcService or
// AnnotatedService individually, because redirects (especially regarding
// paths ending "/") can lead to one path supporting CORS while the other
// does not. By using the decorator on the whole server, then all paths
// support CORS.
Function<? super HttpService, ? extends HttpService> corsDecorator = null;

List<String> allowedOrigins = options.getAllowedOrigins();
Expand All @@ -445,21 +436,39 @@ protected SzGrpcServer(SzEnvironment env,
corsDecorator = CorsService.builderForAnyOrigin()
.allowRequestMethods(GET, HEAD, POST, PUT, DELETE, OPTIONS)
.allowAllRequestHeaders(true)
.exposeHeaders("*")
.maxAge(3600)
.newDecorator();
} else {
corsDecorator = CorsService.builder(allowedOrigins)
.allowRequestMethods(GET, HEAD, POST, PUT, DELETE, OPTIONS)
.allowAllRequestHeaders(true)
.allowCredentials()
.exposeHeaders("*")
.maxAge(3600)
.newDecorator();
}
}

// build the GRPC service
GrpcService grpcService = GrpcService.builder()
.useBlockingTaskExecutor(true)
.addService(new SzGrpcProductImpl(this))
.addService(new SzGrpcConfigImpl(this))
.addService(new SzGrpcConfigManagerImpl(this))
.addService(new SzGrpcDiagnosticImpl(this))
.addService(new SzGrpcEngineImpl(this))
.build();

// create the server builder
ServerBuilder serverBuilder = Server.builder()
.http(new InetSocketAddress(bindAddress, port))
.blockingTaskExecutor(concurrency)
.service(grpcService);

// decorate the GRPC service with the CORS decorator if we have one
if (corsDecorator != null) {
serverBuilder.service(grpcService, corsDecorator);
} else {
serverBuilder.service(grpcService);
serverBuilder.decoratorUnder("/", corsDecorator);
}

// check if we need to build with data mart services
Expand All @@ -479,11 +488,6 @@ protected SzGrpcServer(SzEnvironment env,
.responseConverters(
new JacksonResponseConverterFunction(this.objectMapper));

// conditionally decorate for CORS
if (corsDecorator != null) {
builder.decorator(corsDecorator);
}

// now build the annotated service and bind it to the server builder
builder.build(dataMartReports);
}
Expand Down
Loading