You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by pierrepinon <pp...@smaeur.eu> on 2013/06/12 16:20:14 UTC

Proposal : TomEE embedded documentation

On TomEE website, there is no documentation about TomEE Embedded !

Maven dependencies


<dependency>
	<groupId>org.apache.openejb</groupId>
	<artifactId>tomee-embedded</artifactId>
	<version>1.5.2</version>
</dependency>

Optionnal : For WebServices (REST and SOAP)
<dependency>
	<groupId>org.apache.openejb</groupId>
	<artifactId>tomee-webservices</artifactId>
	<version>1.5.2</version>
</dependency>

Optionnal : For SOAP WebServices
<dependency>
	<groupId>org.apache.openejb</groupId>
	<artifactId>openejb-cxf</artifactId>
	<version>4.5.2</version>
</dependency>

Optionnal : For Custom Broker (Configuration by activemq.xml file)
<dependency>
	<groupId>org.apache.xbean</groupId>
	<artifactId>xbean-spring</artifactId>
	<version>3.13</version>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context</artifactId>
	<version>3.2.3.RELEASE</version>
</dependency>

Build Tomee Embedded Configuration


Configuration configuration = new Configuration();

configuration.setHttpPort(8000);
configuration.setStopPort(8005);
configuration.setDir("/tmp/tomee");

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
LocalInitialContextFactory.class.getName());

//Optionnal : Configure Datasource (SQLServer example)
properties.put("MyDatasource", "new://Resource?type=DataSource");
properties.put("MyDatasource.JdbcDriver",
"net.sourceforge.jtds.jdbc.Driver");
properties.put("MyDatasource.JdbcUrl",
"jdbc:jtds:sqlserver://localhost:1433;DatabaseName=mybase");
properties.put("MyDatasource.UserName", "myuser");
properties.put("MyDatasource.Password", "mypass");

//Optionnal : Configure ActiveMQ
properties.put("MyResourceAdapter",
"new://Resource?type=ActiveMQResourceAdapter");
properties.put("MyResourceAdapter.BrokerXmlConfig",
"broker:(tcp://localhost:61616)"); //Default broker
//properties.put("MyResourceAdapter.BrokerXmlConfig",
"xbean:file:/tmp/activemq.xml"); //Custom broker (by xml)
properties.put("MyResourceAdapter.ServerUrl", "tcp://localhost:61616");

//Optionnal : Configure Connection Factory
properties.put("MyConnectionFactory",
"new://Resource?type=javax.jms.ConnectionFactory");
properties.put("MyConnectionFactory.ResourceAdapter", "MyResourceAdapter");

//Optionnal : Configure JMS Container
properties.put("MyJmsMdbContainer", "new://Container?type=MESSAGE");
properties.put("MyJmsMdbContainer.ResourceAdapter", "MyResourceAdapter");

//Optionnal : Create queue
properties.put("MyQueue", "new://Resource?type=javax.jms.Queue");

configuration.setProperties(properties);

Start Tomee


Container container = new Container();
container.setup(configuration)
container.start();
container.deploy("", "/tmp/ROOT.war", true);
container.deploy("ear", "/tmp/myear.ear", false);
container.deploy("war", "/tmp/mywar.war", true);
container.await();

Tips


Use custom tomcat connector (e.g. : To define SSL or additionnals tomcat
connectors)


I propose a patch who permit to configure custom connector(s). If custom
connector option is not set, default connector was create.

Patch available here (from 1.6.0-SNAPSHOT of 28/05/2013) :
https://github.com/xesnet/test/blob/master/proposal/tomee-embedded.patch

Example for configure SSL


final Connector connector = new Connector(Http11Protocol.class.getName());
connector.setPort(8443);
connector.setAttribute("connectionTimeout", 3000);
connector.setSecure(true);
connector.setScheme("https");
connector.setAttribute("keyAlias", "mykeyalias");
connector.setAttribute("keystorePass", "mykeystorepass");
connector.setAttribute("keystoreFile", "/tmp/myfile.keystore");
connector.setAttribute("clientAuth", "false");
connector.setAttribute("sslProtocol", "TLS");
connector.setAttribute("SSLEnabled", true);

List<Connector> connectors = new ArrayList<Connector>();
connectors.add(connector);
configuration.setConnectors(connectors);

You can inject java properties in activemq.xml by adding in xml file


<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>

If you add in xml this ${activeMQ.dataDirectory}. You just need to write
this code for replacement :

System.setProperty("activeMQ.dataDirectory", "/tmp/activemq_data");






--
View this message in context: http://openejb.979440.n4.nabble.com/Proposal-TomEE-embedded-documentation-tp4663710.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: Proposal : TomEE embedded documentation

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I basically agree and don't get why Tomcat class was designed this way but
that's a tomcat issue IMO (in fact they created it mainly for tests i think
).

Another point is the constraint on Configuration class is to use only
primitive/simple types (boolean, int, java.*) since it is used by
reflection to get some config automatically.


