Question

Java SDK Subscription Refresh Causing 401 Error

  • 29 May 2019
  • 1 reply
  • 1510 views

I'm able to successfully create a new subscription using the Java SDK, but when the subscription attempts to refresh itself it's failing with a 401 error. Either there is a bug with the Java SDK or I'm missing something.

When the subscription is created, it starts a timer to regularly refresh itself:

https://github.com/ringcentral/ringcentral-java/blob/master/src/main/java/com/ringcentral/Subscription.java#L89


Bug when this code runs:

https://github.com/ringcentral/ringcentral-java/blob/master/src/main/java/com/ringcentral/Subscription.java#L110


This error results:

com.ringcentral.RestException: HTTP status code: 401


{

"errorCode" : "TokenInvalid",

"message" : "Token not found",

"errors" : [ {

"errorCode" : "OAU-213",

"message" : "Token not found"

} ]

}

at com.ringcentral.RestClient.request(RestClient.java:152)

at com.ringcentral.HttpClient.put(HttpClient.java:43)

at com.ringcentral.HttpClient.put(HttpClient.java:77)

at com.ringcentral.Subscription.refresh(Subscription.java:115)

at com.ringcentral.Subscription$2.run(Subscription.java:94)

at java.util.TimerThread.mainLoop(Timer.java:555)

at java.util.TimerThread.run(Timer.java:505)


Am I doing something wrong or is this an issue with the SDK?



1 reply

Userlevel 1

Hi Dan,

Yes, the subscription object renews (refresh) the PubNub notifications automatically. It uses the RestClient object, which uses the access token to renew the subscription periodically.

The RestClient is also, by default, auto-refresh, which uses the refresh token to request for a new access token if the access token expires.

In your case, it could be either, the refresh token is also expired if you ran your app for more than a week, which may not be likely the situation. Or, somehow, the access token was revoked.

I ran my test code for a few hours and the notification works fine.

Can you double check, make a simple test and let me know.

Reply