java.lang.NoClassDefFoundError: Could not initialize class org.hornetq.core.client.impl.ClientSessionFactoryImpl
kaluibu Apr 8, 2015 11:56 PMHi,
I am facing some issues while upgrading hornetq 2.0.GA to hornetq2.4.0.Final.
When I am trying to create a Topicconnectionfactory object through JNDI connection, I am getting nullpointer exception.While debugging, I got an exception
" java.lang.NoClassDefFoundError: Could not initialize class org.hornetq.core.client.impl.ClientSessionFactoryImpl".
I am using Proxy class and using newProxyInstance to create TopicConnectionFactory Object. Please see my code below.
***************************************************************************
public class ExceptionInterceptorProxyFactory{
//@SuppressWarnings("unchecked")
public static Object newInstance(Object obj, Class<?>[] interfaces) {
Object myproxy=Proxy.newProxyInstance(ExceptionInterceptorProxyFactory.class.getClassLoader(),
interfaces, new ExceptionInterceptorProxy(obj));
System.out.println("MyProxy instance is " + myproxy);
return myproxy;
}
private static class ExceptionInterceptorProxy implements InvocationHandler {
private Object obj;
public ExceptionInterceptorProxy(Object obj) {
// Proxy.getInvocationHandler(obj);
this.obj = obj;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable{
try {
return method.invoke(obj, args);
} catch (InvocationTargetException ivte) {
JMSUtil.clearCache();
ivte.printStackTrace();
throw ivte.getTargetException().getCause();
} catch (Throwable e) {
JMSUtil.clearCache();
throw e;
}
}
}
}
Here the obj what I am getting is HornetQJMSConnectionFactory object. I dont know why I am getting the same. Everywhere in the code I am using TopicConnectionFactory.
**********************************************************
This is the Code Flow.
1. NotificationConnectionHandler.java
private static TopicConnection getNewTopicConnection(String url) {
TopicConnection connection = null;
try {
connection = JMSUtil.getTopicConnection(url);
connection.start();
} catch (Exception e) {
LOG.warn("Cannot create new topic connection", e);
}
return connection;
}
2. JMSUtil.java
private static AbstractJmxUtil utilImpl;
public static TopicConnection getTopicConnection(String url) throws JMSException
{
return utilImpl.getTopicConnection(url);
}
3. AbstractJmxUtil.java
protected abstract QueueConnectionFactory createQueueConnectionFactory(String url) throws JMSException;
protected abstract TopicConnectionFactory createTopicConnectionFactory(String url) throws JMSException;
Its Implementation is done in HornetqQueueUtil.java
4. HornetqQueueUtil.java
@Override
protected TopicConnectionFactory createTopicConnectionFactory(String url)
throws JMSException {
return (TopicConnectionFactory) createConnectionFactory2(url);
}
______________________________________________________________
protected TopicConnectionFactory createConnectionFactory2(String url) throws JMSException
{
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.put("java.naming.provider.url", url);
props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
try
{
InitialContext initialCtx = new InitialContext(props);
return (TopicConnectionFactory) initialCtx.lookup("/ConnectionFactory");
} catch (NamingException e)
{
// Wrap in JMS exception
throw new JMSException("Failed to lookup inital context for url - '" + url + "'", e.getMessage());
}
}
*********************************
public synchronized TopicConnection getTopicConnection(String url) throws JMSException{ | topicconnection= getTopicConnectionFactory(url).createTopicConnection(); |
return topicconnection;
******************************************************************************************
Method getTopicConnectionFactory(url) is in AbstractJmxUtil.java
5. AbstractJmxUtil.java
protected TopicConnectionFactory getTopicConnectionFactory(String url) throws JMSException{
synchronized (tcfPool) {
if(tcfPool.get(url) == null)
{
Object value=ExceptionInterceptorProxyFactory.newInstance(createTopicConnectionFactory(url), new Class[]{TopicConnectionFactory.class});
//Object value="";
//tcfPool.put(url, (TopicConnectionFactory)ExceptionInterceptorProxyFactory.newInstance(createTopicConnectionFactory(url),
// new Class[]{TopicConnectionFactory.class }));
tcfPool.put(url, (TopicConnectionFactory) value);
System.out.println("Topic Connection pool is " + tcfPool.get(url));
}
return tcfPool.get(url);
}
}
The method Calls newinstance method of the ExceptionInterceptorProxyFactory class which is written above.
Please help me resolve the error.
I am attaching the hornetq configuration files.
-
hornetq-beans.xml.zip 712 bytes
-
hornetq-configuration.xml.zip 883 bytes
-
hornetq-jms.xml.zip 492 bytes
-
hornetq-users.xml.zip 346 bytes
-
jndi.properties.zip 226 bytes