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

Support Instance<Optional> injection #27580

Merged
merged 1 commit into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -177,6 +177,7 @@ void validateConfigInjectionPoints(ValidationPhaseBuildItem validationPhase,
|| DotNames.OPTIONAL_INT.equals(injectedType.name())
|| DotNames.OPTIONAL_LONG.equals(injectedType.name())
|| DotNames.OPTIONAL_DOUBLE.equals(injectedType.name())
|| DotNames.INSTANCE.equals(injectedType.name())
|| DotNames.PROVIDER.equals(injectedType.name())
|| SUPPLIER_NAME.equals(injectedType.name())
|| SR_CONFIG_VALUE_NAME.equals(injectedType.name())
Expand Down
Expand Up @@ -9,7 +9,9 @@
import java.util.OptionalInt;
import java.util.OptionalLong;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand Down Expand Up @@ -56,6 +58,9 @@ public void testOptionals() {
assertFalse(usingOptionals.missingOptionalInt.isPresent());
assertFalse(usingOptionals.missingOptionalLong.isPresent());
assertFalse(usingOptionals.missingOptionalDouble.isPresent());

assertFalse(usingOptionals.instanceOptional.get().isPresent());
assertFalse(usingOptionals.providerOptional.get().isPresent());
}

@Singleton
Expand Down Expand Up @@ -107,6 +112,13 @@ static class UsingOptionals {
@Inject
@ConfigProperty(name = "missing")
OptionalDouble missingOptionalDouble;
}

@Inject
@ConfigProperty(name = "missing")
Instance<Optional<String>> instanceOptional;

@Inject
@ConfigProperty(name = "missing")
Provider<Optional<String>> providerOptional;
}
}
Expand Up @@ -13,9 +13,9 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import io.quarkus.oidc.client.filter.runtime.OidcClientFilterConfig;
import io.quarkus.oidc.client.runtime.AbstractTokensProducer;
import io.quarkus.oidc.client.runtime.DisabledOidcClientException;
import io.quarkus.oidc.common.runtime.OidcConstants;
Expand All @@ -26,10 +26,8 @@
public class OidcClientRequestFilter extends AbstractTokensProducer implements ClientRequestFilter {
private static final Logger LOG = Logger.getLogger(OidcClientRequestFilter.class);
private static final String BEARER_SCHEME_WITH_SPACE = OidcConstants.BEARER_SCHEME + " ";

@Inject
@ConfigProperty(name = "quarkus.oidc-client-filter.client-name")
Optional<String> clientName;
OidcClientFilterConfig oidcClientFilterConfig;

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
Expand All @@ -50,6 +48,6 @@ private String getAccessToken() {
}

protected Optional<String> clientId() {
return clientName;
return oidcClientFilterConfig.clientName;
}
}
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -56,11 +57,11 @@ public String hello(@Context HttpRequest request) {
@Provider
public static class MappingFilter implements ContainerRequestFilter {
@Inject
Mapping mapping;
Instance<Mapping> mapping;

@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
requestContext.setProperty("mapping.hello", mapping.hello());
requestContext.setProperty("mapping.hello", mapping.get().hello());
}
}

Expand Down
@@ -1,5 +1,6 @@
package io.quarkus.it.smallrye.config;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
Expand All @@ -12,17 +13,17 @@ public class ConfigurableExceptionMapper
implements ExceptionMapper<ConfigurableExceptionMapper.ConfigurableExceptionMapperException> {
@Inject
@ConfigProperty(name = "exception.message")
String message;
Instance<String> message;
@Inject
ExceptionConfig exceptionConfig;
Instance<ExceptionConfig> exceptionConfig;

@Override
public Response toResponse(final ConfigurableExceptionMapperException exception) {
if (!message.equals(exceptionConfig.message())) {
if (!message.get().equals(exceptionConfig.get().message())) {
return Response.serverError().build();
}

return Response.ok().entity(message).build();
return Response.ok().entity(message.get()).build();
}

public static class ConfigurableExceptionMapperException extends RuntimeException {
Expand Down