Here is some hints for the AOP caching mechanism using Java 1.5+ with
AspectJ.
1. Wraps all API calls that might throw the ApiException.
2. Look for the GOOGLE_ACCOUNT_COOKIE_INVALID exception reason.
3. Reverse lookup AdWordsUser from Stub._getService() for the email
and pwd.
4. Request a new auth token and update the cache.
5. Update the auth token back to the user instance and Soap header.
6. Retry the last operation.
The use of call() instead of execute() is because I'm using compile-
time weaving instead of load-time weaving to avoid any changes to the
deployment target's environment or the AdWords library itself.
-------- begin --------
@Pointcut("call(public * com.google.api.adwords..*(..) throws
com.google.api.adwords.v200909.cm.ApiException) && target(stub)")
void authWrapperCut(Stub stub) {}
@Around("authWrapperCut(stub)")
public Object authWrapper(ProceedingJoinPoint pjp, Stub stub) throws
Throwable {
try {
return pjp.proceed();
} catch (Throwable e) {
if ( e instanceof ApiException ) {
ApiException ae = (ApiException) e;
ApiError[] errors = ae.getErrors();
if ( null != errors && errors.length > 0 ) {
if ( errors[0] instanceof
AuthenticationError ) {
// Renew the auth token when
this authentication error happened.
if
( AuthenticationErrorReason.GOOGLE_ACCOUNT_COOKIE_INVALID.equals
(((AuthenticationError)errors[0]).getReason())) {
AdWordsUser user =
serviceUsers.get(stub._getService());
String token =
requestAuthToken(user.getEmail(),
user.getPassword());
user.setAuthToken(token);
SOAPHeaderElement he =
stub.getHeaders()[0];
SoapHeader sh =
(SoapHeader) he.getObjectValue();
sh.setAuthToken(token);
return pjp.proceed();
}
}
}
}
throw e;
}
}
-------- end ----------
--
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" 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://groups.google.com/group/adwords-api?hl=en.