lemonzone2010 / javamelody

Automatically exported from code.google.com/p/javamelody
0 stars 0 forks source link

connection enrichment on the proxy object #422

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Database setup with JNDI and java melody.
2. capsulate the JNDI bean :

<bean id="dataSource" class="be.chillworld.auditing.AuditableDataSource" 
c:audit="true" p:dataSource-ref="ds" >
        <property name="dbUserId" value="${hibernate.audit.dbuser}" /> 
    </bean

    <jee:jndi-lookup id="ds" jndi-name="java:/ebulletin" default-ref="dslocal"/>

3. add following to the AuditableDataSource :

    @Override
    public Connection getConnection() throws SQLException {
        return enrichConnection(dataSource.getConnection());
    }

4. implementation of enrichConnection :

    @Override
    public void enrichConnection(Connection connection, String userId) throws SQLException {
        OracleConnection oConn = null;
        if (connection instanceof OracleConnection) { // without JNDI
            oConn = (OracleConnection) connection;
        } else  {
           // with JNDI I get $proxy64 class who implements only java.sql.Connection, see picture
        }
        String[] metrics = new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];
        metrics[OracleConnection.END_TO_END_CLIENTID_INDEX] = userId;
        if (oConn!=null) {
            oConn.setEndToEndMetrics(metrics, (short) 0);
        }

What is the expected output? What do you see instead?
Enrichment of the underlying connection => result is error cause I can't get to 
mine real connection.

What version of the product are you using? On what application server, JDK,
operating system?
Jboss 4.05, Java-6
<spring.version>3.2.8.RELEASE</spring.version>
        <spring.security.version>3.2.3.RELEASE</spring.security.version>
    <spring.data.jpa.version>1.4.3.RELEASE</spring.data.jpa.version>
        <spring.ldap.version>2.0.0.RELEASE</spring.ldap.version>
        <spring-security-kerberos-core.version>1.0.0.M3</spring-security-kerberos-core.version>
    <hibernate.version>4.2.8.Final</hibernate.version>
    <slf4j.version>1.7.5</slf4j.version>
    <logback.version>1.0.13</logback.version>
    <log4j.version>1.2.17</log4j.version>
    <zk.version>6.5.3</zk.version>
    <melody.version>1.46.0</melody.version>
    <querydsl.version>3.3.0</querydsl.version>
    <jpamodelgen.version>1.3.0.Final</jpamodelgen.version>
    <guava.version>15.0</guava.version>
    <junit.version>4.11</junit.version>
    <joda-time.version>2.3</joda-time.version>
    <resteasy.version>2.2.3.GA</resteasy.version>
    <servlet-api.version>2.5</servlet-api.version>
    <commons-collections.version>3.2.1</commons-collections.version>
    <commons-io.version>2.4</commons-io.version>
    <spring-data-oracle.version>1.0.0.RELEASE</spring-data-oracle.version>
    <hibernate-jpa-2.0-api.version>1.0.1.Final</hibernate-jpa-2.0-api.version>

Please provide any additional information below.

I need to set the enrichment and what I do try I can't figure it out. Is it 
possible to call the method or disable the proxyfying (or do it later)

Original issue reported on code.google.com by filip.co...@gmail.com on 17 Jul 2014 at 1:43

GoogleCodeExporter commented 9 years ago
I don't see the picture so here it is in a link :
http://i.stack.imgur.com/0jXij.png

Question on Stackoverflow :

http://stackoverflow.com/questions/24803719/java-melody-proxyobject-need-to-call
-method-of-proxyd-object-or-get-underlying-o

Original comment by filip.co...@gmail.com on 17 Jul 2014 at 1:46

GoogleCodeExporter commented 9 years ago
here is the picture

Original comment by evernat@free.fr on 18 Jul 2014 at 11:45

Attachments:

GoogleCodeExporter commented 9 years ago
If you want to cast to OracleConnection like this, you are supposed to call the 
Connection.unwrap method first.

