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

Draft: Adds lookup in system properties for WAR contextRoot in EAR #24644

Closed
wants to merge 1 commit into from

Conversation

ctabin
Copy link
Contributor

@ctabin ctabin commented Oct 21, 2023

Hi GlassFish team !

I'm looking up to implement a simple system property lookup in GlassFish so we can externalize contextRoot and urlPattern (and more, such as JNDI names, EJB persistance unit names, ...).

This is mainly a prototype to see how this can be implemented since I don't know how it would be the most correct place to put this translation, neither if this is the correct way to do it (for instance, in Payara it only looks for the properties declared in the domain.xml). The goal of this PR is to get some input to see in which way this can go.

Based on my example, the goal is to have a definition like below, so we can build an EAR where the URLs can be configured outside the application itself (so we could eventually have the EAR/WAR/JAR file signed):

<modules>
  <webModule>
    <groupId>ch.astorm.gf-embedded</groupId>
    <artifactId>war</artifactId>
    <contextRoot>/${ch.astorm.root}</contextRoot>
    <bundleFileName>sample-war.war</bundleFileName>
  </webModule>
  <ejbModule>
    <groupId>ch.astorm.gf-embedded</groupId>
    <artifactId>ejb</artifactId>
    <bundleFileName>sample-ejb.jar</bundleFileName>
  </ejbModule>
</modules>

Here are some places that I'd like to see this implemented:

  • context root WAR in the EAR
  • URL patterns in @WebServlet
  • jta-data-source in persistence.xml

Any feedback is welcome :-)

@ctabin ctabin marked this pull request as draft October 21, 2023 18:05
@@ -145,7 +147,13 @@ public T getDescriptor() {
* @param contextRoot the contextRoot
*/
public void setContextRoot(String contextRoot) {
this.contextRoot = contextRoot;
VariableResolver resolver = new VariableResolver() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use the existing functionality in TranslatedConfigView.expandValue(). This method is used to expand values in domain.xml and supports references to system properties and password aliases. In the future, we can also add support to MicroProfile Config values (e.g. also env variables).

I suggest creating a new static method in TranslatedConfigView, e.g. expandValueForDescriptor and delegate to the expandValue() method. This is just in case we need to add additional behavior when dealing with deployment descriptors. E.g. disable it with a config property like Payara did in this PR because it broke some TCK tests: payara/Payara#4132.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @OndroMih,
Thanks for the hints ! I'll take a look and come back with some similar implementation.

@OndroMih
Copy link
Contributor

You can see most, if not all places where Payara supports expansion of deployment descriptor values or annotation values in this PR: https://github.com/payara/Payara/pull/4132/files.

URL patterns are set in WebComponentDescriptorImpl.addUrlPattern() method. Other @WebServlet properties can be expanded there too. For servletName, WebServletHandler uses it to find an existing web servlet definition if it exists. The servletName has to be translated also in this search. However, I would do it inside the WebBundleDescriptor.getWebComponentByCanonicalName

persistence.xml values are I think set in setters in PersistenceUnitDescriptor.

@OndroMih
Copy link
Contributor

OndroMih commented Nov 7, 2024

We at OmniFish are working on this in another branch so that such lookup works in all deployment descriptors and annotations, not only for the contextRoot property. I'll close this PR now. We'll create a PR with the more complete solution soon.

@OndroMih OndroMih closed this Nov 7, 2024
@ctabin
Copy link
Contributor Author

ctabin commented Nov 7, 2024

@OndroMih Amazing 👍 Looking forward to see this implemented in GlassFish and sorry I didn't have the time to work on this.

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