Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This site contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Extension Core Module Structure

Extension Core Module Structure

Use the extensions/core/ext-core module to customize and extend core functionalities. This module can include extensions to classes in ep-core as well as modules that ep-core depends on, such as ep-settings or ep-persistence-openjpa. It can also include new functionalities required for other extension modules.

The ext-core module has the following structure:

  1. ext-core
  2. src
  3. main
  4. java
  5. com
  6. java
  7. // Extension classes go here
  8. resources
  9. META-INF
  10. conf
  11. ep-core-plugin.xml // Spring definitions and overrides
  12. jpa-persistence.xml // OpenJPA persistence additions and overrides
  13. OSGI-INF
  14. blueprint
  15. springCtx-import.xml // OSGi blueprint descriptor file

Copy

...
Read more

OSGi configuration

Cortex runs in an OSGi container. Any library that Cortex uses must be packaged as an OSGi bundle. This section describes how ext-core is configured for OSGi.

Extension pom.xml

The key OSGi configuration is highlighted in this snippet from the core extension's pom.xml.

  1. <artifactId>ext-core</artifactId>
  2. <packaging>bundle</packaging>
  3. ...
  4. <build>
  5. <plugins>
  6. <plugin>
  7. <groupId>org.apache.felix</groupId>
  8. <artifactId>maven-bundle-plugin</artifactId>
  9. <extensions>true</extensions>
  10. <configuration>
  11. <instructions>
  12. <!-- Fragment-Host gives the symbolic name of the core wrapper bundle to attach to. -->
  13. <Fragment-Host>ext-commerce-engine-wrapper</Fragment-Host>
  14. <Import-Package>
  15. !*

Copy

...
Read more

<packaging>bundle</packaging>

The first OSGi configuration data in the POM is the project's packaging <packaging>bundle</packaging> data. With this setting, Maven builds the project as an OSGi bundle. The project still builds into a JAR file, so the project can be used outside of an OSGi setting, which means you can leave this as is even if you are not using the core extension in an OSGi setting.

maven-bundle-plugin

The maven-bundle-plugin configuration transforms the core extension into a OSGi fragment and tells the fragment to attach to Cortex's ext-commerce-engine-wrapper bundle.. The extension commerce engine wrapper bundle wraps the core extension in an OSGi bundle. Fragments are treated as part of the host bundles. Relevant definitions of the fragment are merged with the definitions of the host bundle before the host is resolved, as long as the information does not conflict. If possible, fragment dependencies are resolved. However, if the fragment dependencies cannot be resolved, the fragment is not attached to the host bundle. A fragment cannot have its own class loader or bundle activator. It cannot override the information present in the host bundles. Fragments extend bundles with resources, classes, and permitted headers to customize your bundles.

<Import-Package>

The <Import-Package> element contributes any additional imports to the core bundle. Add !* in the <Import-Package> element if you do not want to import anything to the core bundle. If your core extension relies on additional third party libraries,other than the libraries already used by the core bundle, you must list the required packages in the <Import-Package> instruction. You must also include the manifest header directive value identifying a mandatory resolution type to enable attachment problem logging. For example:

  1. <Import-Package>
  2. org.thirdparty.library.package; resolution:=mandatory,
  3. !*
  4. </Import-Package>

Copy

If you do not specify the mandatory resolution, OSGI does not find the third party library package at run time and the fragment fails to attach, however, no error message appears.

springCtx-import.xml

This file provides information about the spring configuration for the extension project to OSGi.

  1. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xmlns="http://www.springframework.org/schema/beans"
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >
  4.  
  5. <!-- Let OSGI know the spring configuration of this project. -->
  6. <import resource="../../META-INF/conf/ep-core-plugin.xml" />
  7. </beans>

Copy

Notes

  • Core extension classes replacing the default core classes, which have the same package structure and class name, do not work with this approach.
  • If the extension uses third party libraries, the following additional configuration is required:
    • Add the third party packages to the <Import-Package> element as described in the Extension pom.xml section.
    • If the third-party libraries are OSGi compliant, add the libraries as a dependency and artifact items in the Cortex Webapp.
    • If the libraries are not OSGi compliant, the libraries must be embedded in the fragment.

jpa-persistence.xml

The core extension's jpa-persistence.xml file specifies the following:

  1. <persistence-unit name="commerce-persistence-unit">
  2. ...
  3. <mapping-file>...</mapping-file>
  4.  
  5. <class>...</class>
  6.  
  7. <exclude-unlisted-classes>true</exclude-unlisted-classes>
  8.  
  9. <validation-mode>NONE</validation-mode>
  10.  
  11. <properties>
  12. <property name="openjpa.Log" value="slf4j"/commerce-legacy/>
  13. <property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/commerce-legacy/>
  14. </properties>
  15.  

Copy

...
Read more

  • <mapping-file> - Defines the classpath for new ORM metadata mapping files.
  • <class> - Defines the fully qualified class names of the new persistent classes.
  • <exclude-unlisted-classes> - Must be set to true so that OpenJPA will scan only the classpaths of the listed classes. OSGI does not permit scanning of unlisted clases.
  • <validation-mode> - Must be set to NONE, so that OpenJPA does not automatically perform JSR 330 validation on objects persisted to the database.
  • <properties> - Must have values as shown above. openjpa.DetachState is used during OpenJPA byte code enhancement.
    Important: Do not add additional properties here. To add or override OpenJPA properties, see Override Persistence Unit Properties.

For more information about how to exclude existing ORM mapping files and/or persistent classes, see Exclude references from the Persistence Unit.