New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP long polling transport should allow to exchange binary message #77

Closed
flowersinthesand opened this Issue Feb 1, 2015 · 1 comment

Comments

Projects
None yet
1 participant

@flowersinthesand flowersinthesand added this to the 3.0.0-Alpha14 milestone Feb 1, 2015

@flowersinthesand

This comment has been minimized.

Show comment
Hide comment
@flowersinthesand

flowersinthesand Feb 1, 2015

Contributor

Test result along with vibe-project/vibe-protocol#54 (comment)

package test;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.WebListener;

import org.atmosphere.cpr.ApplicationConfig;
import org.atmosphere.vibe.platform.action.Action;
import org.atmosphere.vibe.platform.bridge.atmosphere2.VibeAtmosphereServlet;
import org.atmosphere.vibe.transport.ServerTransport;
import org.atmosphere.vibe.transport.http.HttpTransportServer;

@WebListener
public class HttpLongpollTransportTest implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        HttpTransportServer server = new HttpTransportServer().transportAction(new Action<ServerTransport>() {
            @Override
            public void on(final ServerTransport transport) {
                System.out.println("opened");
                transport.textAction(new Action<String>() {
                    @Override
                    public void on(String data) {
                        System.out.println("on text " + data);
                        transport.send(data);
                    }
                })
                .binaryAction(new Action<ByteBuffer>() {
                    @Override
                    public void on(ByteBuffer data) {
                        System.out.println("on binary " + data + " " + new String(data.array(), Charset.forName("utf-8")));
                        transport.send(data);
                    }
                });
            }
        });
        Servlet servlet = new VibeAtmosphereServlet().httpAction(server);
        ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet);
        reg.setAsyncSupported(true);
        reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
        reg.addMapping("/vibe");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {}
}

// opened
// on text hello
// on binary java.nio.HeapByteBuffer[pos=0 lim=5 cap=5] hello
Contributor

flowersinthesand commented Feb 1, 2015

Test result along with vibe-project/vibe-protocol#54 (comment)

package test;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.WebListener;

import org.atmosphere.cpr.ApplicationConfig;
import org.atmosphere.vibe.platform.action.Action;
import org.atmosphere.vibe.platform.bridge.atmosphere2.VibeAtmosphereServlet;
import org.atmosphere.vibe.transport.ServerTransport;
import org.atmosphere.vibe.transport.http.HttpTransportServer;

@WebListener
public class HttpLongpollTransportTest implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        HttpTransportServer server = new HttpTransportServer().transportAction(new Action<ServerTransport>() {
            @Override
            public void on(final ServerTransport transport) {
                System.out.println("opened");
                transport.textAction(new Action<String>() {
                    @Override
                    public void on(String data) {
                        System.out.println("on text " + data);
                        transport.send(data);
                    }
                })
                .binaryAction(new Action<ByteBuffer>() {
                    @Override
                    public void on(ByteBuffer data) {
                        System.out.println("on binary " + data + " " + new String(data.array(), Charset.forName("utf-8")));
                        transport.send(data);
                    }
                });
            }
        });
        Servlet servlet = new VibeAtmosphereServlet().httpAction(server);
        ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet);
        reg.setAsyncSupported(true);
        reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
        reg.addMapping("/vibe");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {}
}

// opened
// on text hello
// on binary java.nio.HeapByteBuffer[pos=0 lim=5 cap=5] hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment