Skip to content

Commit

Permalink
Ensure that JAX-RS Providers type is accessible without an request
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Oct 27, 2022
1 parent b60542f commit e928dc5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.quarkus.resteasy.reactive.server.runtime;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import javax.ws.rs.ext.Providers;

import org.jboss.resteasy.reactive.server.core.CurrentRequestManager;
import org.jboss.resteasy.reactive.server.jaxrs.ProvidersImpl;

import io.vertx.core.http.HttpServerResponse;

/**
* Provides CDI producers for objects that can be injected via @Context
* In quarkus-rest this works because @Context is considered an alias for @Inject
* In RESTEasy Reactive this works because @Context is considered an alias for @Inject
* through the use of {@code AutoInjectAnnotationBuildItem}
*/
@Singleton
Expand All @@ -21,4 +24,10 @@ public class QuarkusContextProducers {
HttpServerResponse httpServerResponse() {
return CurrentRequestManager.get().serverRequest().unwrap(HttpServerResponse.class);
}

@ApplicationScoped
@Produces
Providers providers() {
return new ProvidersImpl(ResteasyReactiveRecorder.getCurrentDeployment());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Deployment getDeployment() {
}

public ProvidersImpl getProviders() {
// this is rarely called (basically only of '@Context Providers' is used),
// this is rarely called (basically only if '@Context Providers' is used),
// so let's avoid creating an extra field
return new ProvidersImpl(deployment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Providers;
import javax.ws.rs.sse.Sse;

import org.jboss.resteasy.reactive.server.SimpleResourceInfo;
Expand Down Expand Up @@ -79,11 +78,14 @@ Request request() {
// return CurrentRequest.get().getContext().response();
// }

@ApplicationScoped
@Produces
Providers providers() {
return getContext().getProviders();
}
// TODO: ideally we would declare this bean with a lesser priority and let Quarkus override it using a higher priority,
// however that is not possible because @Priority cannot be applied to methods

// @ApplicationScoped
// @Produces
// Providers providers() {
// return getContext().getProviders();
// }

@RequestScoped
@Produces
Expand Down

0 comments on commit e928dc5

Please sign in to comment.