Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » ClassCastException, totally weird
ClassCastException, totally weird [message #708880] Wed, 03 August 2011 08:40 Go to next message
David Wynter is currently offline David Wynter
Messages: 4578
Registered: July 2009
Senior Member
Hi,

I have an OSGi app which embeds Jetty to provide a RESTful interface
into running Drools processes. We use the gwt-console to provide these.
The gwt-console uses jta and the bitronix transaction manager (btm). But
when it gets to initialize btm it throws a ClassCastException. I add a
breakpoint in their method, shown with an asterisk here:

public TransactionManager getTransactionManager(Properties props)
throws HibernateException {
try {
Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
return (TransactionManager) clazz.getMethod("getTransactionManager",
null).invoke(null, null);//*
}
catch (Exception e) {
throw new HibernateException( "Could not obtain BTM transaction
manager instance", e );
}
}

When I Inspect the clazz.getMethod("getTransactionManager", null) it
throws a NoSuchMethodException in Eclipse at runtime, but it DOES have
the getTransactionManager method when I inspect clazz!!!!

I assume this is a classloader problem and to do with the MANIFEST.MF
However, my collegue has identical MANIFEST.MF and he DOES NOT get this
problem. I am totally lost as to why this should be. I removed older
versions of btm from the local maven repo, which was the only other
version on my machine. I checked the classloader used it is that of the
Jetty servlet.

I am complete stalled, so help much appreciated.

Here is the MANIFEST.MF for theh OSGi app

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TestEngine
Bundle-SymbolicName: TestEngine;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.junit,
com.example.testmodel;bundle-version="1.0.0",
com.example.testmodel.edit;bundle-version="1.0.0",
org.eclipse.core.runtime;bundle-version="3.6.0",
org.eclipse.emf.cdo;bundle-version="3.0.0",
org.eclipse.emf.cdo.common;bundle-version="3.0.0",
org.eclipse.emf.cdo.common.db;bundle-version="3.0.0",
org.eclipse.emf.cdo.server;bundle-version="3.0.0",
org.eclipse.emf.cdo.server.net4j;bundle-version="3.0.0",
org.eclipse.emf.cdo.server.db;bundle-version="3.0.1",
org.eclipse.emf.cdo.net4j;bundle-version="3.0.0",
org.eclipse.emf.cdo.edit;bundle-version="3.0.0",
org.eclipse.net4j.db;bundle-version="3.0.0",
org.eclipse.net4j.tcp;bundle-version="3.0.0",
org.eclipse.net4j.db.h2;bundle-version="3.0.0",
org.apache.derby.core;bundle-version="10.5.1",
org.eclipse.jdt.core;bundle-version="3.6.1",
org.codehaus.groovy;bundle-version="1.7.10",
org.eclipse.jdt.groovy.core;bundle-version="2.5.0",
com.example.edm.core;bundle-version="1.0.0",
com.example.drools.lib;bundle-version="1.0.0",
common-services;bundle-version="1.0.0",
ExceptionManager;bundle-version="1.0.0"
Service-Component: OSGI-INF/component.xml
Bundle-ClassPath: .,
lib/drools/gwt-console-rpc-2.1.jar,
lib/drools/gwt-console-server-integration-2.1.jar,
container/lib/annotations/javax.annotation_1.0.0.v20100513-0750.jar,
container/lib/annotations/org.objectweb.asm_3.1.0.v200803061910.jar,
container/lib/jax-rs/jaxrs-api-1.0.2.GA.jar,
container/lib/jax-rs/resteasy-jaxrs-1.0.2.GA.jar,
container/lib/jax-rs/resteasy-multipart-provider-1.0.2.GA.jar,
container/lib/jndi/javax.activation_1.1.0.v201005080500.jar,
container/lib/jndi/javax.mail.glassfish_1.4.1.v201005082020.jar,
container/lib/jsp/com.sun.el_1.0.0.v201004190952.jar,
container/lib/jsp/ecj-3.6.jar,
container/lib/jsp/javax.el_2.1.0.v201004190952.jar,
container/lib/jsp/javax.servlet.jsp_2.1.0.v201004190952.jar,
container/lib/jsp/javax.servlet.jsp.jstl_1.2.0.v201004190952.jar,
container/lib/jsp/jetty-jsp-2.1-7.4.4.v20110707.jar,
container/lib/jsp/org.apache.jasper.glassfish_2.1.0.v201007080150.jar,

container/lib/jsp/org.apache.taglibs.standard.glassfish_1.2.0.v201004190952.jar,
container/lib/jta/btm-2.1.1.jar,
container/lib/jta/btm-jetty7-lifecycle-2.1.1.jar,
container/lib/jetty-ajp-7.4.4.v20110707.jar,
container/lib/jetty-annotations-7.4.4.v20110707.jar,
container/lib/jetty-client-7.4.4.v20110707.jar,
container/lib/jetty-continuation-7.4.4.v20110707.jar,
container/lib/jetty-deploy-7.4.4.v20110707.jar,
container/lib/jetty-http-7.4.4.v20110707.jar,
container/lib/jetty-io-7.4.4.v20110707.jar,
container/lib/jetty-jmx-7.4.4.v20110707.jar,
container/lib/jetty-jndi-7.4.4.v20110707.jar,
container/lib/jetty-overlay-deployer-7.4.4.v20110707.jar,
container/lib/jetty-plus-7.4.4.v20110707.jar,
container/lib/jetty-policy-7.4.4.v20110707.jar,
container/lib/jetty-rewrite-7.4.4.v20110707.jar,
container/lib/jetty-security-7.4.4.v20110707.jar,
container/lib/jetty-server-7.4.4.v20110707.jar,
container/lib/jetty-servlet-7.4.4.v20110707.jar,
container/lib/jetty-servlets-7.4.4.v20110707.jar,
container/lib/jetty-util-7.4.4.v20110707.jar,
container/lib/jetty-webapp-7.4.4.v20110707.jar,
container/lib/jetty-websocket-7.4.4.v20110707.jar,
container/lib/jetty-xml-7.4.4.v20110707.jar,
container/lib/servlet-api-2.5.jar,
lib/scannotation-1.0.2.jar
Bundle-Activator: com.example.edm.edmengine.Activator
Bundle-ActivationPolicy: lazy


Here is the persistence config used by Hibernate.

<persistence-unit name="org.jbpm.persistence.jpa"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/jbpmDS</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>

<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>

Can someone outline the steps required to find such a weird problem?

Thx.

David
Re: ClassCastException, totally weird [message #710633 is a reply to message #708880] Fri, 05 August 2011 08:28 Go to previous messageGo to next message
David Wynter is currently offline David Wynter
Messages: 4578
Registered: July 2009
Senior Member
No responses. Does this mean that these sort of problems are just too
difficult in OSGi and I should switch to a simpler container like JPF?

Anyone?


On 03/08/11 09:40, David Wynter wrote:
> Hi,
>
> I have an OSGi app which embeds Jetty to provide a RESTful interface
> into running Drools processes. We use the gwt-console to provide these.
> The gwt-console uses jta and the bitronix transaction manager (btm). But
> when it gets to initialize btm it throws a ClassCastException. I add a
> breakpoint in their method, shown with an asterisk here:
>
> public TransactionManager getTransactionManager(Properties props) throws
> HibernateException {
> try {
> Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
> return (TransactionManager) clazz.getMethod("getTransactionManager",
> null).invoke(null, null);//*
> }
> catch (Exception e) {
> throw new HibernateException( "Could not obtain BTM transaction manager
> instance", e );
> }
> }
>
> When I Inspect the clazz.getMethod("getTransactionManager", null) it
> throws a NoSuchMethodException in Eclipse at runtime, but it DOES have
> the getTransactionManager method when I inspect clazz!!!!
>
> I assume this is a classloader problem and to do with the MANIFEST.MF
> However, my collegue has identical MANIFEST.MF and he DOES NOT get this
> problem. I am totally lost as to why this should be. I removed older
> versions of btm from the local maven repo, which was the only other
> version on my machine. I checked the classloader used it is that of the
> Jetty servlet.
>
> I am complete stalled, so help much appreciated.
>
> Here is the MANIFEST.MF for theh OSGi app
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: TestEngine
> Bundle-SymbolicName: TestEngine;singleton:=true
> Bundle-Version: 1.0.0.qualifier
> Bundle-RequiredExecutionEnvironment: JavaSE-1.6
> Require-Bundle: org.junit,
> com.example.testmodel;bundle-version="1.0.0",
> com.example.testmodel.edit;bundle-version="1.0.0",
> org.eclipse.core.runtime;bundle-version="3.6.0",
> org.eclipse.emf.cdo;bundle-version="3.0.0",
> org.eclipse.emf.cdo.common;bundle-version="3.0.0",
> org.eclipse.emf.cdo.common.db;bundle-version="3.0.0",
> org.eclipse.emf.cdo.server;bundle-version="3.0.0",
> org.eclipse.emf.cdo.server.net4j;bundle-version="3.0.0",
> org.eclipse.emf.cdo.server.db;bundle-version="3.0.1",
> org.eclipse.emf.cdo.net4j;bundle-version="3.0.0",
> org.eclipse.emf.cdo.edit;bundle-version="3.0.0",
> org.eclipse.net4j.db;bundle-version="3.0.0",
> org.eclipse.net4j.tcp;bundle-version="3.0.0",
> org.eclipse.net4j.db.h2;bundle-version="3.0.0",
> org.apache.derby.core;bundle-version="10.5.1",
> org.eclipse.jdt.core;bundle-version="3.6.1",
> org.codehaus.groovy;bundle-version="1.7.10",
> org.eclipse.jdt.groovy.core;bundle-version="2.5.0",
> com.example.edm.core;bundle-version="1.0.0",
> com.example.drools.lib;bundle-version="1.0.0",
> common-services;bundle-version="1.0.0",
> ExceptionManager;bundle-version="1.0.0"
> Service-Component: OSGI-INF/component.xml
> Bundle-ClassPath: .,
> lib/drools/gwt-console-rpc-2.1.jar,
> lib/drools/gwt-console-server-integration-2.1.jar,
> container/lib/annotations/javax.annotation_1.0.0.v20100513-0750.jar,
> container/lib/annotations/org.objectweb.asm_3.1.0.v200803061910.jar,
> container/lib/jax-rs/jaxrs-api-1.0.2.GA.jar,
> container/lib/jax-rs/resteasy-jaxrs-1.0.2.GA.jar,
> container/lib/jax-rs/resteasy-multipart-provider-1.0.2.GA.jar,
> container/lib/jndi/javax.activation_1.1.0.v201005080500.jar,
> container/lib/jndi/javax.mail.glassfish_1.4.1.v201005082020.jar,
> container/lib/jsp/com.sun.el_1.0.0.v201004190952.jar,
> container/lib/jsp/ecj-3.6.jar,
> container/lib/jsp/javax.el_2.1.0.v201004190952.jar,
> container/lib/jsp/javax.servlet.jsp_2.1.0.v201004190952.jar,
> container/lib/jsp/javax.servlet.jsp.jstl_1.2.0.v201004190952.jar,
> container/lib/jsp/jetty-jsp-2.1-7.4.4.v20110707.jar,
> container/lib/jsp/org.apache.jasper.glassfish_2.1.0.v201007080150.jar,
>
> container/lib/jsp/org.apache.taglibs.standard.glassfish_1.2.0.v201004190952.jar,
>
> container/lib/jta/btm-2.1.1.jar,
> container/lib/jta/btm-jetty7-lifecycle-2.1.1.jar,
> container/lib/jetty-ajp-7.4.4.v20110707.jar,
> container/lib/jetty-annotations-7.4.4.v20110707.jar,
> container/lib/jetty-client-7.4.4.v20110707.jar,
> container/lib/jetty-continuation-7.4.4.v20110707.jar,
> container/lib/jetty-deploy-7.4.4.v20110707.jar,
> container/lib/jetty-http-7.4.4.v20110707.jar,
> container/lib/jetty-io-7.4.4.v20110707.jar,
> container/lib/jetty-jmx-7.4.4.v20110707.jar,
> container/lib/jetty-jndi-7.4.4.v20110707.jar,
> container/lib/jetty-overlay-deployer-7.4.4.v20110707.jar,
> container/lib/jetty-plus-7.4.4.v20110707.jar,
> container/lib/jetty-policy-7.4.4.v20110707.jar,
> container/lib/jetty-rewrite-7.4.4.v20110707.jar,
> container/lib/jetty-security-7.4.4.v20110707.jar,
> container/lib/jetty-server-7.4.4.v20110707.jar,
> container/lib/jetty-servlet-7.4.4.v20110707.jar,
> container/lib/jetty-servlets-7.4.4.v20110707.jar,
> container/lib/jetty-util-7.4.4.v20110707.jar,
> container/lib/jetty-webapp-7.4.4.v20110707.jar,
> container/lib/jetty-websocket-7.4.4.v20110707.jar,
> container/lib/jetty-xml-7.4.4.v20110707.jar,
> container/lib/servlet-api-2.5.jar,
> lib/scannotation-1.0.2.jar
> Bundle-Activator: com.example.edm.edmengine.Activator
> Bundle-ActivationPolicy: lazy
>
>
> Here is the persistence config used by Hibernate.
>
> <persistence-unit name="org.jbpm.persistence.jpa"
> transaction-type="JTA">
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
> <jta-data-source>java:comp/env/jdbc/jbpmDS</jta-data-source>
> <mapping-file>META-INF/JBPMorm.xml</mapping-file>
> <class>org.drools.persistence.info.SessionInfo</class>
> <class>org.drools.persistence.info.WorkItemInfo</class>
> <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
> <class>org.jbpm.process.audit.ProcessInstanceLog</class>
> <class>org.jbpm.process.audit.NodeInstanceLog</class>
> <class>org.jbpm.process.audit.VariableInstanceLog</class>
>
> <properties>
> <property name="hibernate.dialect"
> value="org.hibernate.dialect.H2Dialect" />
> <property name="hibernate.max_fetch_depth" value="3" />
> <property name="hibernate.hbm2ddl.auto" value="update" />
> <property name="hibernate.show_sql" value="true" />
> <property name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.BTMTransactionManagerLookup" />
> </properties>
> </persistence-unit>
>
> Can someone outline the steps required to find such a weird problem?
>
> Thx.
>
> David
Re: ClassCastException, totally weird [message #710797 is a reply to message #708880] Fri, 05 August 2011 12:20 Go to previous messageGo to next message
BJ Hargrave is currently offline BJ Hargrave
Messages: 55
Registered: July 2009
Member
Why do you do this:

Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");

Why not just reference the class directly? I don't see why you are using reflection here. Using reflection is generally a sign that something will be trouble in OSGi.
Re: ClassCastException, totally weird [message #710805 is a reply to message #710797] Fri, 05 August 2011 12:30 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 436
Registered: July 2009
Senior Member
I am confused by where you get the ClassCastException. In your debugging it seemed you got a NoSuchMethodException. I assume the method you are trying to get is public? If so I also question why you are using reflection and Class.forName. Where is the bitronix.tm package coming from? Is it on your Bundle-ClassPath or from one of the bundles you require?
Re: ClassCastException, totally weird [message #711621 is a reply to message #710797] Sat, 06 August 2011 11:43 Go to previous messageGo to next message
David Wynter is currently offline David Wynter
Messages: 4578
Registered: July 2009
Senior Member
On 05/08/11 13:20, BJ Hargrave wrote:
> Why do you do this:
>
> Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
>
> Why not just reference the class directly? I don't see why you are using
> reflection here. Using reflection is generally a sign that something
> will be trouble in OSGi.

Maybe you missed my reference to the fact this is not my code
"get-console....I add a breakpoint in their method" It is actually part
of the Hibernate transaction support, probably used by 10's of thousands
of developers. So it may be bad practice on their part, but I am not
keen to change it. I also assume that on at least several occasions
people must have used Hibernate underlying a OSGi bundled application?

The gwt console from JBoss uses Hibernate to store data about workflow
Process that run. We embedded gwt console in our OSGi plugin that uses
these workflows.

When I put the breakpoint to inspect clazz I see in
clazz.declaredPublicMethods.referent[1] the value
"getTransactionManager". But when I highlight and Inspect
clazz.getMethod("getTransactionManager", null) it throws
NoSuchMethodException. However I think that is a misleading error,
because when you take the whole line

return (TransactionManager) clazz.getMethod("getTransactionManager",
null).invoke(null, null);

It is throwing the ClassCastException after retrieving the
bitronix.tm.TransactionManagerServices.getTransactionManager.invoke(null,null)

when trying to cast to TransactionManager.

Now this is telling, when I try to attach the source for the btm
TransactionManager it cannot find it even though it is in the containing
OSGi bundle. Does this mean it is not on the classpath?

Also another point being this code works on my colleagues PC and not on
mine when we both check out the code from the same SVN repo, including
the same MANIFEST.MF. You can see the included btm jar on this line
container/lib/jta/btm-2.1.1.jar,

Still not sure how to find this error.

Thx.

David
Re: ClassCastException, totally weird [message #711635 is a reply to message #711621] Sat, 06 August 2011 11:52 Go to previous message
David Wynter is currently offline David Wynter
Messages: 4578
Registered: July 2009
Senior Member
Not being able to find the source was the clue I needed. It is supposed
to be defined for that btm jar, in the .classpath file. It turns out the
btm jar was included in the Debug runtime config, but not on the Project
classpath, my collegues must be different. Must remeber to never
assume... Thx.

David

On 06/08/11 12:43, David Wynter wrote:
> On 05/08/11 13:20, BJ Hargrave wrote:
>> Why do you do this:
>>
>> Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
>>
>> Why not just reference the class directly? I don't see why you are using
>> reflection here. Using reflection is generally a sign that something
>> will be trouble in OSGi.
>
> Maybe you missed my reference to the fact this is not my code
> "get-console....I add a breakpoint in their method" It is actually part
> of the Hibernate transaction support, probably used by 10's of thousands
> of developers. So it may be bad practice on their part, but I am not
> keen to change it. I also assume that on at least several occasions
> people must have used Hibernate underlying a OSGi bundled application?
>
> The gwt console from JBoss uses Hibernate to store data about workflow
> Process that run. We embedded gwt console in our OSGi plugin that uses
> these workflows.
>
> When I put the breakpoint to inspect clazz I see in
> clazz.declaredPublicMethods.referent[1] the value
> "getTransactionManager". But when I highlight and Inspect
> clazz.getMethod("getTransactionManager", null) it throws
> NoSuchMethodException. However I think that is a misleading error,
> because when you take the whole line
>
> return (TransactionManager) clazz.getMethod("getTransactionManager",
> null).invoke(null, null);
>
> It is throwing the ClassCastException after retrieving the
> bitronix.tm.TransactionManagerServices.getTransactionManager.invoke(null,null)
>
> when trying to cast to TransactionManager.
>
> Now this is telling, when I try to attach the source for the btm
> TransactionManager it cannot find it even though it is in the containing
> OSGi bundle. Does this mean it is not on the classpath?
>
> Also another point being this code works on my colleagues PC and not on
> mine when we both check out the code from the same SVN repo, including
> the same MANIFEST.MF. You can see the included btm jar on this line
> container/lib/jta/btm-2.1.1.jar,
>
> Still not sure how to find this error.
>
> Thx.
>
> David
Previous Topic:what's the difference between getResource and getEntry in Bundle interface
Next Topic:possible bug in the osgi launch configuration dialog
Goto Forum:
  


Current Time: Sat Oct 25 07:56:20 GMT 2014

Powered by FUDForum. Page generated in 0.02100 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software