Hi,

addition:

Tried to get my application running with Hibernate as JPA-Provider on Tomcat
with Openejb:
Openejb is loaded during startup of Tomcat, hence the Classes in
<openejb-webapp>\lib (yes lib) are loaded very early. Take care to do the
same Class Loading Order in your Development environment, otherwise you
can't compare the two infrastructures.

There seems to be a problem with slf4j-api-1.3.1.jar and
slf4j-jdk14-1.3.1.jar (part of Openejb 3.1).

I had to update these to version 1.5.2. (otherwise LinkageError or no such
Method Error), because i use Hibernate-Entitymanager 3.4.0.GA and
Hibernate-Annotations 3.4.0.GA (and the corresponding delivered dependencies
see below).

I also had to copy all Hibernate jars into <openejb-webapp>\lib folder
instead of in WEB-INF\lib (is this really intended?), otherwise you get
NoClassDef Found Error:

09.01.2009  23:10           443.432 antlr.jar
09.01.2009  23:10            26.360 asm.jar
09.01.2009  23:10           282.338 cglib.jar
09.01.2009  23:10           313.898 dom4j.jar
09.01.2009  23:10           279.714 hibernate-annotations.jar
09.01.2009  23:10            66.993 hibernate-commons-annotations.jar
09.01.2009  23:10         2.266.769 hibernate-core.jar
09.01.2009  23:10           119.292 hibernate-entitymanager.jar
10.01.2009  01:49                 0 hibernate.txt
09.01.2009  23:10           471.005 javassist.jar
09.01.2009  23:13               230 Readme_Hibernate.txt
09.01.2009  23:11            17.384 slf4j-api-1.5.2.jar
09.01.2009  23:11             8.643 slf4j-jdk14-1.5.2.jar

As i wrote TimerService is working in JUnit-Tests, but not in Tomcat with
Openejb! It is initialized, but fires never. No special Openejb-Log-Entry
for this. Any idea about this?

With the Transaction-Openejb-Logging-Fix now transactions work.

Still have to test Mail Session. Additionally access to InnermostConnection
(we are using some features of the Oracle Driver).

JSF 1.2 and EJB-Injection currently no problem. 

Best regards,

Jens


