Hi,

2015-11-16 8:39 GMT+02:00 Dimitar Valov <dimitar.va...@gmail.com>:
>
> Hello,
>
> It is really easy to reproduce this problem even if the default factory
> org.apache.naming.factory.ResourceFactory is used (set
> JAVA_OPTS=%JAVA_OPTS% -Djava.naming.factory.object=
> org.apache.naming.factory.ResourceFactory)
>
> Do you think that this should happen?

I found this in the archives [1]

Regards,
Violeta

[1] http://markmail.org/message/ux4tbigxqrm3tmzy

> Best Regards,
> Dimitar
>
> On Thu, Nov 5, 2015 at 1:51 PM, Dimitar Valov <dimitar.va...@gmail.com>
> wrote:
>
> > Hello,
> >
> > Exceptions such as this are found in the logs when
> > java.naming.factory.object is present
> > 04-Nov-2015 15:40:51.560 SEVERE [main]
> > org.apache.catalina.realm.UserDatabaseRealm.startInternal Exception
looking
> > up UserDatabase under key UserDatabase
> >  java.lang.ClassCastException: Cannot cast class
> > org.apache.naming.ResourceRef to interface
org.apache.catalina.UserDatabase
> >         at
> >
org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:232)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at
> >
org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:249)
> >         at
> >
org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at
> >
org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:905)
> >         at
> >
org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at
> >
org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at
> >
org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
> >         at
> > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> >         at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at
> >
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >         at
> >
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.lang.reflect.Method.invoke(Method.java:497)
> >         at
org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
> >         at
org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
> > It is also not possible to add additional ObjectFactories with
> > java.naming.factory.object property.
> >
> > Steps to reproduce:
> >
> > setenv.bat:
> > set JAVA_OPTS=%JAVA_OPTS%
> >
-Djava.naming.factory.object=org.apache.naming.factory.ResourceFactory:custom.CustomObjectFactory
> >
> > setenv.sh:
> > export JAVA_OPTS=$JAVA_OPTS
> >
-Djava.naming.factory.object=org.apache.naming.factory.ResourceFactory:custom.CustomObjectFactory
> >
> > Details:
> >
> > 1. org.apache.naming.ResourceRef.getFactoryClassName() returns null:
> >
https://github.com/apache/tomcat/blob/trunk/java/org/apache/naming/ResourceRef.java#L134
> >
> > 2. Consequently
> >
http://docs.oracle.com/javase/8/docs/api/javax/naming/spi/NamingManager.html#getObjectInstance-java.lang.Object-javax.naming.Name-javax.naming.Context-java.util.Hashtable-
falls
> > to option 3, however the environment does not contain any values and
> > returns the refInfo (An object created using refInfo; or refInfo if an
> > object cannot be created using the algorithm described above.).
> >
> > Possible Reasons:
> >
> > 1. org.apache.catalina.core.NamingContextListener.lifecycleEvent() uses
an
> > empty Hashtable for specifying the environment of the NamingContext:
> >
https://github.com/apache/tomcat/blob/trunk/java/org/apache/catalina/core/NamingContextListener.java#L235
> >    This is the place where the environment is initially created before
> > lookups are made.
> >
> > Possible Solutions:
> >
> > 1. Add the object factories as specified in the environment to the
initial
> > context environment:
> >
> >    contextEnv.put(javax.naming.Context.OBJECT_FACTORIES,
> > System.getProperty(javax.naming.Context.OBJECT_FACTORIES));
> >
> >    in
> >
https://github.com/apache/tomcat/blob/trunk/java/org/apache/catalina/core/NamingContextListener.java#L235
> >
> > Attachments:
> >
> > The projects.zip contains two maven projects: a web application that
uses
> > custom resource type and extension to Tomcat that adds a custom
> > ObjectFactory.
> >
> > Also regarding
> >
https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories
,
> > there is step "2. Declare Your Resource Requirements" which states to
add a
> > resource-env-ref inside web.xml. I've noticed when the resource is
> > specified in the Context for this web application this step is not
> > requried, i.e. lookups are successful. Is this expected?
> >
> > Best Regards,
> > Dimitar
> >

Reply via email to