Upgraded to jboss-EJB-3.0_RC9

I upgraded to the latest EJB3 update from JBoss. I switched to jboss-EJB-3.0_RC9-FD (was using RC1). My custom @InjectorService annotation implementation had to change slightly. Here is the updated class.

package com.aver.web;

import static java.lang.System.out;

import java.lang.reflect.Field;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.aver.web.annotation.InjectService;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.AroundInterceptor;

public class ServiceInjector extends AroundInterceptor
{
protected void after(ActionInvocation arg0, String arg1) throws Exception
{
}

protected void before(ActionInvocation invocation) throws Exception
{
Object action = invocation.getAction();
Class clazz = action.getClass();
out.println(action.getClass().getName());
for (Field field : clazz.getDeclaredFields())
{
out.println(">>> " + field.getName());
if (field.isAnnotationPresent(InjectService.class))
{
out.println("FIELD " + field.getName() + " IS ANNOTATED WITH @InjectService -> "
+ field.getType().getSimpleName());
field.set(action, getService("myapp/" + field.getType().getSimpleName() + "Bean/local"));
}
}

}

private Object getService(String serviceJndiName)
{
Context ctx;
try
{
ctx = new InitialContext();
return ctx.lookup(serviceJndiName);
}
catch (NamingException e)
{
e.printStackTrace();
}
return null;
}
}

The JNDI name by default (if you deploy in ear format) is earfilename/beanname/local (or remote for remote interfaces). So in my case TimeService would be deployed as myapp/TimeServiceBean/local.

Once past this all is good.

 del.icio.us  Stumbleupon  Technorati  Digg 

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.