Capture current JSF page content

后端 未结 4 1553
孤城傲影
孤城傲影 2021-01-25 05:37

I want to capture the current page and send it to an application that converts it to pdf.

This is what I am using:

FacesContext facesContext=FacesContext         


        
相关标签:
4条回答
  • 2021-01-25 05:44

    Just request the page in the same HTTP session as the current request. If your webapp supports URL rewriting (as by default), then just append session ID as jsessionid path fragment:

    String sessionId = ((HttpSession) externalContext.getSession()).getId();
    InputStream input = new URL("http://localhost:8080/context/page.jsf;jsessionid=" + sessionId).openStream();
    // ...
    

    Or if your webapp doesn't accept URL rewriting, but accepts cookies only, then set it as a request cookie the usual way:

    URLConnection connection = new URL("http://localhost:8080/context/page.jsf").openConnection();
    connection.setRequestProperty("Cookie", "JSESSIONID=" + sessionId);
    InputStream input = connection.getInputStream();
    // ...
    

    Note that I removed setDoOutput() since you don't seem to be interested in performing a POST request.

    0 讨论(0)
  • 2021-01-25 05:54

    Yes of course there is. You are sending this content, so you have it. You should store the Content Object. If you dont have it, inspect your byte streams. The content should be there ;)

    0 讨论(0)
  • 2021-01-25 05:55

    There of couple of websites which allow you to convert the entire page to pdf and save it as .pdf file. Try out the site http://pdfcrowd.com/ Hope this helps you.

    0 讨论(0)
  • 2021-01-25 06:08

    I do not know how to capture the page's content using the current user's session, but I can suggest another way to do it - you could move the pdf conversion logic inside a Selenium test-case and use the test-case to navigate and login to the page requiring authentication. After the automated tc has logged in, you could call your pdf conversion logic...?

    0 讨论(0)
提交回复
热议问题