I'm trying to inject a interceptor in my BackingBean, see:
@SimpleAsync
@Interceptor
public class SimpleAsyncImpl implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Inject
ScheduleManager sm;
Logger logger = Logger.getLogger(getClass().getName());
@AroundInvoke
public Object callAsync(final InvocationContext ctx) throws Exception {
logger.fine("Invokingchronous method: " + ctx.getMethod().getName());
// Schedule 0 seconds from now
sm.schedule(new Runnable() {
@Override
public void run() {
try {
ctx.proceed();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception from asynchronously invoked method.", e);
}
}
}, 0);
return null;
}
}
@InterceptorBinding
@Target(value={ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface SimpleAsync {
}
Now i have the use in my BackingBean:
@Named("acervoVideoDetalheMB")
@ConversationScoped
public class AcervoVideoDetalheMBImpl extends BasicDetailMBImpl<AcervoVideo> {
@SimpleAsync
private void initEnvioVideo(final Part partVideo, String originalName, final String target) {
}
The @SimpleAsync is my interceptor, and as you can see the constructor of AcervoVideoDetalheMBIMpl needs a ParametrizedType, the AcervoVideo bean. In my postConstruct i have the following:
@PostConstruct
public void postConstruct() {
try {
ParameterizedType superClass = (ParameterizedType) getClass()
.getGenericSuperclass();
Class<Bean> type = (Class<Bean>) superClass
.getActualTypeArguments()[0];
return type.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
I got the following error:
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
But if i remove the @SimpleAsync annotation everything works fine because i disabled Interceptor.