Forum Stats

  • 3,733,039 Users
  • 2,246,686 Discussions
  • 7,856,490 Comments

Discussions

Accessing Issue in Files from Customer/Scratch in jcs-sx

3200663
3200663 Member Posts: 170
edited April 2018 in Java Cloud Service

Hi

Jdev-11.1.9

Jcs-SX

I have an requirement where i need to make a pdf document to have a preview inside adf using inlineframe .

I have followed the below link and it works fine when my file is in local system

https://technology.amis.nl/2011/07/28/adf-11g-show-pdf-in-a-popup/

The same when i try in JCS-SX here are the following steps i follow

1)I put a file asd.pdf in /customer/scratch path of jcs-sx server

2)able to read the file length, checked if (!file.exists()) it doesnt go into this loop

3)if i give a wrong file like adddd.pdf it gives filenot found and goes inside the if (!file.exists())

4)when i hit the below servlet url

local system

http://127.0.0.1:7101/Application4-ViewController-context-root/showppf?name=asd.pdf

resp:Pdf file is displayed in browser

In JCS_SX

https://java1-****.java.em2.oraclecloudapps.com/Application4-ViewController-context-root/showppf?name=asd.pdf

resp:In Log no errors able to get same file length,bytes of what i get when i hit locally

In JCS_SX(wrong file)

https://java1-****.java.em2.oraclecloudapps.com/Application4-ViewController-context-root/showppf?name=adssssss.pdf

resp:filenot exists

Please find the Servlet code

Header 1

public class showppf extends HttpServlet {

    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";

     private static final int DEFAULT_BUFFER_SIZE = 10240; // 10KB.

     private String filePath;

     public void init(ServletConfig config) throws ServletException {

       super.init(config);

     }

     public void doGet(HttpServletRequest request,

                       HttpServletResponse response) throws ServletException,

                                                            IOException {

       // Get requested file by path info.

       String requestedFile = request.getParameter("name");

System.out.println("server"+requestedFile);

       // Check if file is actually supplied to the request URI.

       if (requestedFile == null) {

         response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.

         return;

       }

       // I want to invoke a pdf that is located on the machine where the application is running

       this.filePath ="/customer/scratch";

      //this.filePath =

         // "C:\\JDeveloper\\mywork\\Application4\\ViewController\\public_html\\WEB-INF\\pdf-docs";

       // Decode the file name (might contain spaces and on) and prepare file object.

       File file = new File(filePath, URLDecoder.decode(requestedFile, "UTF-8"));

       // Check if file actually exists in filesystem.

       if (!file.exists()) {

           System.out.println("File not exsit XXXXXXXXXXXXX");

         response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.

         return;

       }

       // Get content type by filename.

       String contentType = getServletContext().getMimeType(file.getName());

System.out.println("FROM SERVLET"+contentType);

       // If content type is unknown, then set the default value.

       // For all content types, see: http://www.w3schools.com/media/media_mimeref.asp

       // To add new content types, add new mime-mapping entry in web.xml.

       if (contentType == null) {

         contentType = "application/octet-stream";

       }

       // Init servlet response.

       response.reset();

       response.setBufferSize(DEFAULT_BUFFER_SIZE);

       response.setContentType(contentType);

       System.out.println("---"+file.length());

    

       response.setHeader("Content-Length", String.valueOf(file.length()));

       response.setHeader("Content-Disposition",

                          "filename=\"" + file.getName() + "\"");

       // Prepare streams.

       BufferedInputStream input = null;

       BufferedOutputStream output = null;

       try {

         // Open streams.

         input =

             new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);

           System.out.println("input"+input);

         output =

             new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);

           System.out.println("outputServlet"+output);

         // Write file contents to response.

         byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

         int length;

         while ((length = input.read(buffer)) > 0)

         {

           output.write(buffer, 0, length);

           System.out.println("while outputServlet"+output);

       

         }

       } finally {

         // Gently close streams.

         close(output);

         close(input);

       }

     }

My JSF Small snippet

<af:inlineFrame id="if1" shortDesc="This is an inline frame"

                      source="/showppf?name=#{backingBeanScope.Test.pdfUrl}"

                      styleClass="AFStretchWidth" inlineStyle="height:600px;"></af:inlineFrame>

   

Thanks,

Vikram

Tagged:

Answers

This discussion has been closed.