RESTEasy Proxy Framework
Rest-Servicesを呼び出すために使用しています。プロキシフレームワークでプリエンプティブ認証を使用したいと思います。
それが私の現在のコードです:
public void callSomeService() throws Exception {
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
DefaultHttpClient client = new DefaultHttpClient();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
USERNAME, PASSWORD);
AuthScope authscope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT, AuthScope.ANY_REALM);
client.getCredentialsProvider().setCredentials(authscope, credentials);
ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(client);
dummyResource = ProxyFactory.create(DummyResource.class,
"http://localhost:8888/myapp/rest/", executer);
// Do some calls here
}
アプリケーションのトラフィックを監視すると、Rest-Serviceが2回呼び出されます。
- 最初に、クライアントは401エラー(未承認)を受け取ります
- 2番目のリクエストでは、承認ヘッダーが追加され、すべてが正常に機能します。
私が実際にやりたいのは、最初のリクエストで承認ヘッダーがすでに追加されていることです。どうやってやるの?
RESTEasy 2.3.5を使用しています!また、ドキュメント(http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html_single/index.html#transport_layer)も読みました。これは、プリエンプティブ認証の例ですが、実際には機能しません。このコードのため:
BasicScheme basicAuth = new BasicScheme();
authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);