我正在尝试使用REST对我的jboss上运行的登录模块执行基本身份验证.我已经找到了StackOverflow主题,该主题解释了如何使用凭据进行身份验证.
RESTEasy客户端框架身份验证凭据
这不起作用.分析与Wireshark建立的连接我无法看到带有Authorization:Basic的HTTP包.经过更多的研究,我发现了这篇文章http://docs.jboss.org/resteasy/docs/2.3.3.Final/userguide/html/RESTEasy_Client_Framework.html,它描述了如何ApacheHttpClient4Executor
从resteasy中添加基本身份验证.
// Configure HttpClient to authenticate preemptively
// by prepopulating the authentication data cache.
// 1. Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// 2. Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);
// 3. Add AuthCache to the execution context
BasicHttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
// 4. Create client executor and proxy
httpClient = new DefaultHttpClient();
ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(httpClient, localContext);
client = ProxyFactory.create(BookStoreService.class, url, executor);
但这也不起作用.没有描述如何将基本身份验证的用户名和密码附加到构造中.为什么这些信息与任何类没有关联httpcomponent
?