BTW added ssl ssuport (https://issues.apache.org/jira/browse/TOMEE-974)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/6/12 pierrepinon <pp...@smaeur.eu>

> Hello,
>
> It's a shame not to be able to configure this directly without going
> through
> the configuration file.
>
> Thanks for your answer,
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Proposal-TomEE-embedded-documentation-tp4663710p4663717.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: Proposal : TomEE embedded documentation

Posted by pierrepinon <pp...@smaeur.eu>.
Hello,

It's a shame not to be able to configure this directly without going through
the configuration file.

Thanks for your answer,




--
View this message in context: http://openejb.979440.n4.nabble.com/Proposal-TomEE-embedded-documentation-tp4663710p4663717.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: Proposal : TomEE embedded documentation

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

about custom connector it is already possible using a server.xml (should be
available in configuration). This is aligned on the Tomcat embedded.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/6/12 pierrepinon <pp...@smaeur.eu>

> On TomEE website, there is no documentation about TomEE Embedded !
>
> Maven dependencies
>
>
> <dependency>
>         <groupId>org.apache.openejb</groupId>
>         <artifactId>tomee-embedded</artifactId>
>         <version>1.5.2</version>
> </dependency>
>
> Optionnal : For WebServices (REST and SOAP)
> <dependency>
>         <groupId>org.apache.openejb</groupId>
>         <artifactId>tomee-webservices</artifactId>
>         <version>1.5.2</version>
> </dependency>
>
> Optionnal : For SOAP WebServices
> <dependency>
>         <groupId>org.apache.openejb</groupId>
>         <artifactId>openejb-cxf</artifactId>
>         <version>4.5.2</version>
> </dependency>
>
> Optionnal : For Custom Broker (Configuration by activemq.xml file)
> <dependency>
>         <groupId>org.apache.xbean</groupId>
>         <artifactId>xbean-spring</artifactId>
>         <version>3.13</version>
> </dependency>
> <dependency>
>         <groupId>org.springframework</groupId>
>         <artifactId>spring-context</artifactId>
>         <version>3.2.3.RELEASE</version>
> </dependency>
>
> Build Tomee Embedded Configuration
>
>
> Configuration configuration = new Configuration();
>
> configuration.setHttpPort(8000);
> configuration.setStopPort(8005);
> configuration.setDir("/tmp/tomee");
>
> Properties properties = new Properties();
> properties.put(Context.INITIAL_CONTEXT_FACTORY,
> LocalInitialContextFactory.class.getName());
>
> //Optionnal : Configure Datasource (SQLServer example)
> properties.put("MyDatasource", "new://Resource?type=DataSource");
> properties.put("MyDatasource.JdbcDriver",
> "net.sourceforge.jtds.jdbc.Driver");
> properties.put("MyDatasource.JdbcUrl",
> "jdbc:jtds:sqlserver://localhost:1433;DatabaseName=mybase");
> properties.put("MyDatasource.UserName", "myuser");
> properties.put("MyDatasource.Password", "mypass");
>
> //Optionnal : Configure ActiveMQ
> properties.put("MyResourceAdapter",
> "new://Resource?type=ActiveMQResourceAdapter");
> properties.put("MyResourceAdapter.BrokerXmlConfig",
> "broker:(tcp://localhost:61616)"); //Default broker
> //properties.put("MyResourceAdapter.BrokerXmlConfig",
> "xbean:file:/tmp/activemq.xml"); //Custom broker (by xml)
> properties.put("MyResourceAdapter.ServerUrl", "tcp://localhost:61616");
>
> //Optionnal : Configure Connection Factory
> properties.put("MyConnectionFactory",
> "new://Resource?type=javax.jms.ConnectionFactory");
> properties.put("MyConnectionFactory.ResourceAdapter", "MyResourceAdapter");
>
> //Optionnal : Configure JMS Container
> properties.put("MyJmsMdbContainer", "new://Container?type=MESSAGE");
> properties.put("MyJmsMdbContainer.ResourceAdapter", "MyResourceAdapter");
>
> //Optionnal : Create queue
> properties.put("MyQueue", "new://Resource?type=javax.jms.Queue");
>
> configuration.setProperties(properties);
>
> Start Tomee
>
>
> Container container = new Container();
> container.setup(configuration)
> container.start();
> container.deploy("", "/tmp/ROOT.war", true);
> container.deploy("ear", "/tmp/myear.ear", false);
> container.deploy("war", "/tmp/mywar.war", true);
> container.await();
>
> Tips
>
>
> Use custom tomcat connector (e.g. : To define SSL or additionnals tomcat
> connectors)
>
>
> I propose a patch who permit to configure custom connector(s). If custom
> connector option is not set, default connector was create.
>
> Patch available here (from 1.6.0-SNAPSHOT of 28/05/2013) :
> https://github.com/xesnet/test/blob/master/proposal/tomee-embedded.patch
>
> Example for configure SSL
>
>
> final Connector connector = new Connector(Http11Protocol.class.getName());
> connector.setPort(8443);
> connector.setAttribute("connectionTimeout", 3000);
> connector.setSecure(true);
> connector.setScheme("https");
> connector.setAttribute("keyAlias", "mykeyalias");
> connector.setAttribute("keystorePass", "mykeystorepass");
> connector.setAttribute("keystoreFile", "/tmp/myfile.keystore");
> connector.setAttribute("clientAuth", "false");
> connector.setAttribute("sslProtocol", "TLS");
> connector.setAttribute("SSLEnabled", true);
>
> List<Connector> connectors = new ArrayList<Connector>();
> connectors.add(connector);
> configuration.setConnectors(connectors);
>
> You can inject java properties in activemq.xml by adding in xml file
>
>
> <bean
>
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
> </bean>
>
> If you add in xml this ${activeMQ.dataDirectory}. You just need to write
> this code for replacement :
>
> System.setProperty("activeMQ.dataDirectory", "/tmp/activemq_data");
>
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Proposal-TomEE-embedded-documentation-tp4663710.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>