Pusher for Android Implementation -


i'm trying implement pusher service in android app, doesn't have access server copying ios app previous implementation. works fine in connection process when subscribe private channel authentication fails with:

"com.pusher.client.authorizationfailureexception: java.io.filenotfoundexception: https://authorization_url" 

the implementation goes this:

    httpauthorizer authorizer = new httpauthorizer(pusher_auth_url);     pusheroptions options = new pusheroptions().setencrypted(true).setwssport(443).setauthorizer(authorizer);     pusher = new pusher(pusher_key, options);     pusher.connect(new com.pusher.client.connection.connectioneventlistener() {                     @override                     public void onconnectionstatechange(connectionstatechange change) {                          if (change.getcurrentstate() == connectionstate.connected) {                             channel channel = pusher.subscribeprivate(push_channel, new privatechanneleventlistener() {                                 @override                                 public void onauthenticationfailure(string s, exception e) {                                     log.w("pusher", "channel subscription authorization failed");                                 }                                  @override                                 public void onsubscriptionsucceeded(string s) {                                     log.w("pusher", "channel subscription authorization succeeded");                                 }                                  @override                                 public void onevent(string s, string s2, string s3) {                                     log.w("pusher", "an event name " + s2 + " delivered!!");                                 }                             }, "my-event");                         }                     }                      @override                     public void onerror(string message, string code, exception e) {                         log.w("pusher", "there problem connecting code " + code + " , message " + message);                     }                 }, connectionstate.all); 

update

i'm sure problem authentication, there function call in ios version set headers channel subscription or that:

(void)pusher:(ptpusher *)pusher willauthorizechannel:(ptpusherchannel *)channel withrequest:(nsmutableurlrequest *)request; {     [request addauthorizationheadersforuser:self.credentials.user];  } 

im trying figure out add headers in android, try add authorizer nothing change:

authorizer.setheaders(addmapauthorizationheaders()); 

any idea of equivalent in android of ios function: willauthorizechannel??

ok solved, thought, httpauthorizer needed set of headers can set directly when creating like:

httpauthorizer authorizer = new httpauthorizer(pusher_auth_url); authorizer.setheaders(my_auth_headers); //a hashmap headers pusheroptions options = new pusheroptions().setencrypted(true).setwssport(443).setauthorizer(authorizer); pusher = new pusher(pusher_key, options); 

and works fine, in case have similar problem.

edit: how set authorization headers. it's map set "key" "value" pair example:

public static hashmap<string, string> getmapauthorizationheaders() {     try {         hashmap<string, string> authheader = new hashmap<>();         authheader.put("headerkey1", "headervalue1");         authheader.put("headerkey2", "headervalue2");         return authheader;      } catch (exception e) {         return null;     } } 

so pusher config like:

authorizer.setheaders(getmapauthorizationheaders()); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -