You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "Nestor Hernandez Loli (JIRA)" <ji...@apache.org> on 2014/01/26 07:01:39 UTC

[jira] [Created] (TOMEE-1110) Datasources declared in context.xml doesn't work when the application is redeployed

Nestor Hernandez Loli created TOMEE-1110:
--------------------------------------------

             Summary: Datasources declared in context.xml doesn't work when the application is redeployed
                 Key: TOMEE-1110
                 URL: https://issues.apache.org/jira/browse/TOMEE-1110
             Project: TomEE
          Issue Type: Bug
    Affects Versions: 1.6.0
         Environment: Windows 7 64 Bits, AMD Athon X2 Processor 3 Ghz, 4GB Memory
            Reporter: Nestor Hernandez Loli
            Priority: Critical


I created a datasource in META-INF/context.xml, something like this

<Resource auth="Container" 
                name="jdbc_northwind"  
                type="javax.sql.DataSource" 
                driverClassName="com.mysql.jdbc.Driver"  
                url="jdbc:mysql://localhost:3306/northwind" 
                username="root" 
                password=""                   
                connectionProperties="sessionVariables=time_zone='-5:00'" 
                initialSize="2" maxActive="10" 
                logAbandoned="true" testOnBorrow="true" 
                validationInterval="30000" validationQuery="SELECT 1" 
                closeMethod="close" />  


Then I  created a new simple servlet in order to test the datasource 

 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter(); 
        try {        
          Context initContext = new InitialContext();
          Context envContext = (Context) initContext.lookup("java:/comp/env");
           DataSource dataSource = (DataSource) envContext.lookup("jdbc_northwind");
            try (Connection conn = dataSource.getConnection(); 
               Statement s = conn.createStatement();
                ResultSet rs = s.executeQuery("select * from customers")) {
                while (rs.next()) {
                    out.print(rs.getString("CompanyName"));
                    out.print("<br>");
                }          
            }   
        } catch (Exception e) { e.printStackTrace(); }
    }

I started the server and went to the browser and I see results expected, then when I did  a redeploy to the application I got an exception NameNotFoundException: 

