Dontpush ozone layer : cookie management

Hi,

I’m doing some tests with the DontPush OzoneLayer demo (Tomcat 7 and DontpushApplicationWithTrxListeners used) and I’m trying to add a cookie when I click on a button.
Unfortunately, the added cookie is not seen in Firebug : it seems that it’s only added in a copy of the original HttpResponse.
Here is the code used :

package org.vaadin.dontpush.demo;

import com.vaadin.Application;
import com.vaadin.service.ApplicationContext.TransactionListener;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Window;
import java.util.Collection;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.atmosphere.cpr.AtmosphereResource;
import org.vaadin.dontpush.server.DontPushBroadcaster;

public class DontpushApplicationWithTrxListeners extends Application implements HttpServletRequestListener {

    private static final long serialVersionUID = 1L;

    @Override
    public void init() {
        TestWindow testWindow = new TestWindow();
        setMainWindow(testWindow);
        getContext().addTransactionListener(new TransactionListener() {
            private static final long serialVersionUID = 1L;
            @Override
            public void transactionEnd(Application application, Object transactionData) {
                System.err.println("trx start");
                if (transactionData instanceof DontPushBroadcaster) {
                    for (AtmosphereResource resource : ((DontPushBroadcaster) transactionData).getAtmosphereResources()) {
                        resource.getResponse().addCookie(new Cookie("name1","value1"));
                    }
                }
            }

            @Override
            public void transactionStart(Application application, Object transactionData) {
            }

        });
    }

    @Override
    public Window getWindow(String name) {
        Window w = super.getWindow(name);
        if (w == null) {
            w = new TestWindow();
            addWindow(w);
            w.open(new ExternalResource(w.getURL()));
            return w;
        }
        return w;
    }

    @Override
    public void close() {
        super.close();
        Collection<Window> windows2 = getWindows();
        for (Window window : windows2) {
            TestWindow.unregister((TestWindow) window);
        }
    }

    @Override
    public void onRequestStart(HttpServletRequest request,
            HttpServletResponse response) {
        System.err.println("request start");
    }

    @Override
    public void onRequestEnd(HttpServletRequest request,
            HttpServletResponse response) {
        System.err.println("request end");
    }
}

Any help/suggestions would be great.

Thanks.

Hi,

The request/response in trx listeners is probably just an empty dummy implementation. Real request/response may be unavailable due to varying communication methods (e.g. websockets).

With modern websocket/push stuff you might be better off by setting cookies on the “client side” with Sami’s BrowserCookies add-on:
http://vaadin.com/directory#addon/browsercookies

cheers,
matti

Hi,

Thanks Matti, I’ll try this solution!

Florent