websocket - Android Autobahn request.getHttpSession() = null -
websocket - Android Autobahn request.getHttpSession() = null -
client side code:
private void startpolling() { final string wsuri = mainasync.web_socket_host_ws+"/game"; seek { mconnection.connect(wsuri, new websockethandler() { @override public void onopen() { log.d(tag, "status: connected " + wsuri); int role = maccmeth.loadid(getapplicationcontext()); mconnection.sendtextmessage(string.valueof(role)); } @override public void ontextmessage(string payload) { log.d(tag, "got echo: " + payload); } @override public void onclose(int code, string reason) { log.d(tag, "connection lost."); } }); } grab (websocketexception e) { log.d(tag, e.tostring()); } }
server side realisation:
@serverendpoint(value="/game",configurator = servletconfig.class) public class websocketpollingcoordinates { endpointconfig endconfig; @onmessage public void receivemessage(string message,final session session){ httpsession httpsession = (httpsession) endconfig.getuserproperties().get("httpsession"); //at line nullpointerexception final servletcontext sercntxt = (servletcontext)httpsession.getservletcontext(); } @onopen public void onopen(session sn, endpointconfig ec) { system.out.println("onopen"); this.endconfig = ec; } @onerror public void error(session session, throwable t) { t.printstacktrace(); }
and websocket config class:
public class servletconfig extends configurator{
@override public void modifyhandshake(serverendpointconfig config, handshakerequest request, handshakeresponse response) { httpsession httpsession = (httpsession) request.gethttpsession(); if(httpsession==null || config==null){ if(httpsession==null) system.out.println("httpsession==null"); if(config==null) system.out.println("config==null"); return; } config.getuserproperties().put("httpsession", httpsession); } }
i'm getting next out: http session == null. error? need httpsession, phone call void httpsession.getservletcontext();
android websocket request autobahn
Comments
Post a Comment