我正在使用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会被调用两次:
我真正想做的是第一次请求中已经添加了授权标题!我怎么能这样做?
我正在使用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);
答案 0 :(得分:0)
你说得对,文档中的示例无法编译。尝试用HttpHost实例替换字符串“com.bluemonkeydiamond.sippycups”。 HttpHost类有几个构造函数,所以一定要查看JavaDocs。最简单的构造函数采用字符串。例如,
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("com.bluemonkeydiamond.sippycups"), basicAuth);