### OpenEJB Start Command Examples
Source: https://github.com/apache/tomee/blob/main/docs/quickstart.adoc
Execute this command to see examples of using the start command with its various options.
```bash
openejb start --examples
```
--------------------------------
### Display OpenEJB Start Command Help
Source: https://github.com/apache/tomee/blob/main/assembly/openejb-standalone/src/main/resources/README.txt
Get help information and command options for starting the OpenEJB server.
```shell
openejb start --help
```
--------------------------------
### Arquillian Test Container Setup
Source: https://github.com/apache/tomee/blob/main/examples/tomee-jersey-eclipselink/README.adoc
This example shows how to programmatically start a new test container using Arquillian. It's typically used in tests to persist entities and verify their presence in the database by retrieving all entities.
```java
We use Arquillian to programmatically start a new test container. In a test a person is persisted, then it's presence in database is checked by retrieving all person entities.
Full example can be found https://github.com/apache/tomee/tree/master/examples/tomee-jersey-eclipselink[here].
It's a maven project, and the test can be run with `mvn clean install` command.
```
--------------------------------
### Build and Run Telephone Stateful Example
Source: https://github.com/apache/tomee/blob/main/docs/embedded-and-remotable.adoc
To run the telephone-stateful example, navigate to its directory and execute the Maven clean install command. This will build the project and run the associated tests.
```bash
$ mvn clean install
```
--------------------------------
### OpenEJB Help and Command Options
Source: https://github.com/apache/tomee/blob/main/docs/quickstart.adoc
Use these commands to get help information and view command options for OpenEJB deploy and start commands.
```bash
openejb deploy --help openejb start --help
```
--------------------------------
### Customize Server Build with a Home Directory Consumer
Source: https://github.com/apache/tomee/blob/main/examples/serverless-builder/README.adoc
This example demonstrates using the `home` method with a `Consumer` to perform actions on the server's temporary home directory after it's created but before the server starts. It lists all files within the home directory.
```java
import org.apache.tomee.bootstrap.Server;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
Server.builder()
.home(Main::list)
.build();
}
private static void list(final File home) {
try {
Files.walk(home.toPath())
.sorted()
.forEach(System.out::println);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
```
--------------------------------
### Maven Command to Run Example
Source: https://github.com/apache/tomee/blob/main/examples/jpa-enumerated/README.adoc
This command navigates to the jpa-enumerated directory and runs the Maven clean install lifecycle, which compiles, tests, and packages the project.
```bash
cd jpa-enumerated
mvn clean install
```
--------------------------------
### Build and Install Project with Maven
Source: https://github.com/apache/tomee/blob/main/examples/import-database-liquibase/README.adoc
Command to clean and install the 'examples/import-database-liquibase' project using Maven.
```bash
mvn clean install
```
--------------------------------
### Start Apache TomEE Server
Source: https://github.com/apache/tomee/blob/main/docs/hello-world.adoc
Navigate to your OpenEJB installation directory and start the server using the provided script. This command initiates the TomEE server process.
```bash
karan@poweredge:~/install/openejb-3.0$ bin/openejb start
```
--------------------------------
### Display Help for openejb start
Source: https://github.com/apache/tomee/blob/main/docs/startup.adoc
Use the -help option to display available command-line options for the `openejb start` command.
```bash
openejb start -help
```
--------------------------------
### OpenEJB Console Output on Startup
Source: https://github.com/apache/tomee/blob/main/docs/startup.adoc
Example of the console output observed after starting the OpenEJB server, indicating version and service status.
```properties
Apache OpenEJB 3.0 build: 20070825-01:10
http://tomee.apache.org/
OpenEJB ready.
```
--------------------------------
### Start TomEE Project with Maven
Source: https://github.com/apache/tomee/blob/main/docs/tomee-mp-getting-started.adoc
Package the application and start the embedded TomEE server using the `tomee:run` goal.
```bash
mvn package tomee:run
```
--------------------------------
### Start OpenEJB Server
Source: https://github.com/apache/tomee/blob/main/docs/getting-started.adoc
Command to start the OpenEJB server from the command prompt.
```java
d:\openejb-3.0.0-SNAPSHOT\bin\openejb start
```
--------------------------------
### Clone Apache TomEE Examples with Git
Source: https://github.com/apache/tomee/blob/main/docs/maven.adoc
Use this command to clone the Apache TomEE project examples from GitHub. Ensure Git is installed and accessible from your console.
```bash
git clone https://github.com/apache/tomee.git
```
--------------------------------
### Start OpenEJB on Unix/Linux/Mac OS X
Source: https://github.com/apache/tomee/blob/main/docs/quickstart.adoc
Navigate to the bin directory and execute the openejb script to start the server on Unix-like systems.
```bash
./bin/openejb
```
--------------------------------
### TomEE Server Startup Output
Source: https://github.com/apache/tomee/blob/main/docs/hello-world.adoc
This is an example of the console output you can expect when the Apache TomEE server starts successfully, indicating that services are ready.
```bash
karan@poweredge:~/install/openejb-3.0$ bin/openejb start
Apache OpenEJB 3.0 build: 20070926-12:34
http://tomee.apache.org/
OpenEJB ready.
```
--------------------------------
### Maven Build Output for Simple JMS Example
Source: https://github.com/apache/tomee/blob/main/examples/simple-jms/README.adoc
This log shows the output of the Maven build process for the simple-jms example, including packaging the WAR file and installing it to the local repository.
```java
[INFO]
[INFO] --- maven-war-plugin:2.4:war (default-war) @ simple-jms ---
[INFO] Packaging webapp
[INFO] Assembling webapp [simple-jms] in [/tomee/examples/simple-jms/target/simple-jms-10.0.0-M1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [2118 msecs]
[INFO] Building war: /tomee/examples/simple-jms/target/simple-jms-10.0.0-M1-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ simple-jms ---
[INFO] Installing /tomee/examples/simple-jms/target/simple-jms-10.0.0-M1-SNAPSHOT.war to /.m2/repository/org/superbiz/simple-jms/10.0.0-M1-SNAPSHOT/simple-jms-10.0.0-M1-SNAPSHOT.war
[INFO] Installing /tomee/examples/simple-jms/pom.xml to /.m2/repository/org/superbiz/simple-jms/10.0.0-M1-SNAPSHOT/simple-jms-10.0.0-M1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 50.089 s
----
```
--------------------------------
### users.properties File Example
Source: https://github.com/apache/tomee/blob/main/docs/refcard/refcard.html
Example format for the users.properties file, mapping usernames to passwords. Each line represents a user.
```properties
user1=pwd1
user3=pwd2
user3=pwd3
```
--------------------------------
### Example persistence.xml
Source: https://github.com/apache/tomee/blob/main/docs/configuring-persistenceunits-in-tests.adoc
This is an example persistence.xml file with a named persistence unit 'movie-unit'.
```xml
org.hibernate.ejb.HibernatePersistence
movieDatabase
movieDatabaseUnmanaged
```
--------------------------------
### groups.properties File Example
Source: https://github.com/apache/tomee/blob/main/docs/refcard/refcard.html
Example format for the groups.properties file, mapping group names to users. Users can be comma-separated.
```properties
group1=user1
group2=user2, user3
```
--------------------------------
### Run Simple JMS Example with Maven
Source: https://github.com/apache/tomee/blob/main/examples/simple-jms/README.adoc
Execute this command in the simple-jms directory to run the example application using the TomEE Maven plugin.
```bash
$ mvn tomee:run
```
--------------------------------
### Start Embedded TomEE with Gradle
Source: https://github.com/apache/tomee/blob/main/docs/developer/tools/gradle-plugins.adoc
Execute the Gradle task to start an embedded TomEE instance. This is the command to run after setting up the plugin.
```properties
gradle tomee-embedded -i
```
--------------------------------
### Simple Log4j2 Configuration for TomEE
Source: https://github.com/apache/tomee/blob/main/docs/admin/configuration/log4j2.adoc
A basic log4j2.xml configuration file to get started with Log4j2 in TomEE. This setup includes console logging and file logging to catalina.log.
```xml
%d %p %c{1.} [%t] %m%n
```
--------------------------------
### Full DataSource Ciphered Password Test Example
Source: https://github.com/apache/tomee/blob/main/examples/datasource-ciphered-password/README.adoc
This is a complete JUnit test class demonstrating the setup and usage of a datasource with a ciphered password, including creating a database user and starting an EJB container.
```java
package org.superbiz;
import org.apache.commons.lang.StringUtils;
import org.apache.openejb.resource.jdbc.PasswordCipher;
import org.junit.BeforeClass;
import org.junit.Test;
import jakarta.annotation.Resource;
import jakarta.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;
import static junit.framework.Assert.assertNotNull;
public class DataSourceCipheredExampleTest {
private static final String USER = DataSourceCipheredExampleTest.class.getSimpleName().toUpperCase();
private static final String PASSWORD = "YouLLN3v3rFindM3";
private static final String DATASOURCE_URL = "jdbc:hsqldb:mem:protected";
@Resource
private DataSource dataSource;
@BeforeClass
public static void addDatabaseUserWithPassword() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
Connection conn = DriverManager.getConnection(DATASOURCE_URL, "sa", "");
conn.setAutoCommit(true);
Statement st = conn.createStatement();
st.executeUpdate("CREATE USER " + USER + " PASSWORD '" + PASSWORD + "';");
st.close();
conn.commit();
conn.close();
}
@Test
public void accessDatasource() throws Exception {
// define the datasource
Properties properties = new Properties();
properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource");
properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver");
properties.setProperty("ProtectedDatasource.JdbcUrl", DATASOURCE_URL);
properties.setProperty("ProtectedDatasource.UserName", USER);
properties.setProperty("ProtectedDatasource.Password", "fEroTNXjaL5SOTyRQ92x3DNVS/ksbtgs");
properties.setProperty("ProtectedDatasource.PasswordCipher", "Static3DES");
properties.setProperty("ProtectedDatasource.JtaManaged", "true");
// start the context and makes junit test injections
EJBContainer container = EJBContainer.createEJBContainer(properties);
Context context = container.getContext();
context.bind("inject", this);
```
--------------------------------
### Console Output Example
Source: https://github.com/apache/tomee/blob/main/examples/movies-complete-meta/README.adoc
Example console output indicating the start of test execution for the MoviesTest class.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.injection.tx.MoviesTest
```
--------------------------------
### HTTP GET Request for Year Status
Source: https://github.com/apache/tomee/blob/main/examples/mp-faulttolerance-retry/README.adoc
This is an example of an HTTP GET request to retrieve the year weather status.
```http
GET http://localhost:8080/mp-faulttolerance-retry/weather/year/statusk
```
--------------------------------
### Execute Deploy Tool Help (Unix/Linux/Mac)
Source: https://github.com/apache/tomee/blob/main/docs/deploy-tool.adoc
Execute the OpenEJB deploy tool with the --help option on Unix-like systems.
```shell
user@host# bin/openejb deploy --help
```
--------------------------------
### HTTP GET Request for Month Status
Source: https://github.com/apache/tomee/blob/main/examples/mp-faulttolerance-retry/README.adoc
This is an example of an HTTP GET request to retrieve the month weather status.
```http
GET http://localhost:8080/mp-faulttolerance-retry/weather/month/status
```
--------------------------------
### System Properties Configuration Example
Source: https://github.com/apache/tomee/blob/main/docs/jms-resources-and-mdb-container.adoc
Demonstrates initializing a Properties object in Java, which can be used for configuring TomEE via system properties.
```java
Properties p = new Properties();
```
--------------------------------
### HTTP GET Request for Weekend Status
Source: https://github.com/apache/tomee/blob/main/examples/mp-faulttolerance-retry/README.adoc
This is an example of an HTTP GET request to retrieve the weekend weather status.
```http
GET http://localhost:8080/mp-faulttolerance-retry/weather/weekend/status
```
--------------------------------
### Execute Deploy Tool Help (Windows)
Source: https://github.com/apache/tomee/blob/main/docs/deploy-tool.adoc
Execute the OpenEJB deploy tool with the --help option on Windows to view available commands and options.
```shell
C:\-3.0> bindeploy --help
```
--------------------------------
### MethodLevelInterceptorOnlyTest Setup
Source: https://github.com/apache/tomee/blob/main/examples/interceptors/README.adoc
Sets up the test environment for MethodLevelInterceptorOnlyTest, including initializing the JNDI context and configuring deployment paths.
```java
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
initCtx = new InitialContext(properties);
```
--------------------------------
### Running Tests Console Output
Source: https://github.com/apache/tomee/blob/main/examples/bean-validation-design-by-contract/README.adoc
Example console output indicating the start of test execution for OlympicGamesTest.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running OlympicGamesTest
```
--------------------------------
### Maven Build Console Output
Source: https://github.com/apache/tomee/blob/main/examples/webservice-handlerchain/README.adoc
The console output from running 'mvn clean install' for the webservice handlers example.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.calculator.wsh.CalculatorTest
INFO - openejb.home = /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
INFO - openejb.base = /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
INFO - Using 'jakarta.ejb.embeddable.EJBContainer=true'
INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Creating TransactionManager(id=Default Transaction Manager)
INFO - Creating SecurityService(id=Default Security Service)
INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers/target/test-classes
INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers/target/classes
INFO - Configuring enterprise application: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
INFO - Auto-deploying ejb Calculator: EjbDeployment(deployment-id=Calculator)
INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
INFO - Auto-creating a container for bean Calculator: Container(type=SINGLETON, id=Default Singleton Container)
INFO - Creating Container(id=Default Singleton Container)
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean org.superbiz.calculator.wsh.CalculatorTest: Container(type=MANAGED, id=Default Managed Container)
INFO - Creating Container(id=Default Managed Container)
INFO - Enterprise application "/Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers" loaded.
INFO - Assembling app: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
INFO - Created Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Singleton Container)
INFO - Started Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Singleton Container)
INFO - Deployed Application(path=/Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers)
INFO - Initializing network services
INFO - Creating ServerService(id=httpejbd)
INFO - Creating ServerService(id=cxf)
INFO - Creating ServerService(id=admin)
INFO - Creating ServerService(id=ejbd)
INFO - Creating ServerService(id=ejbds)
INFO - Initializing network services
INFO - ** Starting Services **
INFO - NAME IP PORT
INFO - httpejbd 127.0.0.1 4204
INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from class org.superbiz.calculator.wsh.CalculatorWs
INFO - Setting the server's publish address to be http://nopath:80
INFO - Webservice(wsdl=http://127.0.0.1:4204/Calculator, qname={http://superbiz.org/wsdl}CalculatorService) --> Ejb(id=Calculator)
INFO - admin thread 127.0.0.1 4200
INFO - ejbd 127.0.0.1 4201
INFO - ejbd 127.0.0.1 4203
INFO - -------
INFO - Ready!
INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl
INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl
INFO - Default SAAJ universe not set
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.783 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
```
--------------------------------
### HTTP Request for Day Status
Source: https://github.com/apache/tomee/blob/main/examples/mp-faulttolerance-timeout/README.adoc
This is an example of an HTTP GET request to retrieve the day's weather status from the application.
```text
GET http://localhost:8080/mp-faulttolerance-timeout/weather/day/status
```
--------------------------------
### Maven Build Output Example
Source: https://github.com/apache/tomee/blob/main/examples/rest-cdi/README.adoc
This is an example of the output you can expect after running the Maven build command. It includes information about test execution, service configuration, and application loading.
```text
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.rest.GreetingServiceTest
INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@1b048504
INFO - Succeeded in installing singleton service
INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Creating TransactionManager(id=Default Transaction Manager)
INFO - Creating SecurityService(id=Default Security Service)
INFO - Initializing network services
INFO - Creating ServerService(id=cxf-rs)
INFO - Creating ServerService(id=httpejbd)
INFO - Created ServicePool 'httpejbd' with (10) core threads, limited to (200) threads with a queue of (9)
INFO - Using 'print=true'
FINE - Using default '.xml=false'
FINE - Using default 'stream.count=false'
INFO - Initializing network services
INFO - ** Bound Services **
INFO - NAME IP PORT
INFO - httpejbd 127.0.0.1 44455
INFO - -------
INFO - Ready!
INFO - Configuring enterprise application: /home/daniel/git/apache/tomee/examples/rest-cdi/GreetingServiceTest
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container)
INFO - Creating Container(id=Default Managed Container)
INFO - Using directory /tmp for stateful session passivation
INFO - Enterprise application "/home/daniel/git/apache/tomee/examples/rest-cdi/GreetingServiceTest" loaded.
INFO - Creating dedicated application classloader for GreetingServiceTest
INFO - Assembling app: /home/daniel/git/apache/tomee/examples/rest-cdi/GreetingServiceTest
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.openejb.util.proxy.LocalBeanProxyFactory$Unsafe (file:/home/daniel/.m2/repository/org/apache/tomee/openejb-core/10.0.0-M1-SNAPSHOT/openejb-core-10.0.0-M1-SNAPSHOT.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.apache.openejb.util.proxy.LocalBeanProxyFactory$Unsafe
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO - Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@1b048504
INFO - Some Principal APIs could not be loaded: org.eclipse.microprofile.jwt.JsonWebToken out of org.eclipse.microprofile.jwt.JsonWebToken not found
INFO - OpenWebBeans Container is starting...
INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
INFO - All injection points were validated successfully.
INFO - OpenWebBeans Container has started, it took 476 ms.
INFO - Using readers:
INFO - org.apache.cxf.jaxrs.provider.PrimitiveTextProvider@693b3e2
INFO - org.apache.cxf.jaxrs.provider.FormEncodingProvider@c68e0782
INFO - org.apache.cxf.jaxrs.provider.MultipartProvider@ef757da4
INFO - org.apache.cxf.jaxrs.provider.SourceProvider@778a403d
INFO - org.apache.cxf.jaxrs.provider.JAXBElementTypedProvider@7bca3240
INFO - org.apache.cxf.jaxrs.provider.JAXBElementProvider@2407e67e
INFO - org.apache.openejb.server.cxf.rs.johnzon.TomEEJsonbProvider@52f938e6
INFO - org.apache.openejb.server.cxf.rs.johnzon.TomEEJsonpProvider@75f6fb76
INFO - org.apache.cxf.jaxrs.provider.StringTextProvider@b06cecc0
INFO - org.apache.cxf.jaxrs.provider.BinaryDataProvider@493b69a5
INFO - org.apache.cxf.jaxrs.provider.DataSourceProvider@5dfe78fe
INFO - Using writers:
INFO - org.apache.johnzon.jaxrs.WadlDocumentMessageBodyWriter@5ec30d6b
```
--------------------------------
### Setup and Teardown for Mail Server in Java
Source: https://github.com/apache/tomee/blob/main/examples/javamail-velocity/README.adoc
Java code for setting up and tearing down a custom GreenMail server for testing email functionality. The setup ensures the mail server is started and configured with user credentials before tests run, and stopped afterwards.
```java
@BeforeAll
public static void setUp() throws InterruptedException {
mailServer = new CustomGreenMailServer(new ServerSetup(SMTP_TEST_PORT, null, "smtp"));
mailServer.start();
//wait for the server startup...
started.await();
// create user on mail server
mailServer.setUser(EMAIL_USER_ADDRESS, USER_NAME, USER_PASSWORD);
}
@AfterAll
public static void tearDown() {
if (mailServer != null) {
mailServer.stop();
}
}
```
--------------------------------
### Install Maven Provisioning (TomEE)
Source: https://github.com/apache/tomee/blob/main/docs/provisioning.adoc
For TomEE, extract the openejb-provisionning zip into the same classloader as TomEE, or configure it via provisioning.properties.
```properties
zip=https://repo1.maven.org/maven2/org/apache/openejb/openejb-provisionning//openejb-provisionning-.zip
```
--------------------------------
### OpenEJB Startup Log
Source: https://github.com/apache/tomee/blob/main/examples/dynamic-datasource-routing/README.adoc
This console output shows the startup process of Apache OpenEJB, including service configuration, module loading, and persistence unit setup.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest
Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
http://tomee.apache.org/
INFO - openejb.home = /Users/dblevins/examples/dynamic-datasource-routing
INFO - openejb.base = /Users/dblevins/examples/dynamic-datasource-routing
INFO - Using 'jakarta.ejb.embeddable.EJBContainer=true'
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=My Router, type=Resource, provider-id=DeterminedRouter)
INFO - Configuring Service(id=database3, type=Resource, provider-id=Default JDBC Database)
INFO - Configuring Service(id=database2, type=Resource, provider-id=Default JDBC Database)
INFO - Configuring Service(id=Routed Datasource, type=Resource, provider-id=RoutedDataSource)
INFO - Configuring Service(id=database1, type=Resource, provider-id=Default JDBC Database)
INFO - Found EjbModule in classpath: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
INFO - Beginning load: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
INFO - Configuring enterprise application: /Users/dblevins/examples/dynamic-datasource-routing
WARN - Method 'lookup' is not available for 'jakarta.annotation.Resource'. Probably using an older Runtime.
INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
INFO - Auto-creating a container for bean BoostrapUtility: Container(type=SINGLETON, id=Default Singleton Container)
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean RoutedPersister: Container(type=STATELESS, id=Default Stateless Container)
INFO - Auto-linking resource-ref 'java:comp/env/My Router' in bean RoutedPersister to Resource(id=My Router)
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest: Container(type=MANAGED, id=Default Managed Container)
INFO - Configuring PersistenceUnit(name=router)
INFO - Configuring PersistenceUnit(name=db1)
INFO - Auto-creating a Resource with id 'database1NonJta' of type 'DataSource for 'db1'.
INFO - Configuring Service(id=database1NonJta, type=Resource, provider-id=database1)
INFO - Adjusting PersistenceUnit db1 to Resource ID 'database1NonJta' from 'null'
INFO - Configuring PersistenceUnit(name=db2)
INFO - Auto-creating a Resource with id 'database2NonJta' of type 'DataSource for 'db2'.
INFO - Configuring Service(id=database2NonJta, type=Resource, provider-id=database2)
INFO - Adjusting PersistenceUnit db2 to Resource ID 'database2NonJta' from 'null'
INFO - Configuring PersistenceUnit(name=db3)
```
--------------------------------
### Simplest OpenEJB Startup Scenario
Source: https://github.com/apache/tomee/blob/main/docs/startup.adoc
Starts the OpenEJB Remote Server with default settings. The ejbd service binds to 127.0.0.1 on port 4201.
```bash
openejb start
```
--------------------------------
### Start OpenEJB on Windows
Source: https://github.com/apache/tomee/blob/main/docs/quickstart.adoc
Navigate to the bin directory in the OPENEJB_HOME and run the openejb command for Windows.
```batch
bin
```
--------------------------------
### Custom GreenMail Server Setup
Source: https://github.com/apache/tomee/blob/main/examples/javamail/README.adoc
Extends GreenMail to provide a custom mail server implementation. It includes logic to signal when the server has started.
```java
public static class CustomGreenMailServer extends GreenMail {
public CustomGreenMailServer(ServerSetup config) {
super(new ServerSetup[]{config});
}
public synchronized void start() {
super.start();
started.countDown();
}
}
```
--------------------------------
### TomEE Server Startup Log Example
Source: https://github.com/apache/tomee/blob/main/examples/security-custom-identitystore/README.adoc
This log snippet shows typical Apache TomEE server startup messages, including protocol handler initialization and overall bootstrap time. It also indicates a 401 Unauthorized status when calling the servlet without credentials.
```bash
....
INFOS: Starting ProtocolHandler ["http-nio-54313"]
juin 24, 2021 2:58:42 PM sun.reflect.DelegatingMethodAccessorImpl invoke
INFOS: Server startup in [4703] milliseconds
juin 24, 2021 2:58:42 PM sun.reflect.DelegatingMethodAccessorImpl invoke
INFOS: Full bootstrap in [7638] milliseconds
Calling MovieServlet without any credentials provided.
juin 24, 2021 2:58:43 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFOS: statusCode=[401] contentType=[text/html]
juin 24, 2021 2:58:43 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
```
--------------------------------
### Maven Build Output Log
Source: https://github.com/apache/tomee/blob/main/examples/groovy-jpa/README.adoc
Example output log from a Maven clean install command for the Groovy JPA project. It shows the startup process of OpenEJB and OpenJPA.
```log
[INFO] Running org.superbiz.groovy.GroovyJPATest
INFO - ********************************************************************************
INFO - OpenEJB http://tomee.apache.org/
INFO - Startup: Sat Sep 07 18:29:58 ECT 2019
INFO - Copyright 1999-2024 (C) Apache OpenEJB Project, All Rights Reserved.
INFO - Version: 10.0.0-M1-SNAPSHOT
INFO - Build date: 20190907
INFO - Build time: 04:10
INFO - ********************************************************************************
INFO - openejb.home = /Users/sergio/workspace/git/tomee/examples/groovy-jpa
INFO - openejb.base = /Users/sergio/workspace/git/tomee/examples/groovy-jpa
INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@71c8becc
INFO - Succeeded in installing singleton service
INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Using 'openejb.deployments.classpath=false'
INFO - Creating TransactionManager(id=Default Transaction Manager)
INFO - Creating SecurityService(id=Default Security Service)
INFO - Configuring enterprise application: /Users/sergio/workspace/git/tomee/examples/groovy-jpa/0db140ef-9d71-4f1a-8ddb-1d0e3feae256.war
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean 0db140ef-9d71-4f1a-8ddb-1d0e3feae256_org.superbiz.groovy.GroovyJPATest: Container(type=MANAGED, id=Default Managed Container)
INFO - Creating Container(id=Default Managed Container)
INFO - Using directory /var/folders/3j/qhs78rln3y9bl0c279f2j13m0000gn/T for stateful session passivation
INFO - Configuring PersistenceUnit(name=groovy)
INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database)
INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'groovy'.
INFO - Creating Resource(id=Default Unmanaged JDBC Database)
INFO - Adjusting PersistenceUnit groovy to Resource ID 'Default Unmanaged JDBC Database' from 'jdbc/groovy'
INFO - Enterprise application "/Users/sergio/workspace/git/tomee/examples/groovy-jpa/0db140ef-9d71-4f1a-8ddb-1d0e3feae256.war" loaded.
INFO - Assembling app: /Users/sergio/workspace/git/tomee/examples/groovy-jpa/0db140ef-9d71-4f1a-8ddb-1d0e3feae256.war
INFO - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested installation of a ClassFileTransformer which requires a JavaAgent. See http://tomee.apache.org/javaagent.html
INFO - OpenJPA dynamically loaded a validation provider.
INFO - PersistenceUnit(name=groovy, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 1142ms
INFO - Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@71c8becc
INFO - Some Principal APIs could not be loaded: org.eclipse.microprofile.jwt.JsonWebToken out of org.eclipse.microprofile.jwt.JsonWebToken not found
INFO - OpenWebBeans Container is starting...
INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
INFO - All injection points were validated successfully.
INFO - OpenWebBeans Container has started, it took 574 ms.
INFO - Deployed Application(path=/Users/sergio/workspace/git/tomee/examples/groovy-jpa/0db140ef-9d71-4f1a-8ddb-1d0e3feae256.war)
INFO - Starting OpenJPA 3.1.0
INFO - Using dictionary class "org.apache.openjpa.jdbc.sql.HSQLDictionary" (HSQL Database Engine 2.3.2 ,HSQL Database Engine Driver 2.3.2).
INFO - Connected to HSQL Database Engine version 2.2 using JDBC driver HSQL Database Engine Driver version 2.3.2.
```
--------------------------------
### TomEE Startup Log
Source: https://github.com/apache/tomee/blob/main/examples/testing-transactions-bmt/README.adoc
Example console output showing the startup information for Apache TomEE, including version and build details. This is typically seen when running tests or deploying applications.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.injection.tx.MoviesTest
INFO - ********************************************************************************
INFO - OpenEJB http://tomee.apache.org/
INFO - Startup: Sat Jul 21 16:39:28 EDT 2012
INFO - Copyright 1999-2024 (C) Apache OpenEJB Project, All Rights Reserved.
INFO - Version: 4.1.0
INFO - Build date: 20120721
INFO - Build time: 12:06
```
--------------------------------
### WebserviceClient Example
Source: https://github.com/apache/tomee/blob/main/examples/ejb-examples/README.adoc
This client demonstrates how to invoke remote web services, both POJO and EJB based, by creating service instances and obtaining proxies to the service endpoints. It requires a substantial classpath setup for CXF.
```java
package org.superbiz.servlet;
import jakarta.xml.ws.Service;
import java.io.PrintStream;
import java.net.URL;
public class WebserviceClient {
/**
* Unfortunately, to run this example with CXF you need to have a HUGE class path. This
* is just what is required to run CXF:
*
* jaxb-api-2.0.jar
* jaxb-impl-2.0.3.jar
*
* saaj-api-1.3.jar
* saaj-impl-1.3.jar
*
*
* cxf-api-2.0.2-incubator.jar
* cxf-common-utilities-2.0.2-incubator.jar
* cxf-rt-bindings-soap-2.0.2-incubator.jar
* cxf-rt-core-2.0.2-incubator.jar
* cxf-rt-databinding-jaxb-2.0.2-incubator.jar
* cxf-rt-frontend-jaxws-2.0.2-incubator.jar
* cxf-rt-frontend-simple-2.0.2-incubator.jar
* cxf-rt-transports-http-jetty-2.0.2-incubator.jar
* cxf-rt-transports-http-2.0.2-incubator.jar
* cxf-tools-common-2.0.2-incubator.jar
*
* geronimo-activation_1.1_spec-1.0.jar
* geronimo-annotation_1.0_spec-1.1.jar
* geronimo-ejb_3.0_spec-1.0.jar
* geronimo-jpa_2.2_spec-1.0.jar
* geronimo-servlet_2.5_spec-1.1.jar
* geronimo-stax-api_1.0_spec-1.0.jar
* jaxws-api-2.0.jar
* axis2-jws-api-1.3.jar
*
* wsdl4j-1.6.1.jar
* xml-resolver-1.2.jar
* XmlSchema-1.3.1.jar
*/
public static void main(String[] args) throws Exception {
PrintStream out = System.out;
Service helloPojoService = Service.create(new URL("http://localhost:8080/ejb-examples/hello?wsdl"), null);
HelloPojo helloPojo = helloPojoService.getPort(HelloPojo.class);
out.println();
out.println("Pojo Webservice");
out.println(" helloPojo.hello(\"Bob\")=" + helloPojo.hello("Bob"));
out.println(" helloPojo.hello(null)=" + helloPojo.hello(null));
out.println();
Service helloEjbService = Service.create(new URL("http://localhost:8080/HelloEjbService?wsdl"), null);
HelloEjb helloEjb = helloEjbService.getPort(HelloEjb.class);
out.println();
out.println("EJB Webservice");
out.println(" helloEjb.hello(\"Bob\")=" + helloEjb.hello("Bob"));
out.println(" helloEjb.hello(null)=" + helloEjb.hello(null));
out.println();
}
}
```
--------------------------------
### EJB Container Output - CDI @RequestScoped
Source: https://github.com/apache/tomee/blob/main/examples/cdi-request-scope/README.adoc
Console output from the EJB container during test execution, showing container startup, module loading, and JNDI bindings, confirming the setup for the CDI @RequestScoped example.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.cdi.requestscope.RestaurantTest
Apache OpenEJB 10.0.0-M1-SNAPSHOT build: 20111224-11:09
http://tomee.apache.org/
INFO - openejb.home = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope
INFO - openejb.base = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope
INFO - Using 'jakarta.ejb.embeddable.EJBContainer=true'
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Found EjbModule in classpath: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes
INFO - Beginning load: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope\target\classes
INFO - Configuring enterprise application: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean cdi-request-scope.Comp: Container(type=MANAGED, id=Default Managed Container)
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean Chef: Container(type=STATELESS, id=Default Stateless Container)
INFO - Enterprise application "c:\\Users\\Daniel\\workspaces\\openejb\\openejb\\examples\\cdi-request-scope" loaded.
INFO - Assembling app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-request-scope
INFO - Jndi(name="java:global/cdi-request-scope/Chef!org.superbiz.cdi.requestscope.Chef")
INFO - Jndi(name="java:global/cdi-request-scope/Chef")
INFO - Jndi(name="java:global/cdi-request-scope/Waiter!org.superbiz.cdi.requestscope.Waiter")
INFO - Jndi(name="java:global/cdi-request-scope/Waiter")
```
--------------------------------
### Extended Persistence Context Setup
Source: https://github.com/apache/tomee/blob/main/docs/openjpa.adoc
Demonstrates setting up an extended persistence context using @PersistenceContext with a specified unit name.
```java
@PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
EntityManager entityManager;
```
--------------------------------
### Example Maven Build Output
Source: https://github.com/apache/tomee/blob/main/examples/jpa-enumerated/README.adoc
This console output shows the results of running the Maven build, including TomEE initialization, EJB container setup, and test execution. It confirms that the tests passed with no failures or errors.
```console
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.superbiz.jpa.enums.MoviesTest
Apache OpenEJB 4.0.0-beta-2 build: 20120115-08:26
http://tomee.apache.org/
INFO - openejb.home = /Users/dblevins/openejb/examples/jpa-enumerated
INFO - openejb.base = /Users/dblevins/openejb/examples/jpa-enumerated
INFO - Using 'jakarta.ejb.embeddable.EJBContainer=true'
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database)
INFO - Found EjbModule in classpath: /Users/dblevins/openejb/examples/jpa-enumerated/target/classes
INFO - Beginning load: /Users/dblevins/openejb/examples/jpa-enumerated/target/classes
INFO - Configuring enterprise application: /Users/dblevins/openejb/examples/jpa-enumerated
INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container)
INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
INFO - Auto-creating a container for bean org.superbiz.jpa.enums.MoviesTest: Container(type=MANAGED, id=Default Managed Container)
INFO - Configuring PersistenceUnit(name=movie-unit)
INFO - Auto-creating a Resource with id 'movieDatabaseNonJta' of type 'DataSource for 'movie-unit'.
INFO - Configuring Service(id=movieDatabaseNonJta, type=Resource, provider-id=movieDatabase)
INFO - Adjusting PersistenceUnit movie-unit to Resource ID 'movieDatabaseNonJta' from 'movieDatabaseUnmanaged'
INFO - Enterprise application "/Users/dblevins/openejb/examples/jpa-enumerated" loaded.
INFO - Assembling app: /Users/dblevins/openejb/examples/jpa-enumerated
INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 406ms
INFO - Jndi(name="java:global/jpa-enumerated/Movies!org.superbiz.jpa.enums.Movies")
INFO - Jndi(name="java:global/jpa-enumerated/Movies")
INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
INFO - Deployed Application(path=/Users/dblevins/openejb/examples/jpa-enumerated)
INFO - Undeploying app: /Users/dblevins/openejb/examples/jpa-enumerated
INFO - Closing DataSource: movieDatabase
INFO - Closing DataSource: movieDatabaseNonJta
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.831 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
```
--------------------------------
### InitialContext Setup for EJB over EJBDS
Source: https://github.com/apache/tomee/blob/main/docs/ejb-over-ssl.adoc
Configure the InitialContext to connect to an EJB service using the secure EJBDS protocol. Note: The example URL uses 'ejbd://localhost:4201' which might differ from the server configuration port.
```java
Properties p = new Properties();
p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
p.put("java.naming.provider.url", "ejbd://localhost:4201");
// user and pass optional
p.put("java.naming.security.principal", "myuser");
p.put("java.naming.security.credentials", "mypass");
InitialContext ctx = new InitialContext(p);
MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote");
```
--------------------------------
### MovieRepositoryTest Setup
Source: https://github.com/apache/tomee/blob/main/examples/jakarta-data-repository/README.adoc
Shows the basic setup for testing the 'MovieRepository' using TomEE's 'ApplicationComposer'. The repository and service are injected via CDI, and tests utilize 'UserTransaction' for isolation.
```java
@RunWith(ApplicationComposer.class)
public class MovieRepositoryTest {
```