Details
-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
None
-
linux
Description
I am trying to get the excelsheet file's content in my java, But got 401 .
let me show you step by step.
1、ceate a page
2、use the properity "modelClass" in page's yaml file in order to make my java work
3、use the page properities to set the file which uploaded in asset
3、in my java file, the code to get the excelsheet file's content is
String sourceID = this.content.getProperty("sourceFile").getString();
Node source = MgnlContext.getJCRSession("dam")
.getNodeByIdentifier(sourceID.substring(4));
this.IMPORT_FILE = LinkUtil.createExternalLink(source);
InputStream inputStream = null;
if (this.IMPORT_FILE.startsWith("http")){URL url = new URL(this.IMPORT_FILE);
inputStream = url.openStream();//got 401//but I use this code , it work.
/*URL url = new URL(this.IMPORT_FILE);
URLConnection connection = url.openConnection();
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userPassword = MgnlContext.getUser().getName() + ":" + MgnlContext.getUser().getName();
String encodedAuthorization = enc.encode( userPassword.getBytes() );
connection.setRequestProperty("Authorization", "Basic "+
encodedAuthorization);
inputStream = connection.getInputStream();*/
}
else {
File file = new File(this.IMPORT_FILE);
inputStream = new FileInputStream(file);
}
when I try to use “url.openStream() “ to get the content, it get wrong;