我们正在通过代理设置通过Weblogic服务器(node1 / node2)上的java独立示例代码来调用URL。该代码在节点1上工作正常,但相同的代码在node2服务器上不工作。我们已经检查了代理设置和凭据都很好,但是仍然出现以下错误:
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at ProxyCode.start2(ProxyCode.java:54)
at ProxyCode.main(ProxyCode.java:23)
Exception in thread "Main Thread" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at ProxyCode.readFromInputStream(ProxyCode.java:65)
at ProxyCode.start2(ProxyCode.java:59)
at ProxyCode.main(ProxyCode.java:22)
[另外,请在下面找到我的代码段:SimpleAuthenticator.java
import java.net.Authenticator;导入java.net.PasswordAuthentication;
public class SimpleAuthenticator extends Authenticator
{
private String username;
private String password;
public SimpleAuthenticator(String username,String password)
{
this.username = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(
username,password.toCharArray());
}
}
主类:
String url = "http://www.oracle.com/technetwork/java/readme-2-149793.txt";
String proxy = "proxyserver";
String port = "8080";
String username = "username";
String password = "password";
Authenticator.setDefault(new SimpleAuthenticator(username,password));
URL server = null;
try {
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
server = new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", proxy);
systemProperties.setProperty("http.proxyPort", port);
InputStream in = null;
URLConnection connection = null;
try {
connection = (URLConnection) server.openConnection();
connection.connect();
in = connection.getInputStream();
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println(readFromInputStream(in));
}
public static String readFromInputStream(InputStream in) {
StringBuffer strBuf = new StringBuffer();
char ac[];
BufferedReader buf = new BufferedReader(new InputStreamReader(in));
try
{
while (buf.ready()) {
ac = new char[10000];
buf.read(ac);
strBuf.append(ac);
}
buf.close();
}
catch (IOException e) {
e.printStackTrace();
}
我们从现在开始就陷入困境,几个月来一直无法获得任何有用的信息。请帮助。谢谢
如果您提供错误的凭据(用户名或密码),则会出现此错误。这是基于Glassfish的网络应用程序发生的。我当时期待401回应。
我认为,身份验证器会多次尝试相同的凭据。