Re: Unit testing code containing DirContext resource injection

2009-07-09 Thread Allan Lykke Christensen
Thanks for the tips David. It has taken me ages getting back to the  
code where I was using OpenEJB for testing, hence the late response.


In terms of LDAP, I figured that there was no need to inject it via  
JNDI. DirContext is already connection pooled by default and adding it  
to the JNDI registry wouldn't really serve any purpose.


However, the RAR technique will come in handy as I'm trying to use the  
JackRabbit Content Repository Service. I've never had to work with RAR  
before, so I'll have to get my head around how it works before  
bothering you more.


I still got an issue relating to what I was doing initially with  
LDAP.   I've got some objects that are added to the JNDI registry at  
run-time. Hence,  I don't know their JNDI names at compile-time. I've  
got the following code in one of my EJBs to look up the objects:



public ContentService getRepository(String jndiName) throws  
NamingException {

Context ctx = new InitialContext();
ContentService cs = (ContentService) ctx.lookup(jndiName);
return cs;
}


In my unit test I  bind some "ContentService" objects to the  
InitialContext


@Test
public void testGetRepository() {
Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");

InitialContext initialContext = new InitialContext(p);
initialContext.bind("cs/MyObject", new ContentService("Something  
something"));


ContentFacadeLocal bean = (ContentFacadeLocal)  
getInitialContext().lookup(BEAN_INTERFACE);

try {
ContentService cs = bean.getRepository("cs/MyObject");
assertNotNull(cs);
} catch (NamingException ex) {
fail(ex.getMessage());
}
}

When I run the test a NamingException is thrown with the message  
"javax.naming.NoInitialContextException: Need to specify class name in  
environment or system property, or as an applet parameter, or in an  
application resource file:  java.naming.factory.initial"


While debugging the test I realised that the InitialContext created in  
the bean didn't have the Context.INITIAL_CONTEXT_FACTORY injected.  
Isn't this suppose to happen transparently?


Thanks again for your help! Woking on a series of blog entries focused  
on unit testing where OpenEJB is the cornerstone.


All the best,
 Allan

On 19/06/2009, at 22.58, David Blevins wrote:



On Jun 19, 2009, at 1:53 AM, Allan Lykke Christensen wrote:


Thanks for your response.

I'm starting to think that my LDAP integration is non-standard and  
should be done in another way. What you are suggesting is that  
there might be a JCA connector for LDAP?  In any case, there is  
nothing vendor-specific about my current integration. I'm using a  
vendor-neutral LdapConnectionFactory for obtaining a connection  
from a connection pool.  Perhaps I should bring the connection code  
into my application instead and forget about registering the JNDI  
name in GlassFish. Having a bit of difficulty finding the best  
practice for my use case as you can probably sense.


If the LDAP support is coming from a JCA connector (which it sounds  
like it is), then you have a picture perfect setup and I wouldn't  
change a thing.


To get this to work in OpenEJB/Maven land we just need to deploy  
your .rar file that is providing the LDAP support.


This is a bit of work to setup as we have to work around Maven --  
Maven does not like rars.  We essentially need to "unwrap" that rar  
as Maven is hardwired to ignore rar files and will not included them  
in the classpath as it doesn't know how to include the jars *inside*  
the rar in the classpath.


So one basic technique I've used is to sort of convert the rar to a  
maven module by making a new module named after the rar in some way  
(any name is fine), copying the ra.xml file to src/main/resources/ 
META-INF/ra.xml, and declaring maven dependencies on all the jars  
the rar needs (i.e. the ones you normally find inside the rar file).


The trick is that usually the jars inside the rar are not available  
in any maven repos so you'll have to install them all into your  
local repo.  If you're lazy like me, you can just make up groupId  
and artifactIds for these jars and add them to the pom.xml as if  
they were already in the repo, then just run a 'mvn clean install'  
and maven will be kind enough to spit out all the 'install:install- 
file' commands with the parameters already filled in.


Once you have that "rar replacement module" you can simply depend on  
it from your ejb module and OpenEJB will find and deploy the rar and  
all the injection should work fine.


An example exists, but unfortunately we can't include it in our  
examples zip as it has LGPL'ed code in it which is not allowed for  
us.  But here's the related email and JIRA issue:


http://www.nabble.com/need-help-getting-quartz-ra.rar-file-to-deploy-tp18531000p18783086.html
(http//issues.apache.org/jira/secure/attachment/123873

Re: MDB to listen to Tibco JMS

2009-07-09 Thread DimasOwl

Hi,
Thank a lot for you answer, Jean
I've tried to follow you suggestion
now I've got 
2009-07-09 09:09:31,912 - ERROR - Endpoint connection to JMS broker failed:
Wire format negociation timeout: peer did not send his wire format.
2009-07-09 09:09:31,913 - ERROR - Endpoint will try to reconnect to the JMS
broker in 30 seconds


openejb.xml 

  # Broker configuration URI as defined by ActiveMQ
  # see http://activemq.apache.org/broker-configuration-uri.html

  BrokerXmlConfig

  # Broker address

  ServerUrl tcp://lonmmsjmsu1.uk.db.com:10140

  # DataSource for persistence messages

  DataSource My Unmanaged DataSource


and  here is annotation from MDB
@MessageDriven
(activationConfig = {
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "EventsTopic"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "acknowledgeMode",
propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName =
"subscriptionDurability",
propertyValue = "NonDurable")
}
)
***


More questions:
How to describe user and password to connect to topic?
And what is suspicious is why it doesn't throw  authentication Exception 


Jean-Louis MONTEIRO wrote:
> 
> Hi,
> 
> AFAIK, Active MQ is used both:
> - server (optional): used when you want to start an embedded broker
> - client: Active MQ is used to connect to a broker (ActiveMQ, MQSeries,
> TibcoRV, ...)
> 
> So a configuration like the following should work.
> 
>  
> # Broker configuration URI as defined by ActiveMQ
> # see http://activemq.apache.org/broker-configuration-uri.html
> # We can leave it empty because we don't want to start an embedded
> ActiveMQ broker
> BrokerXmlConfig
> 
> # Broker address
> # It must point to your Tibco broker
> ServerUrl tcp://:
> 
> # Specifies the size of the thread pool available to ActiveMQ.
> ThreadPoolSize 30
>   
> 
> Jean-Louis
> 
> 

-- 
View this message in context: 
http://www.nabble.com/MDB-to-listen-to-Tibco-JMS-tp24369433p24406229.html
Sent from the OpenEJB User mailing list archive at Nabble.com.