2017-12-01 5 views
0

Grails로 프로그래밍 된 웹 앱에서 작업하고 있습니다. 특정 보고서를 표시하는 데 사용되는 페이지가 있으며이 보고서에는 첨부 파일이 포함될 수 있습니다. 첨부 파일은 documentum에 저장되며 현재 사용자가 첨부 파일을 클릭하면 첨부 파일이 저장된 문서 위치의 링크 일 뿐이며 사용자에게 자격 증명을 입력하라는 메시지를 표시합니다. 내 응용 프로그램은 구성 파일에 저장된 문서 자격 증명을 가지고 있으므로 사용자가 자신의 자격 증명을 입력하도록 강요하는 대신 이러한 속성을 사용하려고합니다. RESTful 서비스를 사용하여 링크를 검색하지만 링크를 사용하여 사용자 컴퓨터에 직접 다운로드하는 방법을 찾고 있습니다.Grails에서 인증을 요청하지 않고 URL에서 콘텐츠를 다운로드 중

private def getFileInfo(def id, def subject) { 
    // product show view needs the following four lists to display the document information correctly 
    def ATRReportInstance = ATRReport.findByTrackingNumber(id) 
    def linkList = [] 
    def nameList = [] 
    def formatList = [] 
    def idList = [] 
    // open up a connection to the documentum server 
    def doc = connectToDocumentum() 

    if (!doc) return 
    def rest = doc.rest 
    def response = doc.response 
    if (response.status == 200) { 
    // retrieve the folder for this product (the name of this folder is the product's ID) 
    def rObjectId = rest.get(documentumServer + "/repositories/" + documentumfilestore + "?dql=select r_object_id from dm_folder where any r_folder_path='" + atrreportfolderpath + "/" + id + "'") { 
     auth authuser, authpass 
    } 
    // get the folder's ID from the folder object retrieved above 
    def folderObjectID 
    rObjectId.json.entries.each { 
     entry - > 
     folderObjectID = entry.content.properties.r_object_id 
    } 
    // get all of the documents in the product's MSDS folder using the folder ID retrieved above 
    def resp = rest.get(documentumServer + "/repositories/" + documentumfilestore + "?dql=select r_object_id, object_name, a_content_type, subject from cbs_document where any i_folder_id= '" + folderObjectID + "'") { 
     auth authuser, authpass 
    } 
    // cycle through the documents above to populate the four MSDS document information lists 
    def x = 0 
    resp.json.entries.each { 
     entry - > 
     if (entry.content.properties.subject == subject) { 
      // get the document's content object from the document's ID 
      def content = rest.get(documentumServer + "/repositories/" + documentumfilestore + "/objects/" + entry.content.properties.r_object_id + "/contents/content" + "?media-url-policy=local") { 
      auth authuser, authpass 
      } 
      if (entry.content.properties.r_object_id != null && ATRReportInstance.inactiveFiles != null && ATRReportInstance.inactiveFiles.contains(entry.content.properties.r_object_id.toString())) {} else { 
      linkList[x] = getLink(content.json.links, "enclosure") 
      if (linkList[x].contains("format=msg")) 
       linkList[x] = linkList[x].toString().substring(0, linkList[x].toString().indexOf("content-media")) + "content-media.msg" 

      formatList[x] = entry.content.properties.a_content_type 
      nameList[x] = entry.content.properties.object_name 
      idList[x] = entry.content.properties.r_object_id 
      x++ 
      } 
     } 
    } 
    return [linkList: linkList, nameList: nameList, formatList: formatList, idList: idList] 
    } else { 
    // return null if documentum is unavailable 
    flash.message = message(code: 'error.documentum.unavailable') 
    return null 
    } 
} 

나는 URL에 걸릴 작동 할 수 있습니다 사용자에게 문서를 다운로드 할 수있는 또 다른 기능을 쓰고 생각하고 있어요,하지만 난 Grails를 내 해당 문서를 검색하는 방법을 알아낼 수 없습니다.

답변

0

다음은 구현 된 솔루션입니다. 구성 파일에있는 인증 자격 증명을 사용하여 문서에서 파일을 다운로드하는 방법입니다.

def exportAttachment() { 
 
    //uses parameters from gsp file 
 
    def url = params.url 
 
    def name = params.name 
 
    def format = params.format 
 
    def extension 
 

 
    //find proper extension 
 
    for (s in documentumExtMap) { 
 
    if (s.value.equals(format)) { 
 
     extension = s.key 
 
    } 
 
    } 
 

 
    def connection = new URL(url).openConnection() 
 
    def remoteAuth = "Basic " + "${authuser}:${authpass}".bytes.encodeBase64() 
 
    connection.setRequestProperty("Authorization", remoteAuth) 
 

 
    def dataStream = connection.inputStream 
 

 
    response.setContentType("application/octet-stream") 
 
    response.setHeader('Content-disposition', 'Attachment; filename=' + name + '.' + extension) 
 
    response.outputStream << dataStream 
 
    response.outputStream.flush() 
 
}

방법은 세 가지 매개 변수가 있습니다 URL, 이름, 형식을.

URL은 documentum에있는 파일의 위치입니다.

이름

형식 다운로드되는 파일의 유형입니다 다운로드 클라이언트 측의 이름입니다. 필자의 경우, 필자는이 파일을 사용하여 파일에 필요한 적절한 확장자를 얻어야했습니다.

0

로그인을 생략하려면 SSO 솔루션을 설치하거나 (DCTM의 경우 약간의 작업이 필요함) 제안 된대로 기능을 수행하십시오. 그러나이를 수행 할 때는 라이센스 조항을 고려해야합니다.

관련 문제