I am trying to implement Twitter login process. During the login process a user need to be redirected to a Twitter web-site to enter his/her credentials and then he/she will be redirected to my website URL. Before the first redirect an instance of RequestToken object (Twitter4J library) should be stored and retained between requests.
To do it I decided to use ConverstaionScoped bean, but unfortunately values of references are not retained between requests.
Here are my JSF pages:
twitter.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<f:event listener="#{twitterLoginPageController.login()}" type="preRenderView" />
</html>
twitterRedirect.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<f:event listener="#{twitterLoginPageController.onRedirect(param.oauth_token, param.oauth_verifier)}" type="preRenderView" />
</html>
My Twitter login controller:
@Named
@ConversationScoped
public class TwitterLoginPageController implements Serializable {
@Inject
private Conversation conversation;
// These objects should be retained between requests
Twitter twitter;
RequestToken requestToken;
public void login() {
try {
twitter = new TwitterFactory().getInstance();
requestToken = twitter.getOAuthRequestToken("...");
conversation.begin();
conversation.setTimeout(30000);
// Navigate to Twitter here
} catch (TwitterException ex) {
...
}
}
public void onRedirect(String oauthToken, String oauthVerifier) {
try {
// twitter reference is null here
twitter.getOAuthAccessToken(requestToken, oauthVerifier);
...
} catch (TwitterException e) {
...
} finally {
conversation.end();
}
}
}
It seems to me that I am following examples of using @ConverstaionScope closely, but I fail to get the expected result. What should I do to retain objects between requests?