forgive this delay, but i got it:
That’s true, but even if it’s just a copy, it still hold the session id.
I’ve been quiet for a while, while i was trying to get this to work, and now i get it.
It’s not general or pretty, but with some help i think it would be a great addition to the framework.
Here’s how it works:
A simple VaadinServlet extension:
public class MyServlet extends VaadinServlet {
// the push handler
FilterablePushHandler handler;
@Override
protected VaadinServletService createServletService(
DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
VaadinServletService service = super.createServletService(deploymentConfiguration);
final AtmosphereFramework framework = DefaultBroadcasterFactory.getDefault().lookup("/*").getBroadcasterConfig().getAtmosphereConfig().framework();
//replace the handler registered by vaadin with thi one
handler = new FilterablePushHandler(service);
framework.addAtmosphereHandler("/*", handler);
assert service.ensurePushAvailable() == true;
return service;
}
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//the handler will sett this attribute prior to call the filterchain (that will conclude with the servlet)
Object p = request.getAttribute(FilterablePushHandler.WEB_SOCKET_PUSH_REROUTED);
if(p != null && p.equals(true)){
//the handler also pass the AtmosphereResource
AtmosphereResource resource = (AtmosphereResource) request.getAttribute(FilterablePushHandler.ATMOSPHERE_RESOURCE);
handler.onRequest(resource);
request.removeAttribute(FilterablePushHandler.WEB_SOCKET_PUSH_REROUTED);
request.removeAttribute(FilterablePushHandler.ATMOSPHERE_RESOURCE);
}else{
// if this is not a "simulated" request from the push handler i should handle normally
super.service(request, response);
}
}
}
The pushHandler
public class FilterablePushHandler extends PushHandler {
public static final String WEB_SOCKET_PUSH_REROUTED = "com.vaadin.server.communication.FilterablePushHandler.WEB_SOCKET_PUSH_REROUTED";
public static final String ATMOSPHERE_RESOURCE = "com.vaadin.server.communication.FilterablePushHandler.ATMOSPHERE_RESOURCE";
public FilterablePushHandler(VaadinServletService service) {
super(service);
}
@Override
public void onRequest(AtmosphereResource resource) {
AtmosphereRequest req = resource.getRequest();
if (req.getMethod().equalsIgnoreCase("GET")) {
//if it's a connection inizialization request i handle it normally
super.onRequest(resource);
} else if (req.getMethod().equalsIgnoreCase("POST")) {
//if it's a push request, execute first the filterChain
Object p = resource.getRequest().getAttribute(WEB_SOCKET_PUSH_REROUTED);
if(p != null && p.equals(true)){
//if this has been flagged as push request (and the filters has been already runned)
//handle the request with the original handler...
super.onRequest(resource);
}else{
try {
//...else flag this ad handled (filterChain executed)
resource.getRequest().setAttribute(WEB_SOCKET_PUSH_REROUTED, true);
resource.getRequest().setAttribute(ATMOSPHERE_RESOURCE, resource);
//Retrieve the guiceFilter instance and call it.
//It's the first filter in the chain, and will esecute an internal chain (not the default one)
MyGuiceFilter.instance.doFilter(resource.getRequest(), resource.getResponse(), new FilterChain() {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1)
throws IOException, ServletException {
//will never be called (guice execute internal filterChain and skip this)
assert false;
}
});
} catch (IOException | ServletException e) {
e.printStackTrace();
assert false;
}
}
}
}
}
I need to find a better way…
//this simple let me get the filter instance
public class MyGuiceFilter extends GuiceFilter {
public static EScrumGuiceFilter instance = null;
public EScrumGuiceFilter() {
super();
assert instance == null;
instance = this;
}
}
Here it is. Ugly and Broken as it is, but a starting poin. Is Anyone interested in helping with to put this in the framework?
I think the way push work right now is broken…this should fix.