-
1. Re: Inject Request beans into a servlet fails
lightguard Aug 10, 2011 12:31 PM (in response to craig)Sounds like something is really broken. Would you paste some code please?
-
2. Re: Inject Request beans into a servlet fails
craig Aug 16, 2011 12:05 AM (in response to craig)I think this is a result of a producer method...
I have a @SessionScoped bean that observes a LoginEvent.
This bean then has a method that produces the User, using @Produces and @LoggedIn.
This value is injected into a @Stateless bean as @Inject @Logged User.
If remove the User injection all works fine.
Any ideas?
Many thanks
Craig
-
3. Re: Inject Request beans into a servlet fails
lightguard Aug 16, 2011 4:15 PM (in response to craig)
Craig wrote on Aug 16, 2011 00:05:
I think this is a result of a producer method...
I have a @SessionScoped bean that observes a LoginEvent.
This bean then has a method that produces the User, using @Produces and @LoggedIn.
This value is injected into a @Stateless bean as @Inject @Logged User.
If remove the User injection all works fine.
Any ideas?
Many thanks
CraigIf the producer produces @LoggedIn and you're injecting @Logged that won't work. Try changing the qualifiers on one or the other.
-
4. Re: Inject Request beans into a servlet fails
craig Aug 17, 2011 2:27 AM (in response to craig)Sorry that was a typo
Both produces and inject used @LoggedIn (not the seam version, this is an application annotation)
Thanks
Craig
-
5. Re: Inject Request beans into a servlet fails
lightguard Aug 17, 2011 2:37 AM (in response to craig)Could you please paste some code for the injection point and the producer?
-
6. Re: Inject Request beans into a servlet fails
craig Aug 17, 2011 2:46 AM (in response to craig)Sure, thanks for you help...
@SessionScoped
public class SessionContext implements Serializable
{
@Inject
private Logger log;
private static final long serialVersionUID = 1L;
private Account account;
private User user;
public void userAuthenticated(@Observes @LoggedIn User user)
{
this.user = null;
log.infov("User swapped to : {0}", user.getUsername());
this.user = user;
this.account = user.getAccount();
}
public void userLoggedOut(@Observes @LoggedOut User user)
{
this.user = null;
}
@Produces
@LoggedIn
public User getUser()
{
return user;
}
@Produces
@LoggedIn
public Account getAccount()
{
return account;
}
}@WebServlet(urlPatterns="/resource", loadOnStartup=1)
public class ResourceServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Inject
private ResourceManager resourceManager;
........
}@RequestScoped
public class ResourceManager implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
@LoggedIn
private Account account;
........
}Thanks again
Craig
-
7. Re: Inject Request beans into a servlet fails
lightguard Aug 17, 2011 3:42 AM (in response to craig)Sorry, going to ask you to repaste and use ` to surround your code :)
-
8. Re: Inject Request beans into a servlet fails
craig Aug 17, 2011 3:56 AM (in response to craig)Sorry my bad, should have previewed...
@SessionScoped public class SessionContext implements Serializable { @Inject private Logger log; private static final long serialVersionUID = 1L; private Account account; private User user; public void userAuthenticated(@Observes @LoggedIn User user) { log.infov("User swapped to : {0}", user.getUsername()); this.user = user; this.account = user.getAccount(); } public void userLoggedOut(@Observes @LoggedOut User user) { this.user = null; } @Produces @LoggedIn public User getUser() { return user; } @Produces @LoggedIn public Account getAccount() { return account; } }
@WebServlet(urlPatterns="/resource", loadOnStartup=1) public class ResourceServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Inject private ResourceManager resourceManager; ........ }
@RequestScoped public class ResourceManager implements Serializable { private static final long serialVersionUID = 1L; @Inject @LoggedIn private Account account; ........ }
-
9. Re: Inject Request beans into a servlet fails
lightguard Aug 17, 2011 4:59 AM (in response to craig)It may be possible you're running into https://issues.jboss.org/browse/WELD-892