Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Jakarta provide to BeanProvider as it's lazy #9779

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package io.micronaut.http.converters;

import io.micronaut.context.BeanProvider;
import io.micronaut.context.annotation.Prototype;
import io.micronaut.context.exceptions.ConfigurationException;
import io.micronaut.core.convert.MutableConversionService;
import io.micronaut.core.convert.TypeConverterRegistrar;
import io.micronaut.core.io.Readable;
import io.micronaut.core.io.ResourceLoader;
import io.micronaut.core.io.ResourceResolver;
import jakarta.inject.Inject;
import jakarta.inject.Provider;

import java.net.URL;
Expand All @@ -36,17 +38,34 @@
@Prototype
public class HttpConverterRegistrar implements TypeConverterRegistrar {

private final Provider<ResourceResolver> resourceResolver;
private final BeanProvider<ResourceResolver> resourceResolver;

/**
* Default constructor.
*
* @param resourceResolver The resource resolver
*/
protected HttpConverterRegistrar(Provider<ResourceResolver> resourceResolver) {
@Inject
protected HttpConverterRegistrar(BeanProvider<ResourceResolver> resourceResolver) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this internal? If not need to keep the constructor, deprecate the old one and add @Inject to this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected. Those classes should be internal

this.resourceResolver = resourceResolver;
}

/**
* The constructor.
*
* @param resourceResolver The resource resolver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it misses @deprecated javadoc

* @deprecated Replaced by {@link #HttpConverterRegistrar(BeanProvider)}.
*/
@Deprecated(forRemoval = true)
protected HttpConverterRegistrar(Provider<ResourceResolver> resourceResolver) {
this.resourceResolver = new BeanProvider<ResourceResolver>() {
@Override
public ResourceResolver get() {
return resourceResolver.get();
}
};
}

@Override
public void register(MutableConversionService conversionService) {
conversionService.addConverter(
Expand All @@ -55,7 +74,7 @@ public void register(MutableConversionService conversionService) {
(object, targetType, context) -> {
String pathStr = object.toString();
Optional<ResourceLoader> supportingLoader = resourceResolver.get().getSupportingLoader(pathStr);
if (!supportingLoader.isPresent()) {
if (supportingLoader.isEmpty()) {
context.reject(pathStr, new ConfigurationException(
"No supported resource loader for path [" + pathStr + "]. Prefix the path with a supported prefix such as 'classpath:' or 'file:'"
));
Expand Down