Hello,
i've got a problem since i migrated from Warp Persist to guice persist
which i can not really understand.
I'm working on an app that is using the built in login mechanism from
glassfishV3. To use this I'm injecting a Provider<HttpServletRequest>
in my class.
When using Warp Persist that is not a problem. I set everything up,
especially to mention the Guice Filter, (also the new version 3.0 one)
and everything works like a charm! I can inject the Request, Session
and all the stuff.
Now I just removed the Warp dependencies and set up Guice Persist and
suddenly i get the exception:
"Error in custom provider, com.google.inject.OutOfScopeException:
Cannot access scoped object. Either we are not currently inside an
HTTP Servlet request, or you may have forgotten to apply
com.google.inject.servlet.GuiceFilter as a servlet filter for this
request."
when I'm trying to inject a HttpServletRequest.
The funny thing is that Guice Persist itself is working. I can get,
insert and remove Entities without problems.
I also did not change anything regarding the GuiceFilter!
I spent the whole day trying things out, but nothing solved my
problem. Mainly i played around with the filter mappings in my web.xml
and the ServletModule where I define my JPA Unit.
My setup here is:
GlassfishV3.1
Guice 3.0
web.xml parts that could be important:
<filter>
<filter-name>guiceFiler</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-
class>
</filter>
<filter-mapping>
<filter-name>guiceFiler</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>login area</web-resource-name>
<url-pattern>/index.xhtml</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
The security constraint makes an automatic redirect to https on the
login page (index.xhtml) but, as already said, warp persist had no
problem with that.
ServletModule:
public class MyModule extends ServletModule {
//got a few Singleton bindings in here, this shouldn't be a problem,
should it?
/* Guice Persist */
install(new JpaPersistModule("MyPersistenceUnit"));
bind(GuiceInit.class).asEagerSingleton();
//filter("/*").through(GuiceFilter.class); tried that
filter("/*").through(PersistFilter.class);
}
GuiceInit class:
private final PersistService service;
public class GuiceInit {
@Inject
GuiceInit(PersistService service) {
this.service = service;
this.service.start();
}
public PersistService getService() {
return service;
}
}
public class UserDaoImpl extends DaoImpl<Long, User> implements
UserDao {
private final Provider<HttpServletRequest> requestProvider;
@Inject
public UserDaoImpl(Provider<EntityManager> entityManagerProvider,
Provider<HttpServletRequest> requestProvider) {
super(entityManagerProvider);
this.requestProvider = requestProvider;
}
@Transactional
public User logUserIn(String loginName, String password) {
try {
//User user = findByLoginName("admin"); THAT WORKS!
HttpServletRequest request = requestProvider.get() //THAT
DOES NOT :(
...
} ...
}
I was also able to lookup the Request by myself, so it is there! ; )
I'm happy about every hint, as i would like to migrate completely to
the new stuff after i read yesterday in the warp persist forum that
warp persist now lives on as guice persist!
Regards
Alex
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.