Skip to content

Commit f14ca11

Browse files
authored
Merge pull request #1 from payara/Upstream-Sync
Upstream sync
2 parents ba80ad5 + 262b142 commit f14ca11

File tree

11 files changed

+168
-4
lines changed

11 files changed

+168
-4
lines changed

cdi/dynamic-bean-decorated/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>cdi</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>dynamic-bean-decorated</artifactId>
11+
<name>Java EE 8 Samples: CDI - Dynamic Bean Decorated</name>
12+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.javaee8.cdi.dynamic.bean.decorated;
2+
3+
import javax.enterprise.context.ApplicationScoped;
4+
import javax.enterprise.event.Observes;
5+
import javax.enterprise.inject.spi.AfterBeanDiscovery;
6+
import javax.enterprise.inject.spi.Extension;
7+
8+
/**
9+
*
10+
* @author Arjan Tijms
11+
*
12+
*/
13+
public class CdiExtension implements Extension {
14+
15+
public void afterBean(final @Observes AfterBeanDiscovery afterBeanDiscovery) {
16+
afterBeanDiscovery
17+
.addBean()
18+
.scope(ApplicationScoped.class)
19+
.types(MyBean.class)
20+
.id("Created by " + CdiExtension.class)
21+
.createWith(e -> new MyBeanImpl("Hi!"));
22+
}
23+
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.javaee8.cdi.dynamic.bean.decorated;
2+
3+
/**
4+
*
5+
* @author Arjan Tijms
6+
*
7+
*/
8+
public interface MyBean {
9+
String sayHi();
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.javaee8.cdi.dynamic.bean.decorated;
2+
3+
import javax.enterprise.inject.Typed;
4+
5+
/**
6+
*
7+
* @author Arjan Tijms
8+
*
9+
*/
10+
// Typed: Extra guard so that MyBeanImpl has no types of itself, but extension archive is not scanned
11+
// so not strictly needed.
12+
@Typed
13+
public class MyBeanImpl implements MyBean {
14+
15+
private final String greet;
16+
17+
// Note: There's no default ctor, so CDI cannot directly inject an instance of this
18+
// bean.
19+
20+
public MyBeanImpl(String greet) {
21+
this.greet = greet;
22+
}
23+
24+
@Override
25+
public String sayHi() {
26+
return greet;
27+
}
28+
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.javaee8.cdi.dynamic.bean.decorated.CdiExtension
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.javaee8.cdi.dynamic.bean.decorated;
2+
3+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
4+
import static org.junit.Assert.assertEquals;
5+
6+
import javax.inject.Inject;
7+
8+
import org.jboss.arquillian.container.test.api.Deployment;
9+
import org.jboss.arquillian.junit.Arquillian;
10+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
11+
import org.jboss.shrinkwrap.api.spec.WebArchive;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
15+
/**
16+
*
17+
* @author Arjan Tijms
18+
*
19+
*/
20+
@RunWith(Arquillian.class)
21+
public class DynamicBeanTest {
22+
23+
@Deployment
24+
public static WebArchive deploy() {
25+
return create(WebArchive.class)
26+
.addAsLibraries(
27+
create(JavaArchive.class)
28+
.addClasses(CdiExtension.class, MyBean.class, MyBeanImpl.class)
29+
.addAsResource("META-INF/services/javax.enterprise.inject.spi.Extension"))
30+
.addClass(MyDecorator.class)
31+
.addAsManifestResource("beans.xml");
32+
}
33+
34+
@Inject
35+
private MyBean myBean;
36+
37+
@Test
38+
public void test() {
39+
assertEquals("Hi! decorated", myBean.sayHi());
40+
}
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.javaee8.cdi.dynamic.bean.decorated;
2+
3+
import javax.annotation.Priority;
4+
import javax.decorator.Decorator;
5+
import javax.decorator.Delegate;
6+
import javax.inject.Inject;
7+
8+
@Decorator
9+
@Priority(100)
10+
public class MyDecorator implements MyBean {
11+
12+
@Inject
13+
@Delegate
14+
MyBean mybean;
15+
16+
@Override
17+
public String sayHi() {
18+
return mybean.sayHi() + " decorated";
19+
}
20+
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
6+
bean-discovery-mode="all">
7+
8+
</beans>

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
<!-- Application Server versions (these are downloaded and installed
2727
in these versions by Maven for the CI profiles) -->
28-
<payara.version>5.Beta2</payara.version>
29-
<payara.micro.version>5.Beta3-m1</payara.micro.version>
28+
<payara.version>5.182</payara.version>
29+
<payara.micro.version>5.182</payara.micro.version>
3030
<glassfish.version>4.1.1</glassfish.version>
31-
<tomcat.version>9.0.4</tomcat.version>
31+
<tomcat.version>9.0.10</tomcat.version>
3232
</properties>
3333

3434
<repositories>

servlet/http2/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,24 @@
354354
<alpn.version>8.1.12.v20180117</alpn.version>
355355
</properties>
356356
</profile>
357+
<profile>
358+
<id>alpn-when-jdk8_172</id>
359+
<activation>
360+
<jdk>1.8.0_172</jdk>
361+
</activation>
362+
<properties>
363+
<alpn.version>8.1.12.v20180117</alpn.version>
364+
</properties>
365+
</profile>
366+
<profile>
367+
<id>alpn-when-jdk8_173</id>
368+
<activation>
369+
<jdk>1.8.0_173</jdk>
370+
</activation>
371+
<properties>
372+
<alpn.version>8.1.12.v20180117</alpn.version>
373+
</properties>
374+
</profile>
357375
</profiles>
358376

359377
</project>

0 commit comments

Comments
 (0)