Re: PostgreSQL access via JNDI
My mis-capitalization of DataSource was the main problem. Also, I was trying to use Resource and ResourceLink in META-INF/context.xml; ResourceLink is apparently not needed if the Resource is local to the webapp. Thank you both for your help! Mark On Apr 5, 2006, at 5:11 AM, Hadraba Petr wrote: Hi, I'm successfuly using PostgreSQL 8.1.3 with Tomcat 5.5.15 with JDBC drivers 405 (build)... I have the Resource ... / definition in the META-INF/context.xml and in the WEB-INF/web.xml I have the resource-ref/ element. The resource-env-ref/ I'm using for the ActiveMQ client connection. Also the JDBC drivers are placed in the common/lib directory. If you search the list, you will find my previous posts containing all the configuration files. Have a lot of fun! PETR On 4/5/06, Amila Suriarachchi [EMAIL PROTECTED] wrote: On 4/5/06, Mark Slater [EMAIL PROTECTED] wrote: I've been trying to get PostgreSQL set up to be accessed through JNDI in Tomcat 5.5.x. I found the docs page describing it, jndi- datasource-examples-howto.html, and followed the example there, but it still doesn't work. I'm trying to provide access to PostgreSQL for use by both JDO and JCR in my web-apps. Here's the Resource definition I'm using: Resource name=jdbc/whisper_db auth=Container type=javax.sql.Datasource S should be capital as well DataSource - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
PostgreSQL access via JNDI
I've been trying to get PostgreSQL set up to be accessed through JNDI in Tomcat 5.5.x. I found the docs page describing it, jndi- datasource-examples-howto.html, and followed the example there, but it still doesn't work. I'm trying to provide access to PostgreSQL for use by both JDO and JCR in my web-apps. Here's the Resource definition I'm using: Resource name=jdbc/whisper_db auth=Container type=javax.sql.Datasource driverClassName=org.postgresql.Driver url=jdbc:postgresql://127.0.0.1:5432/my_db username=--- password=--- maxActive=10 maxIdle=100 maxWait=3000 / In my application's META-INF/context.xml, I have the following ResourceLink: ResourceLink global=jdbc/whisper_db name=jdbc/whisper_orm type=javax.sql.Datasource / In my application's WEB-INF/web.xml, I have the following resource- env-ref: resource-env-ref descriptionWhisper's Database/description resource-env-ref-namejdbc/whisper_orm/resource-env-ref-name resource-env-ref-typejavax.sql.Datasource/resource-env- ref-type /resource-env-ref Depending on where I put the Resource definition, I get different errors. If I put it in the web-app's META-INF/context.xml, or in $TOMCAT_HOME/ conf/context.xml, my JDO implementation complains: NestableRuntimeException: There was an error duing JNDI lookup of the name java:comp/env/jdbc/whisper_orm. Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context If I put it in $TOMCAT_HOME/conf/server.xml, in the GlobalNamingResources section, I get: 2006-04-04 11:58:27,866 ERROR [org.apache.catalina.mbeans.GlobalResourcesLifecycleListener] - Exception processing Global JNDI Resources javax.naming.NamingException: Cannot create resource instance at org.apache.naming.factory.ResourceFactory.getObjectInstance (ResourceFactory.java:132) at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:304) at org.apache.naming.NamingContext.lookup(NamingContext.java: 792) at org.apache.naming.NamingContext.lookup(NamingContext.java: 152) at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans (GlobalResourcesLifecycleListener.java:138) at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans (GlobalResourcesLifecycleListener.java:143) at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans (GlobalResourcesLifecycleListener.java:108) at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEve nt(GlobalResourcesLifecycleListener.java:80) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent (LifecycleSupport.java:119) at org.apache.catalina.core.StandardServer.start (StandardServer.java:693) at org.apache.catalina.startup.Catalina.start(Catalina.java: 551) 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:585) at org.apache.catalina.startup.Bootstrap.start (Bootstrap.java:275) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java: 413) I'm assuming these errors are related, and that whatever is causing the NamingException is the same fundamental problem causing the NameNotFoundException in the context-based configuration. My problem is that I can't figure out what it is. The driver for the database (postgresql-8.1-405.jdbc3.jar) is in $TOMCAT_HOME/common/lib/, and I've also tried adding commons-dbcp-1.2.1.jar and commons- pool-1.2.jar alongside it (even though the docs say that shouldn't be necessary), but get the same errors. Is there any logging that I can turn on that will tell me the WHY Tomcat Cannot create resource instance? Or am I doing something obviously stupid with my Resource definition? Or could it be something else entirely? Any suggestions would be really helpful. Thanks! Mark - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Tomcat+Eclipse, breakpoints not working
I'm using Eclipse to try and debug a servlet in tomcat. I've got eclipse set up so that it starts and stops tomcat in debug mode (I can tell because the list of tomcat threads is visible and updated when I'm using the debug perspective). I added a few breakpoints to my code and triggered the servlet, but the breakpoints didn't pause the execution. I know the functions were hit because I've got stack traces being logged with exceptions (they're the reason I'm trying to debug in the first place). I'm not using Eclipse to build or deploy my webapp, but I do want to be able to use it to debug. I have maven building the war and I deploy the webapp by hand (ie cp target mywebapp.war TOMCAT_HOME/ webapps/). I used the eclipse plugin for maven to generate the .project and .classpath files that eclipse is using when I browse my source code. What can I do so that I can also debug it? Thanks! Mark - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tomcat+Eclipse, breakpoints not working
On Mar 29, 2006, at 12:47 PM, Pascal Alberty wrote: Add the following parameters to the tomcat JAVA_OPTIONS -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n In Eclipse, create a new Java Remote Application. By default, port used will be 8000 as configured previously. Launch Tomcat, run this JRA, place breakpoints, use your web application. Eclipse will go in debug mode if breakpoints are meet. See http://tomcat.apache.org/faq/development.html for more explanations. Pascal That's the page I followed in getting it set up. I started tomcat with those environment options and, with my project open, attached to the running tomcat instance. I set my breakpoints, and triggered the web app, but it didn't stop at the breakpoints. In the log output for tomcat, the first line is Listening for transport dt_socket at address: 8000. On Mar 29, 2006, at 1:17 PM, Mark Thomas wrote: The project that contains your servlets needs to be part of the project that is associated with the debug session for Tomcat. Mark I used maven's eclipse plugin to generate an Eclipse .project file. I've opened that in Eclipse and then created the Remote Java Application for debugging, and selected the project in the Connect tab. Do I need to compile the WAR from within Eclipse? I checked the compile settings for Maven, and it is building with Debug on in the generated class files. Mark On 3/29/06, Mark Slater [EMAIL PROTECTED] wrote: I'm using Eclipse to try and debug a servlet in tomcat. I've got eclipse set up so that it starts and stops tomcat in debug mode (I can tell because the list of tomcat threads is visible and updated when I'm using the debug perspective). I added a few breakpoints to my code and triggered the servlet, but the breakpoints didn't pause the execution. I know the functions were hit because I've got stack traces being logged with exceptions (they're the reason I'm trying to debug in the first place). I'm not using Eclipse to build or deploy my webapp, but I do want to be able to use it to debug. I have maven building the war and I deploy the webapp by hand (ie cp target mywebapp.war TOMCAT_HOME/ webapps/). I used the eclipse plugin for maven to generate the .project and .classpath files that eclipse is using when I browse my source code. What can I do so that I can also debug it? Thanks! Mark - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Pascal Alberty - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Trouble accessing Resources in my Context
I've got my servlet working now, without resorting to using a Context element inside the server.xml. I found that putting the Context in $TOMCAT_HOME/conf/Catalina/localhost/jackrabbit_config_test.xml works fine. Context Resource name=jcr/model1Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model1.xml repHomeDir=shared/jackrabbit_model1 / ResourceLink name=sharedJCRRepository global=jcr/model2Repository type=javax.jcr.Repository / Environment name=testNum value=10 type=java.lang.Integer override=false/ /Context And then in my web app, I have these lines: resource-ref descriptionJackrabbit Model 1 Repository/description res-ref-namejcr/model1Repository/res-ref-name res-typejavax.jcr.Repository/res-type res-authContainer/res-auth /resource-ref resource-env-ref descriptionJackrabbit Model 2 Repository/description resource-env-ref-namesharedJCRRepository/resource-env-ref- name resource-env-ref-typejavax.jcr.Repository/resource-env- ref-type /resource-env-ref resource-ref descriptionTest Number/description res-ref-nametestNum/res-ref-name res-typejava.lang.Integer/res-type res-authContainer/res-auth /resource-ref I also finally realized that the ResourceLink's name attribute can't be the same as the the global attribute. That took care of the null pointer I was getting trying to access that object. So, while this works acceptably (the context information for the webapp is not included in server.xml), I would *much* prefer to use the WEB-INF/context.xml the Tomcat docs say I can (the fourth bullet on this page - http://tomcat.apache.org/tomcat-5.5-doc/config/ context.html). If someone could explain why that doesn't work, I'd be really appreciative. Is this possibly a known issue? Thanks, Mark On Feb 13, 2006, at 9:40 PM, Mark Slater wrote: I've solved part of the problem... or at least made it less complicated (I hope). The ClassNotFound exception mentioned at the bottom is due to the jackrabbit jars being located in server/lib as opposed to common/lib. I'd placed them in server lib on the advice of someone more familiar with jackrabbit than I. I'd assumed that, as long as the jar was included in the web app, this would not be a problem; obviously that was incorrect. So after putting jackrabbit and its dependencies in common/lib, here's what I've got: If the context for web-app only resources and environment variables (jcr/model1Repository and testNum in the code below) are placed in HostContext in $TOMCAT_HOME/conf/server.xml, the web app is able to find them. If they are placed in the web-app's WEB-INF/context.xml, an exception is thrown (javax.naming.NamingException: Cannot create resource instance). As the latter is definitely the preferred option (by tomcat documentation and myself), I'd really like to get that to work. I've also confirmed that I get the same errors on a newly downloaded and configured Tomcat 5.5.15. Mark On Feb 13, 2006, at 6:23 PM, Mark Slater wrote: I'm running Tomcat 5.5.9 with JVM 1.5.0_05-83 on MacOS X 10.4.4. I'm trying to build an example webapp that shows the configuration for two Jackrabbit resources: one configured as an embedded resource for that web app and another configured as a shared resource for the entire host. I've tried to define the resources in a variety of places and haven't been able to get any of them to work. My context files are defined like this $TOMCAT_HOME/conf/context.xml: Context WatchedResourceWEB-INF/web.xml/WatchedResource /Context webapp/WEB-INF/context.xml: Context docBase=jackrabbit_config_test reloadable=false Resource name=jcr/model1Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model1.xml repHomeDir=shared/jackrabbit_model1 / Environment name=testNum value=10 type=java.lang.Integer override=false/ /Context I've got the following setup in server.xml: GlobalNamingResources ... Resource name=jcr/model2Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model2.xml repHomeDir=shared/jackrabbit_model2 / /GlobalNamingResources And in my web.xml, I've got the following references: web-app ... resource-ref descriptionJackrabbit Model 1 Repository/description res-ref-namejcr/model1Repository/res-ref-name res-typejavax.jcr.Repository/res-type res-authContainer/res-auth /resource-ref resource-env-ref
Re: Trouble accessing Resources in my Context
Thanks Chuck for pointing that out. Given that everything else goes in WEB-INF, when I was reading the page I misread it every time. Is there any particular reason the context file goes in META-INF as opposed to WEB-INF? Mark On Feb 14, 2006, at 6:16 AM, Caldarale, Charles R wrote: From: Mark Slater [mailto:[EMAIL PROTECTED] Subject: Re: Trouble accessing Resources in my Context So, while this works acceptably (the context information for the webapp is not included in server.xml), I would *much* prefer to use the WEB-INF/context.xml the Tomcat docs say I can (the fourth bullet on this page - http://tomcat.apache.org/tomcat-5.5-doc/config/ context.html). If someone could explain why that doesn't work, I'd be really appreciative. Is this possibly a known issue? Read what the bullet actually says, not what you think it says: if the previous file was not found for this application, in individual file at /META-INF/context.xml inside the application files What directory does it really specify? (Hint: it's not WEB-INF.) - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e- mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Trouble accessing Resources in my Context
I'm running Tomcat 5.5.9 with JVM 1.5.0_05-83 on MacOS X 10.4.4. I'm trying to build an example webapp that shows the configuration for two Jackrabbit resources: one configured as an embedded resource for that web app and another configured as a shared resource for the entire host. I've tried to define the resources in a variety of places and haven't been able to get any of them to work. My context files are defined like this $TOMCAT_HOME/conf/context.xml: Context WatchedResourceWEB-INF/web.xml/WatchedResource /Context webapp/WEB-INF/context.xml: Context docBase=jackrabbit_config_test reloadable=false Resource name=jcr/model1Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model1.xml repHomeDir=shared/jackrabbit_model1 / Environment name=testNum value=10 type=java.lang.Integer override=false/ /Context I've got the following setup in server.xml: GlobalNamingResources ... Resource name=jcr/model2Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model2.xml repHomeDir=shared/jackrabbit_model2 / /GlobalNamingResources And in my web.xml, I've got the following references: web-app ... resource-ref descriptionJackrabbit Model 1 Repository/description res-ref-namejcr/model1Repository/res-ref-name res-typejavax.jcr.Repository/res-type res-authContainer/res-auth /resource-ref resource-env-ref descriptionJackrabbit Model 2 Repository/description resource-env-ref-namejcr/model2Repository/resource-env- ref-name resource-env-ref-typejavax.jcr.Repository/resource-env- ref-type /resource-env-ref resource-ref descriptionTest Number/description res-ref-nametestNum/res-ref-name res-typejava.lang.Integer/res-type res-authContainer/res-auth /resource-ref /web-app I know tomcat is finding the jcr/model2Repository resource because if I delete all of the database entries and repository files, and then restart Tomcat, upon restart the database and repository files are recreated. There's also log output in catalina.out about jackrabbit initializing itself for the model2Repository. When I get to my servlet, I've got some code that prints the context entries for the initial context and the environment's context to the output webpage. Then I try to access both repositories. For good measure, I also try to access the testNum I defined in my webapp's context.xml. None of the objects are accessible. The locally defined objects (those in webapp/WEB-INF/context.xml) throw an exception: javax.naming.NamingException: Cannot create resource instance at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance (ResourceEnvFactory.java:99) at javax.naming.spi.NamingManager.getObjectInstance (NamingManager.java:304) at org.apache.naming.NamingContext.lookup(NamingContext.java:792) at org.apache.naming.NamingContext.lookup(NamingContext.java:139) at org.apache.naming.NamingContext.lookup(NamingContext.java:780) at org.apache.naming.NamingContext.lookup(NamingContext.java:152) at edu.ucsc.whisper.jackrabbit_test.JackrabbitTest.getObjectFromContext (JackrabbitTest.java:85) at edu.ucsc.whisper.jackrabbit_test.JackrabbitTest.doGet (JackrabbitTest.java:54) The shared repository object (defined in the server.xml and global context.xml) simply comes back null when I call context.lookup( jcr/ model2Repository ) without throwing an exception. I tried moving the configuration in the {webapp}/WEB-INF/context.xml to server.xml's Host section, as below: Context path=/jackrabbit_config_test docBase=jackrabbit_config_test Resource name=jcr/model1Repository auth=Container type=javax.jcr.Repository factory=org.apache.jackrabbit.core.jndi.BindableRepositoryFactory configFilePath=conf/repository_model1.xml repHomeDir=shared/jackrabbit_model1 / Environment name=testNum value=10 type=java.lang.Integer override=false/ /Context Doing this made the servlet able to find the testNum environment variable and the jcr/model2Repository was still null. But accessing jcr/model1Repository seems to be worse because I got a ClassNotFound exception on org.apache.jackrabbit.core.jndi.BindableRepositoryFactory calling context.lookup() on it. But the jackrabbit.jar is in both {webapp}/ WEB-INF/lib and $TOMCAT_HOME/server/lib, so I don't know why the factory wouldn't be found. And, in the logs when the server starts using this configuration, the jcr/model2Repository is still