Skip to content

Commit

Permalink
feat(CDI) Refs: #29552 (#29678)
Browse files Browse the repository at this point in the history
### Proposed Changes
* In this PR we are upgrading to jersey  2.28
* We are changing DotRestApplication to use package discovery to load
Resources and Providers
* We're making some adjustments on some Mappers to preserve the present
behavior
* We're introducing CDI through Weld container

---------

Co-authored-by: spbolton <steve.bolton@dotcms.com>
  • Loading branch information
fabrizzio-dotCMS and spbolton authored Aug 29, 2024
1 parent acbd281 commit 11358b0
Show file tree
Hide file tree
Showing 40 changed files with 472 additions and 1,956 deletions.
54 changes: 47 additions & 7 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<shedlock.version>4.33.0</shedlock.version>
<glowroot.version>0.14.1</glowroot.version>
<jackson.version>2.17.2</jackson.version>
<jersey.version>2.22.1</jersey.version>
<jersey.version>2.28</jersey.version>
<graalvm.version>22.3.3</graalvm.version>
</properties>
<dependencyManagement>
Expand Down Expand Up @@ -84,11 +84,6 @@
*****************************
-->

<dependency>
<groupId>com.dotcms</groupId>
<artifactId>ant-tooling</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.aopalliance-repackaged</artifactId>
Expand Down Expand Up @@ -1137,7 +1132,7 @@
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<version>2.1.1</version>
</dependency>

<!-- Rest API Documentation -->
Expand All @@ -1152,6 +1147,51 @@
<version>${swagger.version}</version>
</dependency>

<!-- CDI Support -->

<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>3.1.9.Final</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>bean-validator</artifactId>
<version>2.5.0-b06</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<version>2.0.2.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>3.1.9.Final</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<version>3.0.5</version>
</dependency>

<!--
*****************************
Expand Down
1,141 changes: 0 additions & 1,141 deletions build.xml

This file was deleted.

42 changes: 35 additions & 7 deletions dotCMS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@
*****************************
-->

<dependency>
<groupId>com.dotcms</groupId>
<artifactId>ant-tooling</artifactId>
</dependency>
<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.aopalliance-repackaged</artifactId>
Expand Down Expand Up @@ -1199,12 +1195,11 @@
<artifactId>jersey-common</artifactId>
</dependency>

<!--
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-cdi2-se</artifactId>
<artifactId>jersey-hk2</artifactId>
</dependency>
-->

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
Expand Down Expand Up @@ -1412,6 +1407,39 @@
</exclusions>
</dependency>

<!-- Weld CDI -->

<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>3.1.9.Final</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>bean-validator</artifactId>
<version>2.5.0-b06</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<scope>test</scope>
</dependency>

<!-- Weld CDI -->

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<version>3.0.5</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
Expand Down
35 changes: 35 additions & 0 deletions dotCMS/src/main/java/com/dotcms/cdi/CDIUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.dotcms.cdi;

import com.dotmarketing.util.Logger;
import java.util.Optional;
import javax.enterprise.inject.spi.CDI;

/**
* Utility class to get beans from CDI container
*/
public class CDIUtils {

/**
* Private constructor to avoid instantiation
*/
private CDIUtils() {
}

/**
* Get a bean from CDI container
* @param clazz the class of the bean
* @return an Optional with the bean if found, empty otherwise
*/
public static <T> Optional<T> getBean(Class<T> clazz) {
try {
return Optional.of(CDI.current().select(clazz).get());
} catch (Exception e) {
Logger.error(CDIUtils.class,
String.format("Unable to find bean of class [%s] [%s]", clazz, e.getMessage())
);
}
return Optional.empty();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.ext.Provider;

/**
* This decorator reads the annotations on the resources and includes header based on it based on them.
Expand All @@ -31,6 +32,7 @@
*/
@Singleton
@Priority(Priorities.HEADER_DECORATOR)
@Provider
public class HeaderFilter implements ContainerResponseFilter {

private final PermissionsUtil permissionsUtil = PermissionsUtil.getInstance();
Expand Down
2 changes: 2 additions & 0 deletions dotCMS/src/main/java/com/dotcms/rest/api/CorsFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import com.dotmarketing.util.Logger;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import javax.ws.rs.ext.Provider;


/**
* @author Geoff M. Granum
*/
@Provider
public class CorsFilter implements ContainerResponseFilter {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

import com.dotmarketing.util.Logger;
import java.util.concurrent.atomic.AtomicReference;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.ext.Provider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spi.AbstractContainerLifecycleListener;
import org.glassfish.jersey.server.spi.Container;

/**
* A new Reloader will get created on each reload there can only be one container at a time
*/
class ContainerReloader extends AbstractContainerLifecycleListener {

private static final ContainerReloader INSTANCE = new ContainerReloader();
@Provider
@ApplicationScoped
public class ContainerReloader extends AbstractContainerLifecycleListener {

private static final AtomicReference<Container> containerRef = new AtomicReference<>();

public static ContainerReloader getInstance() {
return INSTANCE;
}

@Override
public void onStartup(Container container) {
Logger.debug(ContainerReloader.class, "Jersey Container started");
Expand Down
Loading

0 comments on commit 11358b0

Please sign in to comment.