我RESTEasy Proxy Framework
用来打电话给我的休息服务。我想对代理框架使用抢先式身份验证。
那是我当前的代码:
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 会被调用两次:
- 首先客户端收到 401 错误(未授权)
- 在第二个请求中添加了授权标头,一切正常。
我真正想做的是在第一个请求中已经添加了授权标头!我怎样才能做到这一点?
我正在使用 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);