Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services RESTEasy客户端代理抢占式基本身份验证_Web Services_Http_Rest_Authentication_Resteasy - Fatal编程技术网

Web services RESTEasy客户端代理抢占式基本身份验证

Web services RESTEasy客户端代理抢占式基本身份验证,web-services,http,rest,authentication,resteasy,Web Services,Http,Rest,Authentication,Resteasy,我正在使用RESTEasy代理框架调用我的Rest服务。我想在代理框架中使用抢占式身份验证 这是我目前的代码: public void callSomeService() throws Exception { RegisterBuiltin.register(ResteasyProviderFactory.getInstance()); DefaultHttpClient client = new DefaultHttpClient(); UsernamePasswo

我正在使用
RESTEasy代理框架
调用我的Rest服务。我想在代理框架中使用抢占式身份验证

这是我目前的代码:

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服务会被调用两次:

  • 首先,客户端收到401错误(未经授权)
  • 在第二个请求中,添加了授权头,一切正常 好的
  • 我真正想做的是,授权头已经添加到第一个请求中!我该怎么做?

    我正在使用RESTEasy 2.3.5!我还阅读了文档(),其中给出了一个抢占式身份验证的示例,由于以下代码,它实际上不起作用:

    BasicScheme basicAuth = new BasicScheme();
    authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);
    

    没错,文档中的示例没有编译。尝试将字符串“com.bluemonkeydmond.sippycups”替换为HttpHost的实例。HttpHost类有几个构造函数,因此请务必查看JavaDocs。最简单的构造函数采用字符串。比如说,

    BasicScheme basicAuth = new BasicScheme();
    authCache.put(new HttpHost("com.bluemonkeydiamond.sippycups"), basicAuth);