Trouble using spring-data-solr with Broadleaf commerce - broadleaf-commerce

Using Broadleaf Commerce version 5.2.2-GA. I have implemented custom search capability using spring-data-solr.
Seeing this issue:
[org.broadleafcommerce.cms.url.domain.URLHandlerImpl]
are managed classes within the MergePersistenceUnitManager
but were not detected as being transformed by the EntityMarkerClassTransformer. There can be multiple causes for this:
1. Session persistence is enabled in your servlet container (like Tomcat) and an entity object has been loaded by the container before being loaded by the application's classloader. Ensure that session persistence is disabled; in Tomcat ensure that a <Manager pathname="" /> element exists in your context.xml.
2. You are inadvertently using class scanning to find a ServletContainerInitializer class, and your servlet container is loading all classes before transformers have been registered. If you are using a web.xml, ensure that there is an <absolute-ordering /> element somewhere in that file. If you are not using a web.xml and are using Spring Boot, then you likely need to add one. See https://www.broadleafcommerce.com/docs/core/5.2/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/tomcat for the example web.xml
3. The classes are being used as apart of an #Bean method or in some other runtime capacity that is initialized prior to persistence manager startup
I can get around the error by either:
removing spring-instrument.jar, via site/pom.xml overriding spring-boot-maven-plugin config:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration combine.self="override">
</configuration>
</plugin>
</plugins>
</pluginManagement>
Removing 'specifically' the spring-data-solr dependency (just to prove it causes the error), i.e. from core/pom.xml, removing this:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
</dependency>
I am happy to remove instrumentation for the time being, although this causes issues with the Auditing functionality. I.e. when attempting to save a BLC organic entity (such as StaticAssetImpl), due to the fact spring-instrumentation is not available, I see this:
java.lang.NullPointerException: null
at org.broadleafcommerce.common.audit.AbstractAuditableListener.setAuditData(AbstractAuditableListener.java:88)
Ideally in the longer term, I would like to safely be able to include the spring-data-solr dependency. NOTE: I can safely use spring-data-commons and spring-data-jpa, it appears that spring-data-solr is solely causing the issue. I have tried spring-data-solr 3.0.5.RELEASE, 3.0.8.RELEASE (latest) and 2.0.9.RELEASE.
In the meantime, have been looking for a way to disable Auditing, cant seem to find any documentation. I have tried overriding Entities to remove the #EntityListener, tried to override the AdminAuditableListener, tried to look for a property that would disable it but no luck as yet.
Appreciate any help with either a short term workaround to disable Auditing, disable Auditing for specific Entities only or perhaps something I have not tried that could make spring-data-solr compatible.
Thanks

The error you are running into regarding UrlHandlerImpl was resolved in Broadleaf 5.2.3-GA, see https://github.com/broadleafcommerce/issues/issues/5. The latest Broadleaf release is actually 5.2.6-GA.
There might be something inadvertent (scanning or something) that Spring Data Solr adds, but generally this piece shouldn't be an issue.

Related

is possible remove Jhipster Dependencies in back? why is necessary?

