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

JakartaEE: Transformer: Support updating bean validation constraint mappings. #12431

Open
nmittles opened this issue May 29, 2020 · 0 comments
Open
Labels
in:Kernel/Bootstrap jakartaEE10 transformer Linking issues for the Eclipse Transformer

Comments

@nmittles
Copy link
Contributor

nmittles commented May 29, 2020

Bean Validation can have XML configuration files that reference javax.validation.constraints.* constraint classes. These XML files are references from the main bean validation deployment descriptor named validation.xml.

The transformer tool needs to be updated to:

  1. locate the bean validation validation.xml deployment descriptors
  • WEB-INF/classes/META-INF/validation.xml (war module location where META-INF/validation.xml is available from the classloader)
  • WEB-INF/validation.xml (non-spec, but Liberty supported war module location)
  • META-INF/validation.xml (ear and jar location where META-INF/validation.xml is available from the classloader))
  1. scan the validation.xml for <constraint-mapping> tags
  2. load the xml file(s) referenced by the <constraint-mapping> tag(s)
  3. update any references to javax.validation.constraints.* in these xml contraint mapping files

For Testing:
From com.ibm.ws.beanvalidation.v11_fat/fat/src/com/ibm/ws/beanvalidation/fat/basic/BasicValidation_Common.java remove:

        if (JakartaEE9Action.isActive()) {
            beanvalidation_10War.move("/WEB-INF/constraints-house_EE9.xml", "/WEB-INF/constraints-house.xml");
            beanvalidation_11War.move("/WEB-INF/constraints-house_EE9.xml", "/WEB-INF/constraints-house.xml");
        }

From /com.ibm.ws.beanvalidation.v11_fat/fat/src/com/ibm/ws/beanvalidation/fat/ejb/EJBModule_Common.java remove:

        if (JakartaEE9Action.isActive()) {
            jar.move("/META-INF/constraints-house_EE9.xml", "/META-INF/constraints-house.xml");
            jar2.move("/META-INF/constraints-house_EE9.xml", "/META-INF/constraints-house.xml");
        }

Delete the no longer needed constraints-house_EE9.xml files from both applications.

Example validation.xml:

<?xml version="1.0" encoding="UTF-8"?>
<validation-config
    xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd"
    version="1.1">
  <message-interpolator>beanvalidation11.CustomMessageInterpolator</message-interpolator>
  <traversable-resolver>beanvalidation11.CustomTraversableResolver</traversable-resolver>
  <constraint-validator-factory>beanvalidation11.CustomConstraintValidatorFactory</constraint-validator-factory>
  
  <!-- new in Bean Validation 1.1 -->
  <parameter-name-provider>beanvalidation11.CustomParameterNameProvider</parameter-name-provider>
  
  <constraint-mapping>WEB-INF/constraints-house.xml</constraint-mapping>
</validation-config>

Example constraint mapping xml. In this case the file is named constraints-house.xml:

<?xml version="1.0" encoding="UTF-8"?>
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd"
  xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
  <default-package>beanvalidation11.web.beans</default-package>

  <bean class="AValidationXMLTestBean" ignore-annotations="true">
    <field name="builder">
      <constraint annotation="javax.validation.constraints.NotNull" />
    </field>

    <field name="address">
      <constraint annotation="javax.validation.constraints.NotNull" />

      <constraint annotation="javax.validation.constraints.Size">
        <element name="min">5</element>
        <element name="max">80</element>
      </constraint>
    </field>
  </bean>
  
  <bean class="AValidationMixTestBean" ignore-annotations="false">
    <field name="builder">
      <constraint annotation="javax.validation.constraints.NotNull" />
    </field>

    <field name="address">
      <constraint annotation="javax.validation.constraints.NotNull" />

      <constraint annotation="javax.validation.constraints.Size">
        <element name="min">5</element>
        <element name="max">80</element>
      </constraint>
    </field>
  </bean>
</constraint-mappings>
@jhanders34 jhanders34 added the transformer Linking issues for the Eclipse Transformer label Oct 6, 2021
@tbitonti tbitonti changed the title Jakarta Transformer Tool: Support updating bean validation constraint mappings. JakartaEE: Transformer: Support updating bean validation constraint mappings. Oct 7, 2021
@tbitonti tbitonti removed their assignment Apr 4, 2022
@hlhoots hlhoots added this to JakartaEE Tasks in Open Liberty Kernel Team Apr 5, 2022
@tbitonti tbitonti moved this from JakartaEE Tasks to IceBox - on hold for now... in Open Liberty Kernel Team Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:Kernel/Bootstrap jakartaEE10 transformer Linking issues for the Eclipse Transformer
Projects
Status: IceBox - on hold for now...
Open Liberty Kernel Team
IceBox - on hold for now...
Development

No branches or pull requests

3 participants