Authentication error in weblogic portal 10.2 (Response: '401: Unauthorized'
681171May 4 2010 — edited May 4 2010I have written following code in my page flow controller in order to access file from a shared location:
Authenticator.setDefault(new MyAuthenticator(username, password));
URLConnection conn = new URL(urlString).openConnection();
InputStream instr = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(instr));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
It always gives me folloing error:
java.io.FileNotFoundException: Response: '401: Unauthorized' for url: 'http://coldev01.col.us.bic/testspec/library/Approved/Packaging%20Components/5647495.pdf'
at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:476)
at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:36)
If I directly past this url in browser then this pdf opens properly but when i try to do through code then it does not work. Any quick help would be highly appreciated.
MyAuthenticator class
private static class MyAuthenticator extends Authenticator {
private String username, password;
public MyAuthenticator(String user, String pass) {
username = user;
password = pass;
}
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println("Requesting Host : " + getRequestingHost());
System.out.println("Requesting Port : " + getRequestingPort());
System.out.println("Requesting Prompt : " + getRequestingPrompt());
System.out.println("Requesting Protocol: "
+ getRequestingProtocol());
System.out.println("Requesting Scheme : " + getRequestingScheme());
System.out.println("Requesting Site : " + getRequestingSite());
return new PasswordAuthentication(username, password.toCharArray());
}
}
}
Thanks,
Alka