![](/img/trans.png)
[英]How to do Preemptive Authentication in SOAP Based Web Service Client
[英]RESTEasy Client Proxy Preemptive Basic Authentication
我正在使用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);
没错,文档中的示例无法编译。 尝试使用HttpHost实例替换字符串“ com.bluemonkeydiamond.sippycups”。 HttpHost类具有多个构造函数,因此请务必查看JavaDocs。 最简单的构造函数采用字符串。 例如,
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("com.bluemonkeydiamond.sippycups"), basicAuth);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.