Home » Language IDEs » AspectJ » Problem to catch exception with aspectj
Problem to catch exception with aspectj [message #673168] |
Sun, 22 May 2011 16:32 |
jimaitou Messages: 1 Registered: May 2011 |
Junior Member |
|
|
Hi,
I'm buiding a sample application with eclipse, spring 3.0, spring dm 2.0 M1 and JPA/EclipseLink to access an H2 database
I want to use aspectj to catch exceptions when methods of the service level are called. Here is the trace when the application is running :
...
--- Get ICustomerService from OSGi Spring context ---
4032 [SpringOsgiExtenderThread-10] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=org.perdigal.client.simpleosgiclient, config=osgibundle:/META-INF/spring/*.xml))
4033 [SpringOsgiExtenderThread-9] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=org.perdigal.server.services.impl, config=osgibundle:/META-INF/spring/*.xml))
[EL Info]: 2011-05-22 17:35:19.395--ServerSession(14252445)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--EclipseLink, version: Eclipse Persistence Services - 2.1.2.v20101206-r8635
[EL Fine]: 2011-05-22 17:35:19.444--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--Detected Vendor platform: org.eclipse.persistence.platform.database.H2Platform
[EL Config]: 2011-05-22 17:35:19.459--ServerSession(14252445)--Connection(15014240)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--connecting(DatabaseLogin(
platform=>H2Platform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2011-05-22 17:35:19.46--ServerSession(14252445)--Connection(15013136)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--Connected: jdbc:h2:~/Documents/Developpement/eclipse/src/DataSource/Test/h2/db/Test.db
User: SA
Database: H2 Version: 1.0.71 (2008-04-25)
Driver: H2 JDBC Driver Version: 1.0.71 (2008-04-25)
[EL Config]: 2011-05-22 17:35:19.46--ServerSession(14252445)--Connection(30013691)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--connecting(DatabaseLogin(
platform=>H2Platform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2011-05-22 17:35:19.46--ServerSession(14252445)--Connection(16329928)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--Connected: jdbc:h2:~/Documents/Developpement/eclipse/src/DataSource/Test/h2/db/Test.db
User: SA
Database: H2 Version: 1.0.71 (2008-04-25)
Driver: H2 JDBC Driver Version: 1.0.71 (2008-04-25)
[EL Info]: 2011-05-22 17:35:19.817--ServerSession(14252445)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--bundleresource://11.fwk12719253:1/_test-h2 login successful
[EL Fine]: 2011-05-22 17:35:19.982--ServerSession(14252445)--Connection(12836222)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--CREATE TABLE T_CUSTOMER (CUSTOMER_ID BIGINT IDENTITY NOT NULL, ADDRESS VARCHAR, GENDER VARCHAR(7), L_NAME VARCHAR(50), F_NAME VARCHAR(30), PRIMARY KEY (CUSTOMER_ID))
[EL Fine]: 2011-05-22 17:35:19.998--ServerSession(14252445)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--SELECT 1
[EL Warning]: 2011-05-22 17:35:20.017--ServerSession(14252445)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: Table T_CUSTOMER already exists [42101-71]
Error Code: 42101
Call: CREATE TABLE T_CUSTOMER (CUSTOMER_ID BIGINT IDENTITY NOT NULL, ADDRESS VARCHAR, GENDER VARCHAR(7), L_NAME VARCHAR(50), F_NAME VARCHAR(30), PRIMARY KEY (CUSTOMER_ID))
Query: DataModifyQuery(sql="CREATE TABLE T_CUSTOMER (CUSTOMER_ID BIGINT IDENTITY NOT NULL, ADDRESS VARCHAR, GENDER VARCHAR(7), L_NAME VARCHAR(50), F_NAME VARCHAR(30), PRIMARY KEY (CUSTOMER_ID))")
4722 [Thread-12] INFO org.perdigal.server.aspectj.impl.CustomerAspect - Class org.perdigal.server.services.impl.CustomerServiceImpl, before method getCustomer
4722 [Thread-12] INFO org.perdigal.server.aspectj.impl.CustomerAspect - Class org.perdigal.server.services.impl.CustomerServiceImpl, before method customerDAO
4722 [Thread-12] INFO org.perdigal.server.aspectj.impl.CustomerAspect - Class org.perdigal.server.services.impl.CustomerServiceImpl, after method customerDAO
[EL Fine]: 2011-05-22 17:35:20.085--ServerSession(14252445)--Connection(6558426)--Thread(Thread[Thread-12,5,spring-osgi-extender[1ca1a68]-threads])--SELECT CUSTOMER_ID, ADDRESS, GENDER, L_NAME, F_NAME FROM T_CUSTOMER WHERE ((F_NAME = ?) AND (L_NAME = ?))
bind => [Xxxxx, Yyyy]
4755 [Thread-12] INFO org.perdigal.server.aspectj.impl.CustomerAspect - Class org.perdigal.server.services.impl.CustomerServiceImpl, after method getCustomer
4755 [Thread-12] INFO org.perdigal.server.aspectj.impl.CustomerAspect - Catch exception javax.persistence.NoResultException after method getCustomer of class org.perdigal.server.services.impl.CustomerServiceImpl
getSingleResult() did not retrieve any entities.
...
At the end of the trace, an exception has occured because the customer is not in the database and a NoResultException exception is catched by the aspect, that's what i want to do.
But i want more ...
The connection to the database is managed by spring, a bean spring is used to declare a datasource :
<!-- DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="${database.driverClassName}"
p:url="${database.url}"
p:username="${database.username}"
p:password="${database.password}"
init-method="createDataSource" destroy-method="close">
</bean>
When the bean is instancied, a connection is opened with the database.
Now if i specify a wrong username, i can't catch exceptions with my aspect :
3488 [SpringOsgiExtenderThread-6] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1162a9c: defining beans [dataSource,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#0]; root of factory hierarchy
3489 [SpringOsgiExtenderThread-6] ERROR org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=com.perdigal.server.dao.datasource, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL [bundleentry://10.fwk21722195/META-INF/spring/module-context.xml]: Invocation of init method failed; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Wrong user name or password [8004-71])
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:62)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:327)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:87)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:292)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:138)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Wrong user name or password [8004-71])
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1244)
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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 14 more
Caused by: org.h2.jdbc.JdbcSQLException: Wrong user name or password [8004-71]
at org.h2.message.Message.getSQLException(Message.java:92)
at org.h2.message.Message.getSQLException(Message.java:96)
at org.h2.message.Message.getSQLException(Message.java:74)
at org.h2.message.Message.getSQLException(Message.java:117)
at org.h2.engine.Engine.validateUserAndPassword(Engine.java:235)
at org.h2.engine.Engine.getSession(Engine.java:109)
at org.h2.engine.Session.createSession(Session.java:229)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:976)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:957)
at org.h2.Driver.connect(Driver.java:57)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1266)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1240)
... 21 more
In fact, i don't know if i have to catch exceptions from spring, from the pooled connection factory or from the driver
Does someone has ideas or advice to do that ?
Thanks for any help
Hervé
|
|
|
Goto Forum:
Current Time: Fri Apr 26 10:40:14 GMT 2024
Powered by FUDForum. Page generated in 0.04065 seconds
|