[MGNLDAMEXT-38] the http code is 401 when I use url.openStream for getting file from Asset Created: 31/Mar/17  Updated: 05/Apr/17  Resolved: 05/Apr/17

Status: Closed
Project: DAM Extensions
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Ivy Cen Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: excelsheet, steam
Remaining Estimate: 3d
Time Spent: Not Specified
Original Estimate: 3d
Environment:

linux


Attachments: PNG File QQ图片20170331134606.png     PNG File screenshot-1.png     PNG File screenshot-2.png    
Issue Links:
Relates
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 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;


Generated at Mon Feb 12 00:40:58 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.