This behavior began in versions 6.0.41 and 7.0.54. Before that, everything
worked as expected.


2014-09-03 15:33 GMT-03:00 Robert Anderson <ranom...@gmail.com>:

> This is the complete code that was working:
> https://code.google.com/p/psi-probe/source/browse/trunk/core/src/main/java/com/googlecode/psiprobe/beans/ResourceResolverBean.java
>
>
>  public List getApplicationResources() throws NamingException {
>         logger.info("Reading GLOBAL resources");
>         List resources = new ArrayList();
>
>         MBeanServer server = getMBeanServer();
>         if (server != null) {
>             try {
>                 Set dsNames = server.queryNames(new ObjectName(
> "Catalina:type=Resource,resourcetype=Global,*"), null);
>                 for (Iterator it = dsNames.iterator(); it.hasNext();) {
>                     ObjectName objectName = (ObjectName) it.next();
>                     ApplicationResource resource = new ApplicationResource
> ();
>
>                     logger.info("reading resource: " + objectName);
>                     resource.setName(getStringAttribute(server, objectName
> , "name"));
>                     resource.setType(getStringAttribute(server, objectName
> , "type"));
>                     resource.setScope(getStringAttribute(server,
> objectName, "scope"));
>                     resource.setAuth(getStringAttribute(server, objectName
> , "auth"));
>                     resource.setDescription(getStringAttribute(server,
> objectName, "description"));
>
>                     lookupResource(resource, true, true);
>
>                     resources.add(resource);
>                 }
>             } catch (Exception e) {
>                 logger.error("There was an error querying JMX server:", e
> );
>             }
>         }
>         return resources;
>     } public void lookupResource(ApplicationResource resource, boolean
> contextBound, boolean global) {
>         DataSourceInfo dataSourceInfo = null;
>         if (contextBound) {
>             try {
>                 String jndiName = resolveJndiName(resource.getName(),
> global);
>                 Object o = new InitialContext().lookup(jndiName); //The
> exception is here
>                 resource.setLookedUp(true);
>                 for (Iterator it = datasourceMappers.iterator(); it.
> hasNext();) {
>                     DatasourceAccessor accessor = (DatasourceAccessor) it.
> next();
>                     dataSourceInfo = accessor.getInfo(o);
>                     if (dataSourceInfo != null) {
>                         break;
>                     }
>                 }
>
>             } catch (Throwable e) {
>                 resource.setLookedUp(false);
>                 dataSourceInfo = null;
>                 logger.error("Failed to lookup: " + resource.getName(), e
> );
>                 //
>                 // make sure we always re-throw ThreadDeath
>                 //
>                 if (e instanceof ThreadDeath) {
>                     throw (ThreadDeath) e;
>                 }
>             }
>         } else {
>             resource.setLookedUp(false);
>         }
>
> We are suspecting that this fix broke something:
> https://issues.apache.org/bugzilla/show_bug.cgi?id=56451.
>
>
>
> 2014-09-03 15:25 GMT-03:00 Filip Hanik <fi...@hanik.com>:
>
> On Wed, Sep 3, 2014 at 11:09 AM, Robert Anderson <ranom...@gmail.com>
>> wrote:
>>
>> > Thanks, Daniel. But my question the question is why that was working in
>> > 6.0.39 and the firsts releases of 7.0.x?
>> > Tomcat is not bind in java:<global name> anymore. Was it a feature
>> request
>> > or is it a bug?
>> >
>>
>> ​Not sure, the resource links have been around for a long time. It may
>> have
>> been a security feature to not expose .
>> However, I'm sure there was a reason for it, and very unlikely it will
>> change back
>> You can get around it by adding a <ResourceLink> element in your
>> conf/context.xml, as this setting will apply to all your apps deployed.
>>
>> Filip
>>
>>
>>
>> > Em 03/09/2014 13:48, "Daniel Mikusa" <dmik...@pivotal.io> escreveu:
>> >
>> > > On Wed, Sep 3, 2014 at 11:51 AM, Robert Anderson <ranom...@gmail.com>
>> > > wrote:
>> > >
>> > > > Ok! :)
>> > > >
>> > > > Steps to reproduce:
>> > > >
>> > > > 1)Download and unpack 6.0.39
>> > > >
>> > > >
>> > > >
>> > >
>> >
>> http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.39/bin/apache-tomcat-6.0.39.tar.gz
>> > > >
>> > > > 2) Create a global jndi resouce in server.xml
>> > > >
>> > > > ....
>> > > > <GlobalNamingResources>
>> > > >         <Resource name="jdbc/cacheapp" auth="Container"
>> > > > type="javax.sql.DataSource" removeAbandoned="true"
>> > > > removeAbandonedTimeout="300"
>> > > >                                    maxActive="10" maxIdle="2"
>> > minIdle="1"
>> > > > maxWait="10000"
>> > > >                    validationQuery="select 1 from dual"
>> > > >                    testOnBorrow="true"
>> > > >                                    validationInterval="0"
>> > > >                                    username="_system" password="SYS"
>> > > > driverClassName="com.intersys.jdbc.CacheDriver"
>> > > >
>> > > url="jdbc:Cache://localhost:1972/USER"/>
>> > > >
>> > > >   </GlobalNamingResources>
>> > > > ...
>> > > >
>> > > > 3) Install psi-probe:
>> > > >
>> > >
>> >
>> https://code.google.com/p/psi-probe/downloads/detail?name=probe-2.3.3.zip
>> ,
>> > > > unpack and copy probe.war to webapps dir;
>> > > >
>> > > > 4)  Edit tomcat-users.xml
>> > > >
>> > > > <role rolename="probeuser" />
>> > > >   <role rolename="poweruser" />
>> > > >   <role rolename="poweruserplus" />
>> > > >   <role rolename="manager" />
>> > > >
>> > > >   <user username="admin" password="t0psecret" roles="manager" />
>> > > >
>> > > > 5) Start tomcat and go to
>> http://localhost:8080/probe/datasources.htm
>> > > >
>> > > > It will list global jndi resources.
>> > > >
>> > >
>> > > I think the question is how does it list these?  You haven't added any
>> > > resource links, so technically there are no resources available to
>> your
>> > > application through JNDI.  See the Introduction section here, which
>> > states
>> > > why resource links are necessary.
>> > >
>> > >
>> > >
>> > >
>> >
>> http://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html#Introduction
>> > >
>> > > Have you tried looking at your running 6.0.41 server, connecting with
>> JMX
>> > > and looking at the MBeans?  Is your database connection pool resources
>> > > actually available?
>> > >
>> > > Dan
>> > >
>> > >
>> > > > Instead of Tomcat 6.0.39, use 6.0.41 and probe will not list global
>> > jndi
>> > > > resources anymore.
>> > > >
>> > > >
>> > > > Thanks.
>> > > >
>> > > >
>> > > >
>> > > > 2014-09-03 12:39 GMT-03:00 Filip Hanik <fi...@hanik.com>:
>> > > >
>> > > > > can you post your configuration file. that will be the only way we
>> > can
>> > > > help
>> > > > > you fix it, as I doubt tomcat will go back to pre 6.0.41 days :)
>> > > > >
>> > > > > Filip
>> > > > >
>> > > > >
>> > > > >
>> > > > > On Wed, Sep 3, 2014 at 9:36 AM, Robert Anderson <
>> ranom...@gmail.com>
>> > > > > wrote:
>> > > > >
>> > > > > > Hi,
>> > > > > >
>> > > > > >
>> > > > > > In a privileged context, a have the following jsp to test a
>> global
>> > > jndi
>> > > > > > resource:
>> > > > > >
>> > > > > > <%@ page session="false"
>> > > import="java.util.*,java.sql.*,javax.naming.*,
>> > > > > > javax.sql.*,org.apache.commons.dbcp.*" contentType="text/html"
>> %>
>> > > > > > <%!
>> > > > > >
>> > > > > > protected void doLookup(JspWriter out) throws ServletException,
>> > > > > IOException
>> > > > > > {
>> > > > > >  Context ctx;
>> > > > > >  try {
>> > > > > >   ctx = new InitialContext();
>> > > > > >   Object o = ctx.lookup("java:jdbc/cacheapp");
>> > > > > >   out.println(o);
>> > > > > >
>> > > > > >
>> > > > > >  } catch (NamingException e) {
>> > > > > >   out.println(e.getMessage());
>> > > > > >  } catch (Exception e) {
>> > > > > >  }
>> > > > > >  }
>> > > > > >
>> > > > > > %>
>> > > > > >
>> > > > > > <html>
>> > > > > > <head>
>> > > > > >   <title>Test JNDI</title>
>> > > > > > </head>
>> > > > > > <body>
>> > > > > >
>> > > > > > <h1>Teste JNDI</h1>
>> > > > > > <hr/>
>> > > > > > <%
>> > > > > > doLookup(out);
>> > > > > > %>
>> > > > > > <hr/>
>> > > > > >
>> > > > > > </body>
>> > > > > > </html>
>> > > > > >
>> > > > > >
>> > > > > > Versions earlier than 6.0.41:
>> > > > > >
>> > > > > > org.apache.tomcat.jdbc.pool.DataSource@29050dfd
>> > > > > > {ConnectionPool[defaultAutoCommit=null;
>> > > > > > defaultReadOnly=null; defaultTransactionIsolation=-1;
>> > > > > defaultCatalog=null;
>> > > > > > driverClassName=com.intersys.jdbc.CacheDriver; maxActive=10;
>> > > maxIdle=2;
>> > > > > > minIdle=1; initialSize=10; maxWait=10000; testOnBorrow=true;
>> > > > > > testOnReturn=false; timeBetweenEvictionRunsMillis=5000;
>> > > > > > numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000;
>> > > > > > testWhileIdle=false; testOnConnect=false; password=********;
>> > > > > > url=jdbc:Cache://localhost:1972/USER; username=tomcat;
>> > > > > > validationQuery=select 1 from dual; validationQueryTimeout=-1;
>> > > > > > validatorClassName=null; validationInterval=0;
>> > > > > > accessToUnderlyingConnectionAllowed=true; removeAbandoned=true;
>> > > > > > removeAbandonedTimeout=300; logAbandoned=false;
>> > > > > connectionProperties=null;
>> > > > > > initSQL=null; jdbcInterceptors=null; jmxEnabled=true;
>> > fairQueue=true;
>> > > > > > useEquals=true; abandonWhenPercentageFull=0; maxAge=0;
>> > useLock=false;
>> > > > > > dataSource=null; dataSourceJNDI=null; suspectTimeout=0;
>> > > > > > alternateUsernameAllowed=true; commitOnReturn=false;
>> > > > > > rollbackOnReturn=false; useDisposableConnectionFacade=true;
>> > > > > > logValidationErrors=false; propagateInterruptState=false;
>> > > > > > ignoreExceptionOnPreLoad=false; }
>> > > > > >
>> > > > > >
>> > > > > > 6.0.41 and 7.0.55:
>> > > > > >
>> > > > > > Name jdbc is not bound in this Context
>> > > > > >
>> > > > > > That is a bug?
>> > > > > >
>> > > > > >
>> > > > > > We are having a issue in psi-probe because this behavior change
>> (
>> > > > > > https://code.google.com/p/psi-probe/issues/detail?id=411).
>> > > > > >
>> > > > > >
>> > > > > > Thanks in advance.
>> > > > > >
>> > > > >
>> > > >
>> > >
>> >
>>
>
>

Reply via email to