Here an extract of the log:
________________________________________________________
Información: Desplieque del descriptor de configuración C:\apache-tomee-jaxrs-1.6.0\conf\Catalina\localhost\datasourceapp.xml
ene 24, 2014 11:39:40 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
Información: ------------------------- localhost -> /datasourceapp
ene 24, 2014 11:39:40 PM org.apache.openejb.config.ConfigurationFactory configureApplication
Información: Configuring enterprise application: D:\datasourceapp\build\web
ene 24, 2014 11:39:40 PM org.apache.openejb.config.ConfigurationFactory configureService
Información: Configuring Service(id=web/jdbc_northwind, type=Resource, provider-id=Default JDBC Database)
ene 24, 2014 11:39:40 PM org.apache.openejb.assembler.classic.Assembler createRecipe
Información: Creating Resource(id=web/jdbc_northwind)
ene 24, 2014 11:39:40 PM org.apache.tomcat.jdbc.pool.ConnectionPool init
Advertencia: maxIdle is larger than maxActive, setting maxIdle to: 10
ene 24, 2014 11:39:41 PM org.apache.openejb.config.AppInfoBuilder build
Información: Enterprise application "D:\datasourceapp\build\web" loaded.
ene 24, 2014 11:39:41 PM org.apache.openejb.assembler.classic.Assembler createApplication
Información: Assembling app: D:\datasourceapp\build\web
ene 24, 2014 11:39:41 PM org.apache.openejb.cdi.CdiBuilder initSingleton
Información: Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@17d2bf0
ene 24, 2014 11:39:41 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
Información: OpenWebBeans Container is starting...
ene 24, 2014 11:39:41 PM org.apache.webbeans.plugins.PluginLoader startUp
Información: Adding OpenWebBeansPlugin : [CdiPlugin]
ene 24, 2014 11:39:41 PM org.apache.webbeans.plugins.PluginLoader startUp
Información: Adding OpenWebBeansPlugin : [OpenWebBeansJsfPlugin]
ene 24, 2014 11:39:41 PM org.apache.webbeans.config.BeansDeployer validateInjectionPoints
Información: All injection points were validated successfully.
ene 24, 2014 11:39:41 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
Información: OpenWebBeans Container has started, it took 14 ms.
ene 24, 2014 11:39:41 PM org.apache.tomee.catalina.TomcatWebAppBuilder deployWebApps
Información: using context file D:\datasourceapp\build\web\META-INF\context.xml
ene 24, 2014 11:39:41 PM org.apache.openejb.assembler.classic.Assembler createApplication
Información: Deployed Application(path=D:\datasourceapp\build\web)
ene 24, 2014 11:41:08 PM org.apache.catalina.core.StandardContext reload
Información: Ha comenzado la recarga de Contexto [/datasourceapp]
ene 24, 2014 11:41:08 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: D:\datasourceapp\build\web
ene 24, 2014 11:41:08 PM org.apache.openejb.assembler.classic.Assembler destroyResource
Información: Closing DataSource: web/jdbc_northwind
ene 24, 2014 11:41:09 PM org.apache.openejb.config.ConfigurationFactory configureApplication
Información: Configuring enterprise application: D:\datasourceapp\build\web
ene 24, 2014 11:41:09 PM org.apache.openejb.config.ConfigurationFactory configureService
Información: Configuring Service(id=web/jdbc_northwind, type=Resource, provider-id=Default JDBC Database)
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler createRecipe
Información: Creating Resource(id=web/jdbc_northwind)
ene 24, 2014 11:41:09 PM org.apache.tomcat.jdbc.pool.ConnectionPool init
Advertencia: maxIdle is larger than maxActive, setting maxIdle to: 10
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler logUnusedProperties
Advertencia: Property "mappedName" not supported by "web/jdbc_northwind"
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler logUnusedProperties
Advertencia: Property "factory" not supported by "web/jdbc_northwind"
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler logUnusedProperties
Advertencia: Property "resourceid" not supported by "web/jdbc_northwind"
ene 24, 2014 11:41:09 PM org.apache.openejb.config.AppInfoBuilder build
Información: Enterprise application "D:\datasourceapp\build\web" loaded.
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler createApplication
Información: Assembling app: D:\datasourceapp\build\web
ene 24, 2014 11:41:09 PM org.apache.openejb.cdi.CdiBuilder initSingleton
Información: Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@17d2bf0
ene 24, 2014 11:41:09 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
Información: OpenWebBeans Container is starting...
ene 24, 2014 11:41:09 PM org.apache.webbeans.plugins.PluginLoader startUp
Información: Adding OpenWebBeansPlugin : [CdiPlugin]
ene 24, 2014 11:41:09 PM org.apache.webbeans.plugins.PluginLoader startUp
Información: Adding OpenWebBeansPlugin : [OpenWebBeansJsfPlugin]
ene 24, 2014 11:41:09 PM org.apache.webbeans.config.BeansDeployer validateInjectionPoints
Información: All injection points were validated successfully.
ene 24, 2014 11:41:09 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
Información: OpenWebBeans Container has started, it took 15 ms.
ene 24, 2014 11:41:09 PM org.apache.tomee.catalina.TomcatWebAppBuilder deployWebApps
Información: using context file D:\datasourceapp\build\web\META-INF\context.xml
ene 24, 2014 11:41:09 PM org.apache.openejb.assembler.classic.Assembler createApplication
Información: Deployed Application(path=D:\datasourceapp\build\web)
ene 24, 2014 11:41:09 PM org.apache.catalina.core.NamingContextListener addResource
Advertencia: No pude registrar en JMX: javax.naming.NameNotFoundException: El nombre web/jdbc_northwind no este asociado a este contexto
ene 24, 2014 11:41:09 PM org.apache.catalina.core.StandardContext reload
Información: Se ha completado la recarga de este Contexto
ene 24, 2014 11:42:57 PM org.apache.catalina.core.StandardServer await
Información: Se ha recibido un comando de apagado a través del puerto de apagado. Parando la instancia del Servidor.
ene 24, 2014 11:42:57 PM org.apache.coyote.AbstractProtocol pause
Información: Pausing ProtocolHandler ["http-bio-8080"]
ene 24, 2014 11:42:57 PM org.apache.coyote.AbstractProtocol pause
Información: Pausing ProtocolHandler ["ajp-bio-8009"]
ene 24, 2014 11:42:57 PM org.apache.catalina.core.StandardService stopInternal
Información: Parando servicio Catalina
ene 24, 2014 11:42:57 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: C:\apache-tomee-jaxrs-1.6.0\webapps\docs
ene 24, 2014 11:42:57 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: C:\apache-tomee-jaxrs-1.6.0\webapps\host-manager
ene 24, 2014 11:42:57 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: C:\apache-tomee-jaxrs-1.6.0\webapps\manager
ene 24, 2014 11:42:58 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: C:\apache-tomee-jaxrs-1.6.0\webapps\ROOT
ene 24, 2014 11:42:58 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: C:\apache-tomee-jaxrs-1.6.0\webapps\tomee
ene 24, 2014 11:42:58 PM org.apache.catalina.deploy.NamingResources cleanUp
Advertencia: Failed to retrieve JNDI resource [jdbc_northwind] for container [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/datasourceapp]] so no cleanup was performed for that resource
javax.naming.NameNotFoundException: El nombre web/jdbc_northwind no este asociado a este contexto
	at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
	at org.apache.openejb.core.ivm.ContextHandler.lookup(ContextHandler.java:50)
	at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:126)
	at org.apache.tomee.common.AbstractObjectFactory.lookup(AbstractObjectFactory.java:102)
	at org.apache.tomee.common.AbstractObjectFactory.getObjectInstance(AbstractObjectFactory.java:51)
	at org.apache.tomee.common.ResourceFactory.getObjectInstance(ResourceFactory.java:49)
	at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
	at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
	at org.apache.catalina.deploy.NamingResources.cleanUp(NamingResources.java:1002)
	at org.apache.catalina.deploy.NamingResources.stopInternal(NamingResources.java:970)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5643)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1575)
	at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

ene 24, 2014 11:42:58 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
Información: Undeploying app: D:\datasourceapp\build\web
ene 24, 2014 11:42:58 PM org.apache.openejb.assembler.classic.Assembler destroyResource
Información: Closing DataSource: web/jdbc_northwind




---------------------------------------------------------------------------------------
One thing that is a bit strange is that when I added the following content to /WEB-INF/web.xml , the application seems to work fine I mean on each redeploy the datasource still OK
    <resource-ref>
        <res-ref-name>jdbc_northwind</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>   


In Tomcat I never declared the datasources in web.xml, Is this a TomEE requirement?, If it is, you should put that in the documentation. 

TomEE is a great project, but this problem is a little blocker to users wanting to migrate from Tomcat to TomEE





--
This message was sent by Atlassian JIRA
(v6.1.5#6160)