Java Jax RS无法对代理进行身份验证

Java Jax RS无法对代理进行身份验证,java,jax-rs,resteasy,squid,Java,Jax Rs,Resteasy,Squid,我的公司有代理人 proxy=myProxy port=myProxyPort username=me password=myPassword 我试图通过使用简单的java.net函数来访问外部世界,结果成功了 System.setProperty("http.proxyHost", myProxy); System.setProperty("http.proxyPort", myProxyPort); Authenticator.setDefault(new Authenticator()

我的公司有代理人

proxy=myProxy
port=myProxyPort
username=me
password=myPassword
我试图通过使用简单的java.net函数来访问外部世界,结果成功了

System.setProperty("http.proxyHost", myProxy);
System.setProperty("http.proxyPort", myProxyPort);

Authenticator.setDefault(new Authenticator() {
      protected PasswordAuthentication getPasswordAuthentication() {
        return new
           PasswordAuthentication(me,myPasssword.toCharArray());
    }});

URL u = new URL("http://www.google.com");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
DataInputStream di = new DataInputStream(con.getInputStream());
byte[] b = new byte[1024*512];
while(-1 != di.read(b,0,1024*512)) {
   System.out.print(new String(b));
不是,我尝试使用Jax RS Resteasy实现,如下所示:

Client client = new ResteasyClientBuilder().defaultProxy(myProxy, myProxyPort).build(); 
System.out.println(client.target("https://www.google.com").request().get().readEntity(String.class));
ResteasyClient client = new ResteasyClientBuilder().defaultProxy(myProxy, myProxyPort).build(); 
Credentials credentials = new UsernamePasswordCredentials(me, mypassword);
ApacheHttpClient4Engine engine = (ApacheHttpClient4Engine)client.httpEngine();
HttpContext context =  new BasicHttpContext();
engine.setHttpContext(context);

CredentialsProvider provider = new BasicCredentialsProvider(); 
context.setAttribute(ClientContext.CREDS_PROVIDER, provider);
AuthScope authScope = new AuthScope(
            myProxy,
            myProxyPort,
            null,
            null);
System.out.println(client.target("https://www.google.com").request().get().readEntity(String.class));
我犯了以下错误

Cache Access Denied
ERR_CACHE_ACCESS_DENIED
(squid/3.1.6)
Sorry, you are not currently allowed to request https://www.google.com/* from this cache until you have authenticated yourself

有人能告诉我如何使用Jax-RS使用用户名密码对代理进行身份验证吗?哇,这个问题真让我抓狂。我不知道如何以独立于实现的方式解决它。不管怎样,到现在为止,它是这样工作的:

Client client = new ResteasyClientBuilder().defaultProxy(myProxy, myProxyPort).build(); 
System.out.println(client.target("https://www.google.com").request().get().readEntity(String.class));
ResteasyClient client = new ResteasyClientBuilder().defaultProxy(myProxy, myProxyPort).build(); 
Credentials credentials = new UsernamePasswordCredentials(me, mypassword);
ApacheHttpClient4Engine engine = (ApacheHttpClient4Engine)client.httpEngine();
HttpContext context =  new BasicHttpContext();
engine.setHttpContext(context);

CredentialsProvider provider = new BasicCredentialsProvider(); 
context.setAttribute(ClientContext.CREDS_PROVIDER, provider);
AuthScope authScope = new AuthScope(
            myProxy,
            myProxyPort,
            null,
            null);
System.out.println(client.target("https://www.google.com").request().get().readEntity(String.class));

最简单的方法不是使用默认的底层Apache引擎,而是设置标准Java URL连接:

resteasyClientBuilder.httpEngine(new URLConnectionEngine());
client = resteasyClientBuilder.build();
如果是这样,所有http.proxyXXX系统属性都将工作,避免对任何凭据提供程序进行编码