All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.gkutiel.flip.web.JsonSocket Maven / Gradle / Ivy

package com.github.gkutiel.flip.web;

import java.io.IOException;
import java.util.Arrays;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.eclipse.jetty.websocket.WebSocket;

import com.github.gkutiel.flip.utils.Utils;

public abstract class JsonSocket implements WebSocket.OnTextMessage, Cloneable {

	private final Cookie[] cookies;
	protected Connection con;

	public JsonSocket(final HttpServletRequest req) {
		cookies = req.getCookies();
	}

	public void close() {
		if (con != null) con.disconnect();
	}

	public final  T get(final Key key) {
		return HttpUtils.get(cookies, key);
	}

	protected abstract void init();

	@Override
	public final void onOpen(final Connection con) {
		this.con = con;
		init();
	}

	public final void send(final Object msg) throws IOException {
		con.sendMessage(Utils.Json.toString(msg));
	}

	@Override
	public String toString() {
		return Arrays.toString(cookies);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy