Skip to content

Commit

Permalink
Adding new jbossws-cxf-jaxrs-cdi module to be used for setting CDI in…
Browse files Browse the repository at this point in the history
…tegration dependency without exposing the whole server side integration class set
  • Loading branch information
asoldano committed Nov 20, 2017
1 parent 7a95ffc commit d5e84f7
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 3 deletions.
7 changes: 7 additions & 0 deletions modules/dist/pom.xml
Expand Up @@ -30,6 +30,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf-jaxrs-cdi</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf-transports-undertow</artifactId>
Expand Down
Expand Up @@ -42,6 +42,7 @@
<include>org.jboss.ws.cxf:jbossws-cxf-jaspi:jar</include>
<include>org.jboss.ws.cxf:jbossws-cxf-factories:jar</include>
<include>org.jboss.ws.cxf:jbossws-cxf-server:jar</include>
<include>org.jboss.ws.cxf:jbossws-cxf-jaxrs-cdi:jar</include>
<include>org.jboss.ws.cxf:jbossws-cxf-transports-undertow:jar</include>
<include>org.jboss.ws.cxf:jbossws-cxf-transports-udp:jar</include>
<include>org.jboss.ws.projects:jaxws-undertow-httpspi:jar</include>
Expand Down
5 changes: 5 additions & 0 deletions modules/dist/src/main/scripts/build-deploy.xml
Expand Up @@ -351,6 +351,11 @@
<include name="**/jbossws-cxf-factories.jar"/>
</fileset>
</copy>
<copy todir="@{targetdir}/org/jboss/ws/cxf/jbossws-cxf-jaxrs-cdi/main" flatten="false" overwrite="true">
<fileset dir="@{thirdpartydir}/lib">
<include name="**/jbossws-cxf-jaxrs-cdi.jar"/>
</fileset>
</copy>
<copy todir="@{targetdir}/org/jboss/ws/cxf/jbossws-cxf-transports-undertow/main" flatten="false" overwrite="true">
<fileset dir="@{thirdpartydir}/lib">
<include name="**/jbossws-cxf-transports-undertow.jar"/>
Expand Down
29 changes: 29 additions & 0 deletions modules/jaxrs-cdi/pom.xml
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>JBoss Web Services - Stack CXF JAX-RS CDI integration</name>
<artifactId>jbossws-cxf-jaxrs-cdi</artifactId>
<packaging>jar</packaging>

<!-- Parent -->
<parent>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf</artifactId>
<version>5.1.3.rest-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
</dependencies>

</project>
Expand Up @@ -45,8 +45,6 @@
import javax.ws.rs.core.Application;
import javax.ws.rs.ext.Provider;

import org.apache.cxf.jaxrs.utils.AnnotationUtils;

/**
* This Extension handles default scopes for discovered JAX-RS components. It
* also observes ProcessInjectionTarget event and wraps InjectionTargets
Expand Down Expand Up @@ -113,7 +111,7 @@ public <T> void observeResources(@WithAnnotations(

if (!annotatedType.getJavaClass().isInterface() && !isSessionBean(annotatedType)
// This check is redundant for CDI 1.1 containers but required for CDI 1.0
&& AnnotationUtils.getClassAnnotation(annotatedType.getJavaClass(), Path.class) != null
&& getClassAnnotation(annotatedType.getJavaClass(), Path.class) != null
&& !annotatedType.isAnnotationPresent(Decorator.class))
{
/*LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanJaxRsResource(annotatedType.getJavaClass()
Expand All @@ -122,6 +120,30 @@ public <T> void observeResources(@WithAnnotations(
this.resources.add(annotatedType.getJavaClass());
}
}

private static <A extends Annotation> A getClassAnnotation(Class<?> c, Class<A> aClass) {
if (c == null) {
return null;
}
A p = c.getAnnotation(aClass);
if (p != null) {
return p;
}

p = getClassAnnotation(c.getSuperclass(), aClass);
if (p != null) {
return p;
}

// finally try the first one on the interface
for (Class<?> i : c.getInterfaces()) {
p = getClassAnnotation(i, aClass);
if (p != null) {
return p;
}
}
return null;
}

/**
* Set a default scope for each CDI bean which is a JAX-RS Provider.
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -53,6 +53,7 @@
<modules>
<module>modules/jaspi</module>
<module>modules/server</module>
<module>modules/jaxrs-cdi</module>
<module>modules/client</module>
<module>modules/endorsed</module>
<module>modules/resources</module>
Expand Down

0 comments on commit d5e84f7

Please sign in to comment.