Created
October 3, 2012 19:11
-
-
Save marianogonzalez/3829112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SharedOAuthTokenTransformer extends AbstractMessageTransformer { | |
private ObjectStore<Serializable> objectStore; | |
@Override | |
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { | |
String accessTokenId = message.getInvocationProperty("OAuthAccessTokenId"); | |
if (StringUtils.isBlank(accessTokenId)) { | |
throw new IllegalStateException("OAuthAccessTokenId is blank or null"); | |
} | |
GoogleCalendarConnectorOAuthState state = null; | |
try { | |
state = (GoogleCalendarConnectorOAuthState) this.objectStore.retrieve(accessTokenId); | |
} catch (ObjectStoreException e) { | |
throw new RuntimeException(String.format("exception reading OAuth object store with key %s", accessTokenId), e); | |
} | |
if (state == null) { | |
throw new IllegalStateException("Got null oauth state for key " + accessTokenId); | |
} | |
GoogleTasksConnectorOAuthState taskState = new GoogleTasksConnectorOAuthState(); | |
taskState.setAccessToken(state.getAccessToken()); | |
taskState.setAccessTokenUrl(state.getAccessTokenUrl()); | |
taskState.setAuthorizationUrl(state.getAccessTokenUrl()); | |
taskState.setRefreshToken(state.getRefreshToken()); | |
try { | |
this.objectStore.store(accessTokenId + "Task", taskState); | |
} catch (ObjectStoreException e) { | |
throw new RuntimeException(String.format("exception writing task OAuth state with key %s", accessTokenId), e); | |
} | |
return message; | |
} | |
public void setObjectStore(ObjectStore<Serializable> objectStore) { | |
this.objectStore = objectStore; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment