Note that there are some explanatory texts on larger screens.

plurals
  1. POGuice @SessionScoped annotation causes IllegalArgumentException with Shiro HttpSession
    primarykey
    data
    text
    <p>I have an Apache Wicket 1.5 application that uses Shiro for security, and Guice for dependency injection. Most of its pages are stateless, but some of my model objects (user data, current menu state, ...) need to be consistent across all requests in the same session. All of these objects have both logic (mostly simple finder methods using remote EJB3 interfaces to access a database) and state, and all of them implement Serializable.</p> <p>Here's a short excerpt that should convey the idea:</p> <pre><code>@SessionScoped public class UsersImpl implements Users, Serializable { private static final long serialVersionUID = 8841809043461673585L; private final Logger log = LoggerFactory.getLogger( UsersImpl.class ); @Inject public UserService users; @Inject public RoleService roles; private UserDTO currentUser; public UserVO findUserByUser( UserVO user ) { UserDTO userDto = null; try { userDto = users.findUserByUser( user.toUserDTO() ); } catch( Exception e ) { log.error( "Error finding user:"+user.id, e ); } return userDto != null ? new UserVO( userDto ) : null; } (...) } </code></pre> <p>I developed and unit tested the classes using <code>@Singleton</code> (for simplicity), and everything works fine this way, but I get frequent errors like this, now that I have switched to <code>@SessionScoped</code> for production:</p> <pre><code>Guice provision errors: 1) Error in custom provider, org.apache.shiro.session.InvalidSessionException: java.lang.IllegalArgumentException: HttpSession based implementations of the Shiro Session interface requires attribute keys to be String objects. The HttpSession class does not support anything other than String keys. </code></pre> <p>Obviously, Guice seems to use some custom Key object to store the objects in the session, and the Shiro HttpSession implementation can't handle that. Strangely enough, though, this exception does not occur for all of the <code>@SessionScoped</code> classes, but certainly for more than one. </p> <p>I have been searching the web like crazy, looking for an idea what I could do - some way to force Guice to use Strings for keys, some other way to make the HttpSession more compatible, anything - but I can't seem to find any helpful information. Also, judging from my search results for the error message, I seem to be the only person on the planet who even has this problem at all... </p> <p>Is there any way to make this work? Or am I doing something wrong here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload