Uploaded image for project: 'DAM Extensions'
  1. DAM Extensions
  2. MGNLDAMEXT-38

the http code is 401 when I use url.openStream for getting file from Asset

    XMLWordPrintable

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;

      Checklists

        Acceptance criteria

        Attachments

          1. QQ图片20170331134606.png
            QQ图片20170331134606.png
            26 kB
          2. screenshot-1.png
            screenshot-1.png
            43 kB
          3. screenshot-2.png
            screenshot-2.png
            29 kB

          Activity

            People

              Unassigned Unassigned
              icen Ivy Cen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Bug DoR
                  Task DoD

                  Time Tracking

                    Estimated:
                    Original Estimate - 3d
                    3d
                    Remaining:
                    Remaining Estimate - 3d
                    3d
                    Logged:
                    Time Spent - Not Specified
                    Not Specified