Igor Vaynberg schrieb:
map WicketSessionFilter in front of those servlets, you will get both
Session.get() and Session.get().getApplication(), and
Application.get()
actually, (as the name implies), this is quite session centric. my
current use case is web services where i don´t have a session.
subclassing WicketFilter is not too easy as well, because it does not
reveal the application reference (private, no getter).
this makes me do nasty reflection tricks to get it, which - while it
works - feels even much more dirty than using the singleton approach to
get an application reference.
any idea, how this could be done with a cleaner approach?
or would
WicketFilter: protected WebApplication getApplication()
be an alternative?
cu uwe
------- current nasty impl:
@Override
public void doFilter(final ServletRequest request, final
ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
super.doFilter(request, response, new ModifiedChain(chain,
getApplication()));
}
private Application getApplication() {
// very very nasty
return (Application) getFieldValue(this, "webApplication");
}
public static Object getFieldValue(final Object obj, final String
string) {
// did i say nasty?
try {
final Field declaredField =
obj.getClass().getSuperclass().getDeclaredField(string);
declaredField.setAccessible(true);
return declaredField.get(obj);
}
catch (final Throwable e) {
throw new RuntimeException(e);
}
}
}
class ModifiedChain implements FilterChain
{
private FilterChain orgChain;
private final Application application;
public ModifiedChain(final FilterChain chain, final Application
application) {
this.orgChain = chain;
this.application = application;
}
public void doFilter(final ServletRequest request, final
ServletResponse response) throws IOException,
ServletException {
Application.set(this.application);
try {
this.orgChain.doFilter(request, response);
}
finally {
Application.unset();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org