⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit de406c4

Browse files
committed
Remote EJB sample of EE 8.
1 parent 89f0149 commit de406c4

16 files changed

Lines changed: 375 additions & 0 deletions

File tree

‎ejb/pom.xml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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>samples-parent</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>ejb</artifactId>
11+
<packaging>pom</packaging>
12+
13+
<name>Java EE 8 Sample: ejb</name>
14+
15+
<modules>
16+
<module>remote</module>
17+
</modules>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.javaee8</groupId>
22+
<artifactId>test-utils</artifactId>
23+
<version>${project.version}</version>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>fish.payara.ejb.rest</groupId>
28+
<artifactId>ejb-rest-client</artifactId>
29+
<version>5.191-SNAPSHOT</version>
30+
</dependency>
31+
</dependencies>
32+
</project>

‎ejb/remote/pom.xml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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>ejb</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>ejb-remote</artifactId>
11+
<packaging>pom</packaging>
12+
13+
<name>Java EE 8 Sample: ejb - remote</name>
14+
15+
<modules>
16+
<module>vendor</module>
17+
<module>roles-allowed</module>
18+
</modules>
19+
20+
</project>

‎ejb/remote/roles-allowed/pom.xml‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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>ejb-remote</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>ejb-remote-roles-allowed</artifactId>
11+
<packaging>war</packaging>
12+
13+
<name>Java EE 8 Sample: ejb - remote - Roles Allowed</name>
14+
15+
<profiles>
16+
<profile>
17+
<id>payara-ci-managed</id>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.javaee8.ejb.remote.vendor</groupId>
21+
<artifactId>ejb.remote.vendor.payara-rest</artifactId>
22+
<version>1.0-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</profile>
26+
27+
<profile>
28+
<id>payara-remote</id>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.javaee8.ejb.remote.vendor</groupId>
32+
<artifactId>ejb.remote.vendor.payara-rest</artifactId>
33+
<version>1.0-SNAPSHOT</version>
34+
</dependency>
35+
</dependencies>
36+
</profile>
37+
38+
<profile>
39+
<id>glassfish-remote</id>
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.javaee8.ejb.remote.vendor</groupId>
43+
<artifactId>ejb.remote.vendor.payara-rest</artifactId>
44+
<version>1.0-SNAPSHOT</version>
45+
</dependency>
46+
</dependencies>
47+
</profile>
48+
</profiles>
49+
50+
51+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.ejb.remote.remote;
3+
4+
import java.io.Serializable;
5+
6+
import javax.annotation.security.RolesAllowed;
7+
import javax.ejb.Stateless;
8+
9+
@Stateless
10+
public class Bean implements BeanRemote, Serializable {
11+
12+
private static final long serialVersionUID = 1L;
13+
14+
@Override
15+
@RolesAllowed("g1")
16+
public String method() {
17+
return "method";
18+
}
19+
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.ejb.remote.remote;
3+
4+
import javax.ejb.Remote;
5+
6+
@Remote
7+
public interface BeanRemote {
8+
String method();
9+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.ejb.remote;
3+
4+
import static org.javaee8.ServerOperations.addUsersToContainerIdentityStore;
5+
import static org.jboss.shrinkwrap.api.asset.EmptyAsset.INSTANCE;
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assume.assumeTrue;
8+
9+
import javax.naming.Context;
10+
import javax.naming.NamingException;
11+
12+
import org.javaee8.RemoteEJBContextFactory;
13+
import org.javaee8.RemoteEJBContextProvider;
14+
import org.javaee8.ejb.remote.remote.Bean;
15+
import org.javaee8.ejb.remote.remote.BeanRemote;
16+
import org.jboss.arquillian.container.test.api.Deployment;
17+
import org.jboss.arquillian.container.test.api.RunAsClient;
18+
import org.jboss.arquillian.junit.Arquillian;
19+
import org.jboss.shrinkwrap.api.Archive;
20+
import org.jboss.shrinkwrap.api.ShrinkWrap;
21+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
22+
import org.junit.After;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
/**
28+
* This class demonstrates and tests how to request an EJB bean from a remote server.
29+
*
30+
* <p>
31+
* {@link RemoteEJBContextProvider} is used, which is a test artifact abstracting the different
32+
* ways this is done for different servers.
33+
*
34+
* @author Arjan Tijms
35+
*
36+
*/
37+
@RunWith(Arquillian.class)
38+
public class RemoteBeanTest {
39+
40+
private RemoteEJBContextProvider remoteEJBContextProvider;
41+
42+
@Deployment
43+
public static Archive<?> deployment() {
44+
45+
// Add user u1 with password p1 and group g1 to the container's native identity store
46+
addUsersToContainerIdentityStore();
47+
48+
return ShrinkWrap.create(JavaArchive.class)
49+
.addClasses(Bean.class, BeanRemote.class)
50+
.addAsManifestResource(INSTANCE, "beans.xml");
51+
}
52+
53+
@Before
54+
public void before() {
55+
remoteEJBContextProvider = RemoteEJBContextFactory.getProvider();
56+
assumeTrue(
57+
"No RemoteEJBContextProvider available in current profile",
58+
remoteEJBContextProvider != null);
59+
}
60+
61+
@After
62+
public void after() {
63+
remoteEJBContextProvider.releaseContext();
64+
}
65+
66+
@Test
67+
@RunAsClient
68+
public void callProtectedRemoteBean() throws NamingException {
69+
70+
try {
71+
72+
// Obtain the JNDI naming context in a vendor specific way.
73+
Context ejbRemoteContext = remoteEJBContextProvider.getContextWithCredentialsSet("u1", "p1");
74+
75+
BeanRemote beanRemote = (BeanRemote) ejbRemoteContext.lookup("java:global/test/Bean");
76+
77+
assertEquals("method", beanRemote.method());
78+
} catch (Exception e) {
79+
e.printStackTrace();
80+
}
81+
}
82+
83+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create-file-user --groups g1 --passwordfile ${project.build.directory}/test-classes/password.txt u1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AS_ADMIN_USERPASSWORD=p1

‎ejb/remote/vendor/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Java EE 8 Samples: EJB - Remote - Vendor #
2+
3+
This module contains vendor specific implementations to obtain the JNDI context from where remote EJB beans can be requested
4+
from with a username/password credential.
5+
6+
## Implementations ##
7+
8+
- payara-glassfish - An implementation that works for both Payara and GlassFish
9+
10+
11+
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Java EE 7 Samples: EJB - Remote - Vendor - Payara and GlassFish #
2+
3+
This modules contains a class that returns a JNDI context suitable for remote lookups against the default URL
4+
for a remote Payara or GlassFish server (localhost). It sets the provided credentials
5+
in a Payara/GlassFish specific way and puts the required client jar on the classpath.
6+
7+
8+
9+

0 commit comments

Comments
 (0)