Skip to content

Commit

Permalink
Merge pull request #14663 from geoand/rr-tiny-polish
Browse files Browse the repository at this point in the history
Apply tiny polish to RESTEasy Reactive startup code
  • Loading branch information
gsmet authored Feb 1, 2021
2 parents 237b725 + 650d76d commit 38acffd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public DeploymentInfo setApplicationPath(String applicationPath) {
return this;
}

public List<HandlerChainCustomizer> getGlobalHandlerCustomers() {
public List<HandlerChainCustomizer> getGlobalHandlerCustomizers() {
return globalHandlerCustomers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public BeanFactory.BeanInstance<?> apply(Class<?> aClass) {

//pre matching interceptors are run first
List<ServerRestHandler> preMatchHandlers = new ArrayList<>();
for (HandlerChainCustomizer customizer : info.getGlobalHandlerCustomers()) {
preMatchHandlers.addAll(customizer.handlers(HandlerChainCustomizer.Phase.BEFORE_PRE_MATCH));
for (int i = 0; i < info.getGlobalHandlerCustomizers().size(); i++) {
preMatchHandlers
.addAll(info.getGlobalHandlerCustomizers().get(i).handlers(HandlerChainCustomizer.Phase.BEFORE_PRE_MATCH));
}
if (!interceptors.getContainerRequestFilters().getPreMatchInterceptors().isEmpty()) {
preMatchHandlers = new ArrayList<>(interceptorDeployment.getPreMatchContainerRequestFilters().size());
Expand All @@ -190,16 +191,15 @@ public BeanFactory.BeanInstance<?> apply(Class<?> aClass) {
preMatchHandlers.add(new ResourceRequestFilterHandler(containerRequestFilter, true));
}
}
for (HandlerChainCustomizer customizer : info.getGlobalHandlerCustomers()) {
preMatchHandlers.addAll(customizer.handlers(HandlerChainCustomizer.Phase.AFTER_PRE_MATCH));
for (int i = 0; i < info.getGlobalHandlerCustomizers().size(); i++) {
preMatchHandlers
.addAll(info.getGlobalHandlerCustomizers().get(i).handlers(HandlerChainCustomizer.Phase.AFTER_PRE_MATCH));
}

Deployment deployment = new Deployment(exceptionMapping, info.getCtxResolvers(), serialisers,
return new Deployment(exceptionMapping, info.getCtxResolvers(), serialisers,
abortHandlingChain.toArray(EMPTY_REST_HANDLER_ARRAY), dynamicEntityWriter,
prefix, paramConverterProviders, configurationImpl, applicationSupplier,
threadSetupAction, requestContextFactory, preMatchHandlers, classMappers);

return deployment;
}

//TODO: this needs plenty more work to support all possible types and provide all information the FeatureContext allows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ public static Map<String, RequestMapper<RuntimeResource>> buildClassMapper(
//now we have all our possible resources
List<RequestMapper.RequestPath<RuntimeResource>> result = new ArrayList<>();
for (Map.Entry<URITemplate, List<RequestMapper.RequestPath<RuntimeResource>>> entry : i.getValue().entrySet()) {
if (entry.getValue().size() == 1) {
List<RequestMapper.RequestPath<RuntimeResource>> requestPaths = entry.getValue();
if (requestPaths.size() == 1) {
//simple case, only one match
result.addAll(entry.getValue());
result.addAll(requestPaths);
} else {
List<RuntimeResource> resources = new ArrayList<>();
for (RequestMapper.RequestPath<RuntimeResource> val : entry.getValue()) {
resources.add(val.value);
List<RuntimeResource> resources = new ArrayList<>(requestPaths.size());
for (int j = 0; j < requestPaths.size(); j++) {
resources.add(requestPaths.get(j).value);
}
MediaTypeMapper mapper = new MediaTypeMapper(resources);
//now we just create a fake RuntimeResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public RuntimeResourceDeployment(DeploymentInfo info, Supplier<Executor> executo
public RuntimeResource buildResourceMethod(ResourceClass clazz,
ServerResourceMethod method, boolean locatableResource, URITemplate classPathTemplate, DeploymentInfo info) {
URITemplate methodPathTemplate = new URITemplate(method.getPath(), false);
List<ServerRestHandler> abortHandlingChain = new ArrayList<>();
MultivaluedMap<ScoreSystem.Category, ScoreSystem.Diagnostic> score = new QuarkusMultivaluedHashMap<>();

Map<String, Integer> pathParameterIndexes = buildParamIndexMap(classPathTemplate, methodPathTemplate);
Expand Down Expand Up @@ -147,7 +146,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
handlers.addAll(interceptorDeployment.setupInterceptorHandler());
//at this point the handler chain only has interceptors
//which we also want in the abort handler chain
abortHandlingChain.addAll(handlers);
List<ServerRestHandler> abortHandlingChain = new ArrayList<>(handlers);

// when a method is blocking, we also want all the request filters to run on the worker thread
// because they can potentially set thread local variables
Expand All @@ -158,7 +157,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionNonBlocking);
}

//spec doesn't seem to test this, but RESTEeasy does not run request filters again for sub resources (which makes sense)
//spec doesn't seem to test this, but RESTEasy does not run request filters again for sub resources (which makes sense)
if (!locatableResource) {
handlers.addAll(interceptorDeployment.setupRequestFilterHandler());
}
Expand Down Expand Up @@ -189,7 +188,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
handlers.add(new InputHandler(quarkusRestConfig.getInputBufferSize(), executorSupplier));
}
}
// if we need the body, let's deserialise it
// if we need the body, let's deserialize it
if (bodyParameter != null) {
Class<Object> typeClass = loadClass(bodyParameter.declaredType);
Type genericType = typeClass;
Expand Down Expand Up @@ -333,13 +332,13 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
//the response filter handlers, they need to be added to both the abort and
//normal chains. At the moment this only has one handler added to it but
//in future there will be one per filter
List<ServerRestHandler> responseFilterHandlers = new ArrayList<>();
List<ServerRestHandler> responseFilterHandlers;
if (method.isSse()) {
handlers.add(new SseResponseWriterHandler());
responseFilterHandlers = Collections.emptyList();
} else {
handlers.add(new ResponseHandler());

responseFilterHandlers.addAll(interceptorDeployment.setupResponseFilterHandler());
responseFilterHandlers = new ArrayList<>(interceptorDeployment.setupResponseFilterHandler());
handlers.addAll(responseFilterHandlers);
handlers.add(new ResponseWriterHandler(dynamicEntityWriter));
}
Expand All @@ -355,24 +354,23 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
abortHandlingChain.add(new ResponseWriterHandler(dynamicEntityWriter));
handlers.add(0, new AbortChainHandler(abortHandlingChain.toArray(EMPTY_REST_HANDLER_ARRAY)));

RuntimeResource runtimeResource = new RuntimeResource(method.getHttpMethod(), methodPathTemplate,
return new RuntimeResource(method.getHttpMethod(), methodPathTemplate,
classPathTemplate,
method.getProduces() == null ? null : serverMediaType,
consumesMediaTypes, invoker,
clazz.getFactory(), handlers.toArray(EMPTY_REST_HANDLER_ARRAY), method.getName(), parameterClasses,
nonAsyncReturnType, method.isBlocking(), resourceClass,
lazyMethod,
pathParameterIndexes, score, sseElementType, clazz.resourceExceptionMapper());
return runtimeResource;
}

private void addHandlers(List<ServerRestHandler> handlers, ServerResourceMethod method, DeploymentInfo info,
HandlerChainCustomizer.Phase phase) {
for (HandlerChainCustomizer i : info.getGlobalHandlerCustomers()) {
handlers.addAll(i.handlers(phase));
for (int i = 0; i < info.getGlobalHandlerCustomizers().size(); i++) {
handlers.addAll(info.getGlobalHandlerCustomizers().get(i).handlers(phase));
}
for (HandlerChainCustomizer i : method.getHandlerChainCustomizers()) {
handlers.addAll(i.handlers(phase));
for (int i = 0; i < method.getHandlerChainCustomizers().size(); i++) {
handlers.addAll(method.getHandlerChainCustomizers().get(i).handlers(phase));
}
}

Expand Down

0 comments on commit 38acffd

Please sign in to comment.