-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdi) Upgrading Jersey to 2.28 and including CDI through Weld Ref…
…s:29552 (#29822) 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 This PR fixes: #29552 --------- Co-authored-by: spbolton <steve.bolton@dotcms.com>
- Loading branch information
1 parent
07a110e
commit b3427e9
Showing
43 changed files
with
533 additions
and
1,957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.dotcms.rest.config; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
|
||
/** | ||
* Annotation to mark a resource as disabled. | ||
* This is useful now that resources are activated by classpath scanning. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface Disabled { | ||
Response.Status status() default Status.NOT_FOUND; | ||
String message() default ""; | ||
} |
41 changes: 41 additions & 0 deletions
41
dotCMS/src/main/java/com/dotcms/rest/config/DisabledResourceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dotcms.rest.config; | ||
|
||
import com.dotmarketing.util.Logger; | ||
import com.jayway.jsonpath.internal.Utils; | ||
import java.io.IOException; | ||
import javax.annotation.Priority; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.container.ResourceInfo; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* Filter to check if a resource is disabled. | ||
*/ | ||
@Provider | ||
@Priority(1) | ||
public class DisabledResourceFilter implements ContainerRequestFilter { | ||
|
||
@Context | ||
private ResourceInfo resourceInfo; | ||
|
||
/** | ||
* Check if the resource is disabled. | ||
* @param requestContext request context. | ||
* @throws IOException if an I/O exception occurs. | ||
*/ | ||
@Override | ||
public void filter(final ContainerRequestContext requestContext) throws IOException { | ||
Class<?> resourceClass = resourceInfo.getResourceClass(); | ||
if (resourceClass.isAnnotationPresent(Disabled.class)) { | ||
final Disabled annotation = resourceClass.getAnnotation(Disabled.class); | ||
final Status status = annotation.status(); | ||
final String message = Utils.isEmpty(annotation.message()) ? status.getReasonPhrase() : annotation.message(); | ||
requestContext.abortWith(Response.status(annotation.status()).entity(message).build()); | ||
Logger.debug(this.getClass(), "Resource " + resourceClass.getName() + " is marked disabled."); | ||
} | ||
} | ||
} |
Oops, something went wrong.