Hi Alain,

 For now I actually worked around in my code by catching the NPE, matching
the message "No authentication header information", and calling the
credential¹s refresh method myself.

 I don¹t have the code in front of me at the moment but I remember there may
have existed another issue. Somewhere there the exception message of
AuthenticationException is analyzed to decide if SessionExpiredException
should be thrown.  The code assumes the message would contain ŒToken
expired¹ w/ uppercase T but in reality the message arrived in response is a
bit different: ³Token invalid - Invalid token: Stateless token expired². So,
you may want to double check that part of the code also. Let me know if you
need the exact method name/ line number.

 Other than that the OAuth2 based ContactsService seems to be working fine.

Thanks much,
Alexey


On 6/11/12 2:34 PM, "Alain Vongsouvanh" <[email protected]> wrote:

> Hello,
> 
> Thanks for the issue report. I'll send in a patch ASAP, in the meantime, you
> can fix this by changing this line
> <https://code.google.com/p/gdata-java-client/source/browse/trunk/java/src/com/
> google/gdata/util/AuthenticationException.java#96> :
>     if (authHeader == null)
>       throw new NullPointerException("No authentication header information");
> 
> To return instead of throwing an exception.
> 
> Best,
> Alain
> 
> On Fri, Jun 8, 2012 at 3:39 PM, Alexey Panteleev <[email protected]> wrote:
>> Hello,
>> 
>>  I have just started using ContactsService in a new way, with OAuth2,
>> using GoogleCredential mechanism.
>> Unfortunately it seems there is a bug in the gdata lib or the protocol!
>> Whenever my token expires the library throws the NPE exception because
>> "WWW-Authenticate" si not available in the response.
>> So SessionExpiredException exception is never thrown and the credential's
>> refreshToken listener is never called.
>> 
>>  Any suggestions?
>> 
>> 
>>>>> >>>Token invalid - Invalid token: Stateless token expired<<<
>> 
>> Exception in thread "main" java.lang.NullPointerException: No authentication
>> header information
>> 
>> at 
>> com.google.gdata.util.AuthenticationException.initFromAuthHeader(Authenticati
>> onException.java:96)
>> 
>> at 
>> com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.
>> java:67)
>> 
>> at 
>> com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRe
>> quest.java:608)
>> 
>> at 
>> com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDa
>> taRequest.java:564)
>> 
>> at 
>> com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.
>> java:560)
>> 
>> at 
>> com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:5
>> 38)
>> 
>> at 
>> com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.ja
>> va:536)
>> 
>> at com.google.gdata.client.Service.getFeed(Service.java:1135)
>> 
>> 
>> 
>> 
>> 
>> 
>> GoogleCredential credential = new GoogleCredential.Builder()
>> 
>> .setTransport(new NetHttpTransport())
>> 
>> .setJsonFactory(new JacksonFactory())
>> 
>> .setClientSecrets(CLIENT_ID,
>> 
>> CLIENT_SECRET)
>> 
>> .addRefreshListener(new CredentialRefreshListener() {
>> 
>> 
>> 
>> @Override
>> 
>> public void onTokenResponse(Credential credential,
>> 
>> TokenResponse tokenResponse) {
>> 
>> svc.setAccessToken(tokenResponse.getAccessToken());
>> 
>> if (tokenResponse.getRefreshToken() != null)
>> 
>> svc.setRefreshToken(tokenResponse.getRefreshToken());
>> 
>> }
>> 
>> 
>> 
>> @Override
>> 
>> public void onTokenErrorResponse(Credential credential,
>> 
>> TokenErrorResponse tokenErrorResponse) {
>> 
>> svc.setAccessToken(null);
>> 
>> svc.setRefreshToken(null);
>> 
>> }
>> 
>> }).build();
>> 
>> 
>> 
>> credential.setAccessToken(svc.getAccessToken());
>> 
>> credential.setRefreshToken(svc.getRefreshToken());
>> 
>> 
>> myService = new ContactsService("App-1");
>> 
>> myService.setOAuth2Credentials(credential);

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to