Twitterのログインプロセスを実装しようとしています。ログイン プロセス中に、ユーザーは Twitter Web サイトにリダイレクトされて資格情報を入力する必要があり、その後、私の Web サイト URL にリダイレクトされます。最初のリダイレクトの前に、RequestToken オブジェクト (Twitter4J ライブラリ) のインスタンスを保存し、リクエスト間で保持する必要があります。
それを行うために ConverstaionScoped Bean を使用することにしましたが、残念ながら参照の値はリクエスト間で保持されません。
ここに私のJSFページがあります:
ツイッター.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>
私のTwitterログインコントローラー:
@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();
}
}
}
@ConverstaionScope の使用例に厳密に従っているように思えますが、期待した結果が得られません。リクエスト間でオブジェクトを保持するにはどうすればよいですか?