It was created for that in the java.sql API
http://docs.oracle.com/javase/6/docs/api/java/sql/Wrapper.html#unwrap%28java.lan
g.Class%29

For example:
        Connection unwrappedConnection = connection.unwrap(Connection.class)
        OracleConnection oConn = null;
        if (unwrappedConnection instanceof OracleConnection) {
            oConn = (OracleConnection) unwrappedConnection;
        }

Original comment by evernat@free.fr on 18 Jul 2014 at 12:01

GoogleCodeExporter commented 9 years ago
Is it OK and can we close this issue?

Original comment by evernat@free.fr on 18 Jul 2014 at 12:02

GoogleCodeExporter commented 9 years ago
Sorry, forto's to say in originaliteit thread that the unwrap throws 
abstractmethoderror on wrappedconnecton.class and oracleconnection.class.

Original comment by filip.co...@gmail.com on 19 Jul 2014 at 9:54

GoogleCodeExporter commented 9 years ago
I don't understand at the moment why you have an abstractmethoderror for unwrap 
on the wrapped connection.
Can you give the stack-trace of the error to clarify that?

Original comment by evernat@free.fr on 19 Jul 2014 at 12:02

GoogleCodeExporter commented 9 years ago
I can give you that in a couple days. Need to be back at work in around 60 
hours.

Original comment by filip.co...@gmail.com on 19 Jul 2014 at 10:32

GoogleCodeExporter commented 9 years ago
Caused by: java.lang.AbstractMethodError: 
org.jboss.resource.adapter.jdbc.WrappedConnection.isWrapperFor(Ljava/lang/Class;
)Z
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.bull.javamelody.JdbcWrapper$ConnectionInvocationHandler.invoke(JdbcWrapper.java:180)
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:277)
    at $Proxy64.isWrapperFor(Unknown Source)
    at be.mil.cccis.auditing.OracleClientInfoProvider.enrichConnection(OracleClientInfoProvider.java:35)
    at be.mil.cccis.auditing.ClientInfoProvider.setClientInfo(ClientInfoProvider.java:25)
    at be.mil.cccis.auditing.AuditableDataSource.enrichConnection(AuditableDataSource.java:49)
    at be.mil.cccis.auditing.AuditableDataSource.getConnection(AuditableDataSource.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.bull.javamelody.JdbcWrapper$3.invoke(JdbcWrapper.java:748)
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:277)
    at $Proxy63.getConnection(Unknown Source)
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1825)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1783)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:290)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)

This is with is code : connection.isWrapperFor(WrappedConnection.class);

Original comment by filip.co...@gmail.com on 22 Jul 2014 at 6:11

GoogleCodeExporter commented 9 years ago
Ah ok. You have said that you use JBoss 4.0.5.
That's very, very old and that's of the JDK 5 era. Said otherwise the JBoss 
4.0.5 jdbc resource adapter are not compatible with the changes of the java.sql 
api in the JDK 6. So you can not call Connection.isWrapperFor/unwrap with the 
JBoss 4.0.5 jdbc resource adapter.
And so you can not get the wrapped connection with unwrap and cannot cast to 
OracleConnection.

I suggest to upgrade your age-old JBoss version, otherwise you will probably 
not be able to have both oracle clientInfo/endToEndMetrics and javamelody sql 
monitoring, at the same time.

For javamelody concerns, getting the wrapped connection to use driver specific 
classes is not supported with JBoss 4.0.5 jdbc resource adapter. So this issue 
is invalid/won't fix, sorry.

Original comment by evernat@free.fr on 23 Jul 2014 at 11:15

GoogleCodeExporter commented 9 years ago
Thx for the answer, the upgrade to Jboss 7 is in the pipeline so I'll have to 
wait till then.

Original comment by filip.co...@gmail.com on 25 Jul 2014 at 7:14