is possible remove Jhipster Dependencies in back? why is necessary or recommended???
IF I REMOVE OF POM.XML appears different compilation errors.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster-dependencies</artifactId>
<version>${jhipster-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency-management -->
</dependencies>
</dependencyManagement>
Is it possible?
Yes but you have to import all the dependencies yourself although nothing very difficult because most of them are already provided as Spring Boot starters. Looking at effective pom with mvnw help:effective-pom could help.
Then you must import maven plugins configuration.
Finally, your project will still depend on jhipster-framework library unless you extract only the classes your project needs.
Is it recommended?
For long term, managing yourself your dependencies is a good thing because major libraries like Spring Boot, Hibernate, ... support old releases for quite a long time while JHipster team supports only current major release (currently 7.x) which usually means one year.
At the beginning of your project, you will probably want to be able to follow JHipster updates. Modifying the pom.xml will make updating generated code more difficult.
Once you have written much manual code, your project is probably already too difficult to update, so cutting the dependency with JHipster will be harmless.
I found it harder to remove dependency from JHipster frontend than from backend because for instance ng-jhipster has some dependencies on Bootstrap that require some effort to remove.

Using Liquibase with Azure SQL And Azure Active Directory Authentication

How can you use Liquibase with an Azure SQL database and Azure Active Directory Authentication? Specifically, I want to connect using ActiveDirectoryPassword authentication mode as documented here:
https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15#connecting-using-activedirectorypassword-authentication-mode
I cannot figure out how to call the Liquibase CLI to make this happen.
Is this possible?
I was able to get this to work. I am not very familiar with Java (we use Liquibase with a C# project), so I think some of the Java pieces tripped me up.
There were a few things I had to do to make this work:
I needed to add some properties to the URL I sent to Liquibase:
--url="jdbc:sqlserver://REDACTED.database.windows.net;databaseName=REDACTED;authentication=ActiveDirectoryPassword;encrypt=true;trustServerCertificate=true"
ActiveDirectoryPassword is what tells the driver to use the authentication mechanism I wanted. I also had to add encrypt=true and trustServerCertificate=true to avoid some SSL errors I was getting (from: https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption?view=sql-server-ver15).
I needed the MSAL4J (Azure Active Directory) libraries in my classpath. I added them to the liquibase/lib directory so that the default Liquibase launcher scripts would add them for me. I got caught on this, too, because I needed to use Maven which we do not use. After downloading Maven, I used the copy-dependencies plugin to download the dependencies I needed.
mvn dependency:copy-dependencies
Here was the simple pom.xml I used:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
</project>
I also put these dependencies in the liquibase/lib directory so they were automatically included in the classpath. The instructions from Microsoft were helpful in leading me to the correct places:
https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15#connecting-using-activedirectorypassword-authentication-mode
Also, not sure it was required to meet my goal, but I upgraded to the latest Liquibase (3.8.7) and latest SQL Server drivers (8.2):
https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15

FacesContext.getCurrentInstance() returns null even in managed bean thread

I have a fairly standard archirecture where a PrimeFaces page calls a login action in a class annotated with javax.inject.#Named and javax.enterprise.context.#SessionScoped.
The doLogin() method receives null back from FacesContext.getCurrentInstance() even though the Faces Servlet should be properly invoked.
There are many posts that say essentially, "the only time FacesContext.getCurrentInstance() will return null is when it's called outside a managed bean thread". But I did find one post on another forum that identified a build/class loader issue that causes it. Somehow, due to improperly specified dependencies, your FacesContext class can get loaded for the container and again for the app. So what is supposed to be a singleton turns into two singletons (somehow...?). Anyway, I'm posting this to record the fix, not to fully explain the problem behind the symptom.
I'm using JBoss Developer Studio, building with Maven for JBoss EAP 6.2. EAP comes with modules for JSF 1 and JSF 2.1. I want to use 2.1, which is stored here:
C:\JBoss\jboss-eap-6.2.0\modules\system\layers\base\javax\faces\api\main.
In my EJB project POM I had incorrectly added a dependency for jsf-api <scope>compile, which resulted in FacesContext.getCurrentInstance() returning null as described above.
The solution was: in the POM for my ejb and my web projects, I added this dependency:
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
And to make sure my deployed ejb project also tells JBoss about that I needed to make sure it gets published with this in it's MANIFEST.MF:
Dependencies: javax.faces.api:main
That can be done by Maven too, by putting an archive configuration in the POM for the ejb project where the build plugin was created:
<!-- most of this <build> element was already in my POM -->
<build>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<!-- I added this <archive> element to tell Maven to add the dependency line in MANIFEST.MF -->
<archive>
<manifestEntries>
<Dependencies>javax.faces.api:main</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
For me, the maven-ejb-plugin entry was already there and I just added the archive definition to the existing <configuration>. I assume if you are building with ejb-jar-plugin or ejb-war-plugin, the same <archive>...</archive> definition could be used.

When releasing an application, how to disable pages used during devolpment?

Is there a way to disable JSF pages when deploying to a production environment, but use these features in a development environment?
I am using Java EE with JSF to create a web application. I use a number of JSF pages to carry out debugging and testing. I want to disable these pages when the application is deployed in its production environment. No-one, not even develops will need to use these pages on the deployed application, so I want to disable them as a security precaution.
I do not want to simply restrict access to authenticated users. Firstly, this makes it tedious to use the debug features, as a login is required. And secondly, the debug features are quite powerful, and if there is a vulnerability in my web application, it could be devastating for an attacker to gain access to these features.
You can use the Maven WAR plugin in order to exclude resources from your build. You are allowed to use wildcards an even expressions to specify what you want to exclude.
Let's refer to some adapted example from the docs:
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<packagingExcludes>*-test.xhtml</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
That will exclude all the -test.xhtml ended resources from the root of your web application. You can develop this as far as you want to accomplish your requirements.
See also:
Including and Excluding Files From the WAR

Is it possible (and viable) to use Oracle ADF alongside JSF2 with Facelets?

I am searching the web for information regarding the usage of Oracle ADF as a component suite (and not as a development framework), alongside vanilla JSF (2.0).
I am working with a client that insists the solution uses the Oracle ADF UI components. The rest of the Fusion Middleware, however, can be completely skipped for all he cares. Therefore, I'd like to stay as close to the Java EE-JSF2 blueprints as possible, and only resort to ADF as a UI component library, as one would with PrimeFaces, for example.
So, the question - is it possible? Does ADF imposes limitations/dependencies that would prevent this scenario? Can we use it solely as a component library, or must we depend on its heavyweight framework to make them work?
It does not work; at least, not as one would expect. In short: ADF does indeed support JSF2 and Facelets, and they coexist nicely in a single application. As long as you don't mix them together.
I intended to use ADF as a component library, in a way similar to how one uses PrimeFaces or RichFaces: you add the correct dependencies, config what needs to be configured, and you're good to go. When Oracle says that ADF supports JSF2 and Facelets, this is the scenario that one would assume.
To start, you cannot use ADF components outside of a <af:document /> tag (or trinidad's counterpart); which means that content outside this tag is ignored, reducing the ability to use Facelets to a minimum. So, you'll hardly have any Facelets code on the same page where ADF components reside.
JSF + CDI integration is only available through the Mojarra implementation. Using MyFaces (the base for the current ADF version), one might make it work through updating the MyFaces jars and adding CODI, but it does not work out-of-the-box and I did not take the time to investigate it further.
To add to that, for layout management, you're stuck with the ADF way (through pageTemplateDef and pageTemplate tags), since mixing in Facelets is difficult due to the dependency on the document tag. So you see, Facelets support is there, "standard" JSF2 pages can exist in a ADF application - but to use ADF's components, you need to be in an ADF page.
To anyone that might be interested, once you populate your local maven repository using JDeveloper (as per the techniques suggested on the comments in the original question), the minimal dependencies to have ADF UI components in a web application (war) that can be run on WebLogic 12c or Glassfish with ADF essentials, are the following:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>trinidad-api</artifactId>
<version>12.1.2-0-0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>trinidad-impl</artifactId>
<version>12.1.2-0-0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>adf-richclient-api-11</artifactId>
<version>12.1.2.0.40.66.34</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.adf</groupId>
<artifactId>adf-richclient-impl-11</artifactId>
<version>12.1.2.0.40.66.34</version>
<scope>provided</scope>
</dependency>
You'll also need to add several other configuration files:
WEB-INF/adfc-config.xml
META-INF/adf-config.xml
META-INF/connections.xml
META-INF/wsm-assembly.xml
Along with further ADF boilerplate configuration on faces-config.xml and web.xml files.
So, the answer so far is:
Is it possible (to use ADF as a component library)? Yes.
Are there any limitations? There's no CDI (out of the box), and limited Facelets support. JSF2 ajax capabilities cannot be used within a ADF document - you must resort to the ADF partial page rendering, but JSF2 custom components and any ClientBehavior you may code work fine.
Is it worth the hassle? No.
Couple of months ago, Oracle ADF was supporting only JSF 1.2.
But with the release of JDeveloper 12c there are lots of new features and improvements over the IDE and over the Oracle ADF, for which there is JSF 2.0 Support now.
So, to answer your question - yes, you can use Oracle ADF with JSF2/Facelets.
If you just want a WAR through Maven do this (In JDeveloper 12c):
New Application -> Custom Application
Add the ADF Faces technology (shuttle to the right).
In the last step of the wizard choose "Use Maven".

Resources