JensToerber wrote:
> 
> Hi David,
> 
> thanks a lot. Yes, had a little problems with my logging and some
> Openejb-Auto-Correction-Logging-Entries are a little bit confusing for me.
> 
> There are hopefully only 2 things left.
> 
> Currently i am assembling all hints together and then will try to get
> everything running on Tomcat with Openejb:
> 
> 1.) DataSource-Resource:
> You may specify connection properties. Is it possible to specify a SQL
> statement on new connection?
> The idea is to execute some ALTER SESSION ... statements for Oracle.
> 
> Ok i know and also read here that you may take an
> Oracle-Session-Logon-Trigger where you may execute some statements.
> And some things may be configurable via connection properties.
> We are used by JBoss to configure it in the JBoss *-ds.xml file
> <new-connection-sql/>.
> 
> 2.) javax.mail.Session:
> There is no property specified in the documentation for <Resource> in
> openejb.xml.
> Is it configured via System properties (hm, how about several applications
> querying using different servers) or does each client have to take care of
> the mail settings?
> Could not find very much about this topic.
> 
> Thanks in advance.
> 
> Best regards,
> 
> Jens
> 
> David Blevins wrote:
>> 
>> 
>> On Dec 28, 2008, at 2:12 PM, JensToerber wrote:
>> 
>>>
>>> Hi again,
>> 
>> Hi Jens!
>> 
>>> I did not manage to run OpenEJB on Oracle in JUnit-Test if i  
>>> configure it
>>> like this:
>>> p.put(DATASOURCE, "new://Resource?type=DataSource");
>>>        p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>>>        // it is not working thin driver is complaining about missing
>>> username and/or password
>>>        // p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" +  
>>> USERNAME +
>>> "/" + PASSWORD + "@192.168.2.96:1521:ORCL");
>>>        p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin:" + USERNAME  
>>> + "/"
>>> + PASSWORD + "@192.168.2.99:1521:XE");
>>>        p.put("oracle.jdbc.user", USERNAME);
>>>        p.put("oracle.jdbc.username", USERNAME);
>>>        p.put("oracle.jdbc.password", PASSWORD);
>>>        p.put("user", "openejb");
>>>        p.put("password", "openejb");
>>>        p.put(DATASOURCE + ".JdbcUsername", "openejb");
>>>        p.put(DATASOURCE + ".JdbcPassword", "openejb");
>>>        // openejb always sets the username to sa and password to ""
>> 
>> You'll want to specify the "username" and "password" properties as  
>> follows:
>> 
>>          p.put("Oracle", "new://Resource?type=DataSource");
>>          p.put("Oracle.JdbcDriver", "oracle.jdbc.OracleDriver");
>>          p.put("Oracle.JdbcUrl", "jdbc:oracle:thin: 
>> 192.168.2.99:1521:XE");
>>          p.put("Oracle.Username", "foo");
>>          p.put("Oracle.Password", "bar");
>> 
>> Or if you want to use a "DATASOURCE" variable as you showed in your  
>> code then like this:
>> 
>>          String DATASOURCE = "Oracle";
>>          String USERNAME = "foo";
>>          String PASSWORD = "bar";
>> 
>>          p.put(DATASOURCE, "new://Resource?type=DataSource");
>>          p.put(DATASOURCE + ".JdbcDriver", "oracle.jdbc.OracleDriver");
>>          p.put(DATASOURCE + ".JdbcUrl", "jdbc:oracle:thin: 
>> 192.168.2.99:1521:XE");
>>          p.put(DATASOURCE + ".Username", USERNAME);
>>          p.put(DATASOURCE + ".Password", PASSWORD);
>> 
>> Note that all properties are not case-sensitive, so "username" and  
>> "password" will work as will "UsErNaMe" and "pAsSwOrD" and so on.
>> 
>> With the way you have it configured, you should see these four  
>> warnings in your log file saying that your guesses are not correct:
>> 
>>      WARN - Property "JdbcUsername" not supported by "Oracle"
>>      WARN - Property "jdbc.username" not supported by "Oracle"
>>      WARN - Property "JdbcPassword" not supported by "Oracle"
>>      WARN - Property "jdbc.user" not supported by "Oracle"
>>      WARN - Property "jdbc.password" not supported by "Oracle"
>> 
>>> Then i found something here to configure OpenEJB in JUnit-Tests via
>>> openejb.xml:
>>> Properties properties = getProperties();
>>>     
>>>             URL config =
>>> this.getClass().getClassLoader().getResource("META-INF/openejb.xml");
>>>             properties.setProperty("openejb.configuration",
>>> config.toExternalForm());
>>>     
>>>             Context retContext = null;
>>>     
>>>             try {
>>>                             retContext = new InitialContext(properties);
>>>
>>>            ...
>>>
>>> Then Oracle Datasource is working in JUnit-Tests.
>>> Fine.
>> 
>> That's also a fine way to configure things for a test case.
>> 
>>> Got Timer running in OpenEJB JUnit-Test. It's straight forward.
>> 
>> Great!
>> 
>>> I tried to get an MDB running. This is working now in my JBoss  
>>> (without
>>> OpenEJB), not yet tested in Tomcat with OpenEJB, but it is not  
>>> working in
>>> OpenEJB-JUnit-Test.
>>>
>>> Initialization is working, OpenEJB does not complain about missing  
>>> Queue in
>>> configuration.
>>>
>>> I don't know if it should work in JUnit-Test.
>>> Here my inspection code:
>>> obj = retContext.lookup("<queue>");
>>>                             if (obj instanceof ActiveMQQueue) {
>>>                                     ActiveMQQueue activeMQQueue  = 
>>> (ActiveMQQueue) obj;
>>>                                     
>>>                                     String physicalName = 
>>> activeMQQueue.getPhysicalName(); // value  
>>> of
>>> destination of openejb.xml - <Resource ...>destination ...</resource
>>>                                     log.debug("physicalName: " + 
>>> physicalName);
>>>                                     String qualifiedName = 
>>> activeMQQueue.getQualifiedName(); //
>>> queue://<physicalName>
>>>                                     log.debug("qualifiedName: " + 
>>> qualifiedName);                                   
>>>                                     String destinationTypeAsString =
>>> activeMQQueue.getDestinationTypeAsString(); // Queue
>>>                                     log.debug("destinationTypeAsString: " + 
>>>  
>>> destinationTypeAsString);                                   
>>>                                     // may throw JMSException:
>>>                                     String queueName = 
>>> activeMQQueue.getQueueName(); // equals to
>>> <physicalName> (?)
>>>                                     log.debug("queueName: " + queueName);   
>>>                         
>>>                                     Map options = 
>>> activeMQQueue.getOptions(); // currently null
>>>                                     log.debug("options: " + options);       
>>>                         
>>>                                     Properties ps = 
>>> activeMQQueue.getProperties();
>>>                                     logProperties(ps);
>>>                                     log.debug("ps: " + ps);                 
>>>         
>>>                             }
>>>
>>> I'll add my current openejb.xml file (for JUnit-Test).
>> 
>> Currently, you cannot lookup topics and queues directly inside a test  
>> case, you need to have an EJB (or servlet when in tomcat) lookup the  
>> topic or queue and pass it back.
>> 
>> This can be quite easy, however, by just including a bean as an inner  
>> class that declares dependencies on the resources you need.  For  
>> example:
>> 
>> public class MessagingTest extends TestCase {
>> 
>>      public void test() throws Exception {
>>          Properties p = new Properties();
>>          p.put(Context.INITIAL_CONTEXT_FACTORY,  
>> "org.apache.openejb.client.LocalInitialContextFactory");
>>          InitialContext context = new InitialContext(p);
>> 
>>          TestClient bean = (TestClient)  
>> context.lookup("TestClientBeanLocal");
>> 
>>          ConnectionFactory connectionFactory =  
>> bean.getConnectionFactory();
>> 
>>          Queue questionQueue = bean.getQueue();
>> 
>>          Connection connection = null;
>>          Session session = null;
>> 
>>          try {
>>              connection = connectionFactory.createConnection();
>>              connection.start();
>> 
>>              // Create a Session
>>              session = connection.createSession(false,  
>> Session.AUTO_ACKNOWLEDGE);
>> 
>>              // Create a MessageProducer from the Session to the Topic  
>> or Queue
>>              MessageProducer producer =  
>> session.createProducer(questionQueue);
>>              producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>> 
>>              // Create a message
>>              TextMessage message = session.createTextMessage("Hello  
>> World");
>> 
>>              // Tell the producer to send the message
>>              producer.send(message);
>>          } finally {
>>              // Clean up
>>              if (session != null) session.close();
>>              if (connection != null) connection.close();
>>          }
>> 
>>      }
>> 
>>      @Stateless
>>      public static class TestClientBean implements TestClient {
>> 
>>          @Resource
>>          private ConnectionFactory connectionFactory;
>> 
>>          @Resource(name = "FooQueue")
>>          private Queue queue;
>> 
>>          public ConnectionFactory getConnectionFactory() {
>>              return connectionFactory;
>>          }
>> 
>>          public Queue getQueue() {
>>              return queue;
>>          }
>>      }
>> 
>>      public interface TestClient {
>> 
>>          public ConnectionFactory getConnectionFactory();
>> 
>>          public Queue getQueue();
>>      }
>> }
>> 
>> For this to work you'll need to add a META-INF/ejb-jar.xml to your  
>> test sources directory (src/test/resources/ for Maven).  We'll then  
>> scrape your test classes for ejbs as well and process them with your  
>> other applications.  Quite a lot of interesting testing techniques can  
>> be done this way.
>> 
>> 
>>> Currenlty i am not quite sure how to configure an ActiveMQ  
>>> persistent Queue
>>> in OpenEJB.
>>>
>>> ActiveMQ creates the Destination on the fly. In JBoss you have to  
>>> configure
>>> Queues in advance to be persistent. Non-persistent are created on  
>>> the fly.
>>>
>>> There is a service-jar.xml in openejb.war\org.apache.openejb.tomcat 
>>> \META-INF
>>> or openejb.war\WEB-INF\classes\META-INF\org.apache.openejb.tomcat 
>>> \META-INF.
>> 
>> The service-jar.xml is there to specify the default values for  
>> properties that haven't been explicitly configured the user.  We use a  
>> different service-jar.xml for unit testing that we do for usage in  
>> Tomcat, for example.  In unit testing the service-jar.xml sets up a  
>> profile that by default will not open any ports or consume any disk  
>> (i.e. no embedded database files and no persistence message stores).   
>> In Tomcat the service-jar.xml sets up a profile that by default will  
>> open ports for things like the message broker and also use disk for  
>> persistence message stores.
>> 
>> But as mentioned, this only affects the defaults when not specified.   
>> In all cases you can set things up explicitly how you would like  
>> them.  Here's how you would setup ActiveMQ for more of an online mode:
>> 
>> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>>    # Broker configuration URI as defined by ActiveMQ
>>    # see http://activemq.apache.org/broker-configuration-uri.html
>>    BrokerXmlConfig = broker:(tcp://localhost:61616)?useJmx=false
>> 
>>    # Broker address
>>    ServerUrl = tcp://localhost:61616
>> 
>>    # DataSource for persistence messages, should be the "id" of a  
>> <Resource> of type DataSource
>>    DataSource = MyDataSource
>> </Resource>
>> 
>> 
>> Here's a more offline mode which we typically recommend for test cases  
>> as all clients are in the same VM.  No ports will be opened with this  
>> configuration:
>> 
>> <Resource id="MyJMSResourceAdapter" type="ActiveMQResourceAdapter">
>>    # Broker configuration URI as defined by ActiveMQ
>>    # see http://activemq.apache.org/broker-configuration-uri.html
>>    BrokerXmlConfig = broker:()/localhost?persistent=false
>> 
>>    # Broker address
>>    ServerUrl = vm://localhost?async=true
>> 
>>    # DataSource for persistence messages, should be the "id" of a  
>> <Resource> of type DataSource
>>    DataSource = MyDataSource
>> </Resource>
>> 
>> 
>> -David
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/OpenEJB-on-Oracle-tp20294024p21383484.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to