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

Fix Dynamic proxy #5747

Open
wants to merge 1 commit into
base: 3.1
Choose a base branch
from
Open

Conversation

kalinchan
Copy link

Credit to @breakponchito

This is a fix to enable the creation of Proxy classes for context Field injection instead of concrete classes.

@jansupol
Copy link
Contributor

jansupol commented Oct 2, 2024

@kalinchan Do I understand this PR correctly that the injectee class is annotated by both RequestScoped and EJB Singleton?
A test would be much explanatory here...

@kalinchan
Copy link
Author

kalinchan commented Oct 3, 2024

I have attempted to create the test for this, but was unsuccessful.

If a class is annotated with jakarta.ejb.Singleton:

@Singleton
@Path("singleton")
public class RSSingletonTestService {
    ...
}

When injecting:

@Context
private HttpHeaders httpHeaders;

@Context
private UriInfo uriInfo;

And calling two different endpoints:

    @GET
    @Produces(MediaType.TEXT_HTML)
    @Path("/test1")
    public String test1(@HeaderParam("TESTHEADER") final String testHeaderParam, @Context final UriInfo uriInfoParam) {
        final long msstart = System.currentTimeMillis();
        final String ret = getHeader("test1");

        return getTestBody(testHeaderParam, uriInfoParam.getRequestUri().toString(), msstart, ret);

    }

    @GET
    @Produces(MediaType.TEXT_HTML)
    @Path("/test2")
    public String test2(@HeaderParam("TESTHEADER") final String testHeaderParam, @Context final UriInfo uriInfoParam) {
        final long msstart = System.currentTimeMillis();
        final String ret = getHeader("test2");

        return getTestBody(testHeaderParam, uriInfoParam.getRequestUri().toString(), msstart, ret);

    }

The Header and URI incorrectly returns the first requested Header and URI respectively.

private String getTestBody(final String testHeaderParam, final String uriParam, final long msstart, String ret) {
        ret += "URI member: " + uriInfo.getRequestUri().toString() + "\n"; // prints first requested uri // WRONG !!
        ret += "URI param: " + uriParam + "\n"; // works as expected; prints uri per request

        ret += "TESTHEADER member:" + httpHeaders.getHeaderString("TESTHEADER") + "\n"; // prints header sent by first request // WRONG !!
        ret += "TESTHEADER param:" + testHeaderParam + "\n"; // works as expected; prints header per request

        return ret + getFooter(msstart);
    }

Expected Result:

...
URI member: http://localhost:8080/servlet/singleton/test2
URI param: http://localhost:8080/servlet/singleton/test2
TESTHEADER member:TEST2
TESTHEADER param:TEST2
...

Actual Result:

...
URI member: http://localhost:8080/servlet/singleton/test1
URI param: http://localhost:8080/servlet/singleton/test2
TESTHEADER member:TEST1
TESTHEADER param:TEST2
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants