0

I use PrimeFaces and need to deliver a dynamic file content (image or PDF), which is read from the file system and is not cashed - neither on the server nor on the file system. I also need to access the HttpSession, as it contains information on which folders the user is entitled to see.

I have the following options:

1.) Up to know I was using the imlementation of BalusC for rendering dynamic image with PrimeFaces:

https://stackoverflow.com/a/12452144/1925356

2.) There is also the option of using PrimeFaces Extensions:

https://www.primefaces.org/showcase-ext/sections/documentviewer/basic.jsf

3.) Finally, one could always write an own HttpServlet and let it read the binary file from the file system and deliver it back to the client.

In all the cases above I could request the HttpSession session, for example in (1) and (2) like this:

(( HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getSession(false)

in the body of the method, which delivers the StreamedContent - and decide whether to return the StreamedContent representing the file or just an "empty" StreamedContent.

I.) Am I wright for cases (1) and (2)

II.) Which of the above approaches (1), (2), (3) is best in terms of performance ?

Alex Mi
  • 926
  • 2
  • 8
  • 25
  • 1
    I: No. Start by looking at the implementations and not just the scope. Does the imange need to be cached on the client? How long? Do you need control over it? How big is the image? – Kukeltje Jun 05 '20 at 15:41
  • 1
    1) uses an application scoped bean but for each request it does a threadsafe(?) call to a service to retrieve things. Is this bad? Don't know, could be caching in the service that makes it perform great... Could be a bad implementation that makes it crash your server with an OOM. – Kukeltje Jun 05 '20 at 15:42
  • 1
    2) has three different implementations all from a sessionscoped bean. Is the implementaion IN the bean good? Don't know? URL could be via a servlet that retrieves it from google, Resource can be from a database via a resource resolver, and the streamed content is generated on each request. Is that needed? Don't know, depends on your usecase. – Kukeltje Jun 05 '20 at 15:43
  • 1
    3) Can be bad performance as well. Maybe you can cache it? Maybe the Filesystem caches it. Can there be changes that need to be detected? – Kukeltje Jun 05 '20 at 15:44
  • @Kukeltje thanks for your remarks. Sure the caching matters, as well as the location of the file delivered (file system, database, external URL). That is why I adjusted and simplified my question and kindly ask you for your opinion) – Alex Mi Jun 07 '20 at 07:22
  • Opnionated questions sort of do not belong in stackoverflow. Want to know performance differences? Try... profile... And there is (in my opinion) currently too much in this question. Focus... due to there being less focus, it costs too much time finding out what you changed. – Kukeltje Jun 07 '20 at 07:31
  • @Kukeltje I once again narrowed my question. I would prefer to know what is the difference first, and eventually, on a later stage, use a profiling. – Alex Mi Jun 07 '20 at 07:55
  • @Kukeltje by performance I also mean accounting for JSF specific stages of rendering the response, like this: if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); } I have no way to perform this in a HttpServlet, right? But then it depends HOW the resurce is being refered (i.e. in an iframe or in a PirmeFaces component such as ???! – Alex Mi Jun 07 '20 at 08:02
  • In your first link, read the blog at the end. I suspect lots is answered there. – Kukeltje Jun 07 '20 at 08:38
  • and 2 has a completely different purpose... it is pure PDF viewer based. https://www.primefaces.org/showcase-ext/views/documentViewer.jsf – Kukeltje Jun 07 '20 at 10:16
  • @Kukeltje great, thank you! – Alex Mi Jun 07 '20 at 10:52

0 Answers0