2014-01-21 3 views
1

저는 초보자이며 심볼 링크를 사용하여 Jboss EAP 6.0의 정적 콘텐트 액세스에 대한 지침을 찾아 봅니다. 검색하는 동안 Jboss 5/6에 대한 솔루션을 찾았지만 EAP 버전과 매핑 할 수 없었습니다.Jboss EAP 6.0의 정적 콘텐트 액세스

Google Apps 서버에는 1000 개 이상의 PDF가 있으며 웹 응용 프로그램을 통해 액세스합니다. EAP 6.0에서 배포 된 ear/war 내에 심볼릭 링크를 만들 때 웹 브라우저에서 PDF에 액세스 할 수 없습니다.

누구든지 이전에이 작업을 수행했거나 EAP에있을 수있는 방법에 대한 제안 사항이 있으면 알려 주시기 바랍니다.

감사합니다.

답변

0

짧은 대답 : 해당 파일을 가져올 위치를 알고 서 전달할 수있는 서블릿을 만듭니다.

더 긴 버전/설명 :

는 서블릿을 작성 가령에 매핑 /yourapp/pdfs/* : 위의 코드는 일부 조정을 beed 수 있지만 일반적으로이 솔루션을 설명

@WebServlet("/pdfs/*") 
public class PdfServlet extends HttpServlet 
{ 
    public void doGet(HttpServletRequest req, HttpServletResponse res) { 
     String basePath = getServletContext().getInitParameter("basePath"); 
     File f = new File(basePath + File.separator + req.getPathInfo()); 
     ///////////////////////////////////////////////////////////////////// 
     //// BIG WARNING:            //// 
     //// Normalize the path of the file and check if the user can //// 
     //// legitimately access it, or you created a BIG security  //// 
     //// hole! If possible enhance it with system-level security, //// 
     //// i.e. the user running the application server can access //// 
     //// files only in the basePath and application server dirs. //// 
     ///////////////////////////////////////////////////////////////////// 
     if(f.exists()) { 
      OutputStream out = res.getOutputStream(); 
      // also set response headers for correct content type 
      // or even cache headers, if you so desire 
      byte[] buf = new byte[1024]; 
      int r; 
      try(FileInputStream fis = new FileInputStream(f)) { 
       while((r=fis.read(buf)) >= 0) { 
        out.write(buf, 0, r); 
       } 
      } 
     } 
     else res.sendError(HttpServletResponse.SC_NOT_FOUND); 
    } 
} 

...

지금 web.xml에서 컨텍스트 초기화 파라미터 지정

<context-param> 
    <param-name>basePath</param-name> 
    <param-value>/the/path/to/the/pdfs</param-value> 
</context-param>