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

ResourceUtils: does not recognize resource URLs on Jakarta EE #9452

Closed
andrejkolontai opened this issue Nov 26, 2022 · 6 comments
Closed

ResourceUtils: does not recognize resource URLs on Jakarta EE #9452

andrejkolontai opened this issue Nov 26, 2022 · 6 comments
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@andrejkolontai
Copy link

Describe the bug

org.primefaces.util.ResourceUtils.getResourceURL(FacesContext, String) doesn't recognize resource URLs on Jakarta EE. This caueses the ImageCropper to break when resource are used, i.e. #{resource['requestPhotosEdit:9752-66110-07_3']} used in the image attribute.

These URLs resolve into something like /admin-ui/jakarta.faces.resource/9752-66110-07_3.jsf?ln=requestPhotosEdit . But in the rendered HTML code they become something like /admin-ui//admin-ui/jakarta.faces.resource/9752-66110-07_3.jsf?ln=requestPhotosEdit (the context path gets prepended another time).

I hunted this down to org.primefaces.util.ResourceUtils.getResourceURL(FacesContext, String):

        else if (value.contains(ResourceHandler.RESOURCE_IDENTIFIER)) {
            return value;
        }

In the case of a resource URL, the value should be returned unmodified. Instead, the else branch is taken (I guess):

        else {
            String url = context.getApplication().getViewHandler().getResourceURL(context, value);

            return context.getExternalContext().encodeResourceURL(url);
        }

To me it seems that it simply does not recognize that this is a resource URL because it's still stuck in the javax namespace (despite ResourceHandler.RESOURCE_IDENTIFIER actually having the correct value).

Reproducer

I have forked the jakarta branch of the primefaces-test project:

https://github.com/andrejkolontai/primefaces-test/tree/jakarta

To reproduce, clone my repo, check out the jakarta branch and run

mvn clean jetty:run

Open http://localhost:8080/primefaces-test/ in some browser.

You will see:

  • the original URL from my project (in jakarta namespace)
  • the same URL in javax namespace
  • the jakarta URL after ResourceUtils.getResourceURL which is modified
  • the javax URL after ResourceUtils.getResourceURL (which is not modified, but I don't really care it's just to prove that the old namespace is still beeing used).

image

Expected behavior

jakarta resource URL should be returned unmodified.

PrimeFaces edition

Community

PrimeFaces version

12.0.0

Theme

No response

JSF implementation

Mojarra

JSF version

4.0

Java version

11

Browser(s)

Chrome(ium)

@andrejkolontai andrejkolontai added ‼️ needs-triage Issue needs triaging 🐞 defect Bug...Something isn't working labels Nov 26, 2022
@andrejkolontai andrejkolontai changed the title Component: ResourceUtils don't recognize resource URLs ´ Component: ResourceUtils don't recognize resource URLs on Jakarta EE Nov 26, 2022
@melloware
Copy link
Member

Thanks for the excellent report!

@melloware melloware removed the ‼️ needs-triage Issue needs triaging label Nov 26, 2022
@melloware melloware changed the title Component: ResourceUtils don't recognize resource URLs on Jakarta EE ResourceUtils: does not recognize resource URLs on Jakarta EE Nov 27, 2022
@tandraschko
Copy link
Member

tandraschko commented Nov 28, 2022

shouldnt RESOURCE_IDENTIFIER be shaded to jakarta?
i will check it now

@tandraschko
Copy link
Member

really weird
it also fails on MyFaces 4.0.0-SNAPSHOT, where you can clearly see:
public static final String RESOURCE_IDENTIFIER = "/jakarta.faces.resource";

else if (value.contains(ResourceHandler.RESOURCE_IDENTIFIER)) {
evaluates to false
where as else if (value.contains("/jakarta.faces.resource")) {
evaluates to true

maybe someone else can debug further
dependencies are looking fine
no idea

@NicolaIsotta
Copy link
Contributor

NicolaIsotta commented Nov 28, 2022

I decompiled the jakarta jar, this is the method:

    public static String getResourceURL(final FacesContext context, final String value) {
        if (LangUtils.isBlank(value)) {
            return "";
        }
        if (value.contains("/javax.faces.resource")) {
            return value;
        }
        final String url = context.getApplication().getViewHandler().getResourceURL(context, value);
        return context.getExternalContext().encodeResourceURL(url);
    }

Seems like the compiler, knowing that RESOURCE_IDENTIFIER is a constant (static and final), replaces the string reference with the value.

@tandraschko
Copy link
Member

puuuh, okay
we have to check how to manage this with shade plugin
this will propably also hit us for other constants

tandraschko added a commit that referenced this issue Nov 28, 2022
@tandraschko tandraschko added this to the 13.0.0 milestone Nov 28, 2022
@tandraschko tandraschko self-assigned this Nov 28, 2022
@melloware
Copy link
Member

Nice fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants