tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karan Malhi" <karan.ma...@gmail.com>
Subject Re: Tomcat webapp Configuration
Date Wed, 07 May 2008 05:06:20 GMT
David,

I think the issue is with the
org.apache.catalina.util.DefaultAnnotationProcessor.

Look at this portion of the error stack trace:-

org.apache.naming.NamingContext.lookup(NamingContext.java:770)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:201)
org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:139)
com.sun.faces.vendor.Tomcat6InjectionProvider.inject(Tomcat6InjectionProvider.java:46)
com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:298)
First thing is that the JSF implementation by sun provides four Injection
Providers, one for glassfish,tomcat,jetty and a generic web container. The
one being used above is the  com.sun.faces.vendor.Tomcat6InjectionProvider.
The inject method, then uses the tomcat DefaultAnnotationProcessor to
process annotations and lookup the EJB in the NamingContext. This is where
the problem is.
1. I am not sure which context is being used by this
DefaultAnnotationProcessor. thats probably why the lookup is failing because
it is not looking up in the right location
2. If you look at the lookupFieldResource() method, then it is lookingup and
EJB by @EJB.name() . if it does not find that (which it will not because we
are not specifying @EJB(name=something) in the ResourceBean, then it looks
up by JSF managed bean classname / field name i.e. in our case it is
org.ui.beans.ResourceBean. Hence the exception that it cannot find the name
org.ui.beans.ResourceBean in the NamingContext.

What we would need to do is to add our own InjectionProvider and also add
our own AnnotationProcessor. Since the InjectionProvider will use the
AnnotationProcessor, we simply need to tell the JSF implementation on how to
get to our InjectionProvider. This can be done by setting a system property
named com.sun.faces.
InjectionProvider=org.apache.openejb.OurInjectionProvider

I need some sleep now :), so provided the above info, just in case you or
somebody else might want to fix this. Otherwise, I will try to work on it
tomorrow.

Below is the DefaultAnnotationProcessor (I have stripped off irrelevant
stuff from here):


public class DefaultAnnotationProcessor implements AnnotationProcessor {

protected javax.naming.Context context = null;

public DefaultAnnotationProcessor(javax.naming.Context context) {

this.context = context;

}

/**

* Inject resources in specified instance.

*/

public void processAnnotations(Object instance)

throws IllegalAccessException, InvocationTargetException, NamingException {

if (context == null) {

// No resource injection

return;

}

// Initialize fields annotations

Field[] fields = instance.getClass().getDeclaredFields();

for (int i = 0; i < fields.length; i++) {

if (fields[i].isAnnotationPresent(Resource.class)) {

Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);

lookupFieldResource(context, instance, fields[i], annotation.name());

}

if (fields[i].isAnnotationPresent(EJB.class)) {

EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);

lookupFieldResource(context, instance, fields[i], annotation.name());

}

if (fields[i].isAnnotationPresent(WebServiceRef.class)) {

WebServiceRef annotation =

(WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);

lookupFieldResource(context, instance, fields[i], annotation.name());

}

if (fields[i].isAnnotationPresent(PersistenceContext.class)) {

PersistenceContext annotation =

(PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);

lookupFieldResource(context, instance, fields[i], annotation.name());

}

if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {

PersistenceUnit annotation =

(PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);

lookupFieldResource(context, instance, fields[i], annotation.name());

}

}



}

 /**

* Inject resources in specified field.

*/

protected static void lookupFieldResource(javax.naming.Context context,

Object instance, Field field, String name)

throws NamingException, IllegalAccessException {

Object lookedupResource = null;

boolean accessibility = false;

if ((name != null) &&

(name.length() > 0)) {

lookedupResource = context.lookup(name);

} else {

lookedupResource = context.lookup(instance.getClass().getName() + "/" +
field.getName());

}

accessibility = field.isAccessible();

field.setAccessible(true);

field.set(instance, lookedupResource);

field.setAccessible(accessibility);

}

On Tue, May 6, 2008 at 9:01 PM, David Blevins <david.blevins@visi.com>
wrote:

>
> On May 5, 2008, at 6:30 PM, JimOR wrote:
>
> David Blevins wrote:
> >
> > > If you can whip up a tiny example that reproduces the problem, I'll be
> > > happy to take a look at it.  You can attach the war to this jira:
> > > http://issues.apache.org/jira/browse/OPENEJB-797
> > >
> > >
> > >
> > The jira has a zip attached containing IceFaces jars in ./lib and a
> > ./webapps/IceSample.war.  The war contains a working EJB injected
> > servlet,
> > and the openejb.log shows that my  bean was created.
> >
> > Running the default page, main.jspx, results in the following exception:
> > ERROR-
> > com.icesoft.faces.facelets.D2DFaceletViewHandler.renderResponse(Line:292)
> > -
> > Problem in renderResponse: javax.faces.FacesException:
> > javax.naming.NameNotFoundException: Name org.ui.beans.RequestBean is not
> > bound in this Context
> > javax.faces.FacesException: javax.faces.FacesException:
> > javax.naming.NameNotFoundException: Name org.ui.beans.RequestBean is not
> > bound in this Context
> >        at
> >
> > com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:560)
> >        at
> >
> > com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
> >
> > [snip]
> >
> > Caused by: javax.faces.FacesException:
> > javax.naming.NameNotFoundException:
> > Name org.ui.beans.RequestBean is not bound in this Context
> >        at
> >
> > com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:340)
> >        at
> >
> > com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:550)
> >        ... 53 more
> > Caused by: javax.naming.NameNotFoundException: Name
> > org.ui.beans.RequestBean
> > is not bound in this Context
> >        at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> >        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> >        at
> >
> > org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:203)
> >
> > [snip]
> >
> >
> Hmmm.  I'm not sure I have the JSF expertise to figure out what the moving
> parts are.  Is there an IceFaces developer that we can pull into this
> thread?  Maybe between the two projects we can figure something out.
>
> Also, I am at JavaOne, so if there's someone from IceSoft around, I'd be
> happy to sit down with them.
>
> -David
>
>


-- 
Karan Singh Malhi

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message