-
1. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 3:12 AM (in response to oourfali)What exactly does the code look like?
Oved O wrote:
I add the @Interceptor annotation (javax.interceptor.Interceptor) to that ejb, containing a class that is located in a jar in
<ear>/lib.
Are you really using @Interceptor or is that a typo? You'll have to use @Interceptors and point to the interceptor class(es).
-
2. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 3:19 AM (in response to jaikiran)Here is the code for the ejb:
package org.nogah.genericapi;
import java.util.ArrayList
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.interceptor.Interceptors;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.Addressing;
import org.nogah.utils.MyContextInterceptor;
import org.nogah.utils.ThreadLocalParamsContainer;
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@Addressing(enabled = true, required = true)
@WebService(name = "IBackendCxf", serviceName = "IBackend", targetNamespace = "http://service.org.nogah")
@Stateless
@Interceptors({ MyContextInterceptor.class })
public class GenericApiService {
@EJB(name="Backend")
//private static BackendLocal backend;
private static BackendInternal backend;
@WebMethod
public VdcReturnValueBase EndAction(VdcActionType actionType, VdcActionParametersBase parameters) {
VdcReturnValueBase returnValue = backend.EndAction(actionType, parameters);
return returnValue;
}
@WebMethod
public VdcReturnValueBase RunAction(VdcActionType actionType, VdcActionParametersBase parameters) {
VdcReturnValueBase returnValue = backend.RunAction(actionType, parameters);
return returnValue;
}
}
And here is the interceptor:
package org.nogah.utils;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import org.jboss.injection.WebServiceContextProxy;
import org.nogah.common.config.Config;
import org.nogah.common.config.ConfigValues;
import org.nogah.compat.LogCompat;
import org.nogah.compat.LogFactoryCompat;
public class MyContextInterceptor {
private static LogCompat log = LogFactoryCompat.getLog(MyContextInterceptor.class);
@AroundInvoke
public Object injectWebContextToThreadLocal(InvocationContext ic) throws Exception {
WebServiceContext wsContext = new WebServiceContextProxy();
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST))
.getSession();
session.setMaxInactiveInterval(Config.<Integer> GetValue(ConfigValues.UserSessionTimeOutInterval) * 60);
if (log.isDebugEnabled()) {
log.debug("session id=" + session.getId());
}
ThreadLocalParamsContainer.setHttpSessionId(session.getId());
return ic.proceed();
}
}
-
3. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 3:26 AM (in response to oourfali)What does the client code which invokes on the webservice, look like?
By the way, you have an (unrelated) issue in your code:
@EJB(name="Backend")
//private static BackendLocal backend;
private static BackendInternal backend;
You can't expect injection in static field/methods. Looks like we aren't taking that into account in AS7 during injection. I'll file a JIRA for that.
-
4. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 3:32 AM (in response to jaikiran)I'm not responsible for the client code (I use the same client code that worked for 5.1). How is it related?
As for the other issue, I didn't understand the problem.
You are saying it is not allowed to inject a static field?
It worked in jboss 5.1. And also works now in as7 :-)
Thank you,
Oved
-
5. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 3:38 AM (in response to oourfali)Oved O wrote:
I'm not responsible for the client code (I use the same client code that worked for 5.1). How is it related?
May not be related. But I want to understand the flow and see if there's anything obvious bug out there
Oved O wrote:
As for the other issue, I didn't understand the problem.
You are saying it is not allowed to inject a static field?
It worked in jboss 5.1. And also works now in as7 :-)
Java EE6 spec, section EE.5.2.5:
Any of the types of resources described in this chapter may be injected. Injection may also be requested using entries in the deployment descriptor corresponding to each of these resource types. The field or method may have any access qualifier (public, private, etc.). For all classes except application client main classes, the fields or methods must not be static.
-
6. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 3:43 AM (in response to oourfali)I understand.
Basically the client code provides a session id, and we use the interceptor in order to save it in the TLS.
The web service calls the backend code, and it uses this session id.
Perhaps the problem having an interceptor in the lib folder?
I have a similar issue with another ejb (without web methods), and it also takes the interceptor from the same jar.
-
7. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 3:45 AM (in response to oourfali)Oved O wrote:
Perhaps the problem having an interceptor in the lib folder?
Shouldn't be a problem. If it is, then it's a bug. Can you create a JIRA and attach a application which reproduces this?
Oved O wrote:
I have a similar issue with another ejb (without web methods), and it also takes the interceptor from the same jar.
That looks like a bug too. Can you attach that app too?
-
8. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 3:50 AM (in response to jaikiran)The application I have that reproduces it is large and with many dependencies (DB, LDAP server etc.).
I'll try to create a smaller example and attach it.
Do you happen to know if a similar issue happend for anyone else?
Thank you for your help and the quick response!
Oved
-
9. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 4:21 AM (in response to oourfali)Oved O wrote:
Do you happen to know if a similar issue happend for anyone else?
I haven't seen a similar issue related to interceptors being reported yet.
-
10. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 4:55 AM (in response to jaikiran)Will the following considered a good example?
I wanted to keep it as simple as possible, but I'm not sure it is a good reproduction.
I have an interceptor, and a jar with two ejbs:
MyRegularUser and CallingRegularUser.
CallingRegularUser depends on MyRegularUser, and in its initialization it looks up MyRegularUser bean, and calls one of its methods.
I'm just not sure whether or not the interceptor should be invoked in such a case.
I see clearly that it doesn't invoke, so if it should then it is a reproduction.
Interceptor:
package reproduction.interceptors;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
public class MyInterceptor {
@AroundInvoke
public Object injectWebContextToThreadLocal(InvocationContext ic) throws Exception {
System.out.println("testing");
return ic.proceed();
}
}
MyRegularUser:
package reproduction.regular_user;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.interceptor.Interceptors;
import reproduction.interceptors.MyInterceptor;
@Interceptors({ MyInterceptor.class })
@Singleton
@Startup
public class MyRegularUser {
@PostConstruct
public void init() {
System.out.println("initialized");
}
public void doSomething() {
System.out.println("something");
}
}
CallingRegularUser:
package reproduction.regular_user;
import javax.annotation.PostConstruct;
import javax.ejb.DependsOn;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@Singleton
@Startup
@DependsOn("MyRegularUser")
public class CallingRegularUser {
public static MyRegularUser getInstance() {
try {
Context context = new InitialContext();
Object res = context.lookup("java:app/test_reg/MyRegularUser");
if (res == null) {
System.out.println("returned null : ");
}
return (MyRegularUser) res;
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("exception : ");
}
return null;
}
@PostConstruct
public void init() {
System.out.println("calling initialized");
getInstance().doSomething();
}
public void doSomething() {
getInstance().doSomething();
}
}
Thank you,
Oved
-
11. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 5:48 AM (in response to oourfali)I made a better example.
I used two interceptors, one is in the same jar as the ejb, and one is in <ear>/lib.
The local interceptor runs, but the one from <ear>/lib doesn't.
Creating a new issue now.
Thank you!
-
12. Re: ejb interceptors are ignored
jaikiran Jul 15, 2011 10:15 AM (in response to oourfali)I just replied to that JIRA https://issues.jboss.org/browse/AS7-1295. It looks like you are testing this against AS 7.0 CR1. This works fine against AS7.0 Final.
-
13. Re: ejb interceptors are ignored
oourfali Jul 15, 2011 12:36 PM (in response to jaikiran)Indeed you are right.
I'll install the final release, and test it there.
Thank you,
Oved
-
14. Re: ejb interceptors are ignored
cbien Sep 11, 2013 5:06 AM (in response to jaikiran)Hello,
Does this issue disappear on jboss 7.1?
I'm still facing issues concerning the interceptor annotation ignored issue in the interface on Jboss 7.1.1 final. When an implementation class of TtService is called, the interceptors are never called on Jboss 7 but it works well on Jboss 5.1
@Interceptors({
// ExceptionHandler.class,
ContextAspect.class,
SecurityAspect.class
})
public interface TtService
public class ContextAspect{
....
@AroundInvoke
public Object setRequestContext(InvocationContext ctx) throws Exception
....