
import javax.enterprise.inject.spi.CDI;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author apple
 */
public class WSKonfigurator extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest req, HandshakeResponse res) {
        super.modifyHandshake(sec, req, res); 
        UzytkownikBean ub = CDI.current().select(UzytkownikBean.class).get();
        sec.getUserProperties().put("uzytkownik", ub.getLogin());
        
    }
    
    @Override
    public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
        CzatBean cb = CDI.current().select(CzatBean.class).get();
        if (cb == null)
            return super.getEndpointInstance(endpointClass);
        else
            return (T)cb;
    }
    
}
