Im trying to reach a XML file behind a secure url. I want to unmarshall the file from a url based on a XSD binding I already have. Here is my method.
public void urlTest(String url){
URLConnection connection = null;
JAXBContext jc;
try {
String userPassword = username + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
URL add = new URL(this.url);
connection = add.openConnection();
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.connect();
jc = JAXBContext.newInstance("XML");
Unmarshaller u = jc.createUnmarshaller();
Object o = u.unmarshal(connection.getURL());
System.out.println("Complete");
} catch (IOException ex) {
Logger.getLogger(UrlDownload.class.getName()).log(Level.SEVERE, null, ex);
} catch (JAXBException ex) {
Logger.getLogger(UrlDownload.class.getName()).log(Level.SEVERE, null, ex);
}
}
I get an 401 server error from this. The username and password I pass are correct. Perhaps I’m missing something.
after quick scan it looks liek you are providing an URL to the unmarshaller, not the connection with Authorization.