wanjidong / jmesa

Automatically exported from code.google.com/p/jmesa
0 stars 0 forks source link

Export to PDF fails in secure pages (HTTPS) #182

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use the export to PDF (ExportType.PDF, Flying Saucer) from a secure page
(https)

What is the expected output? What do you see instead?
The exported pdf. 0 bytes pdf, Exception that the jmesa.css can't be loaded

What version of the product are you using? On what operating system?
jmesa 2.4.1, core-renderer-r8pre2. Windows XP, Firefox, IE, ...

Please provide any additional information below.
I know that this is a xhtmlrenderer issue, but I was wondering if there is
something can be done to solve this problem (but keep using the Flying
Saucer, PDFP doesn't look very well...).
I debugged jmesa and xhtmlrenderer hard to find the exact point where the
problem occurs:

package org.xhtmlrenderer.swing;

public class NaiveUserAgent implements UserAgentCallback, DocumentListener {...
...
    protected InputStream resolveAndOpenStream(String uri) {
        java.io.InputStream is = null;
        uri = resolveURI(uri);
        try {
            is = new URL(uri).openStream();   <---- ERROR
        } catch (java.net.MalformedURLException e) {
            XRLog.exception("bad URL given: " + uri, e);
        } catch (java.io.FileNotFoundException e) {
            XRLog.exception("item at URI " + uri + " not found");
        } catch (java.io.IOException e) {
            XRLog.exception("IO problem for " + uri, e);
        }
        return is;
    }
..
...
This method will fail if the uri of the jmesa css is an https path. Maybe a
possibility would be changing this in jmesa:

package org.jmesa.view.pdf;

public class PdfViewExporter extends AbstractViewExporter {
...
    private String getBaseUrl() {
        return request.getRequestURL().toString();
    }
...
Forcing this base url to be http, for example. But only an idea.
I would appreciate any comment or help. Most of my pages have to be in
https and I would like to use the Flying Saucer export to pdf.

Cheers.
Alex

Original issue reported on code.google.com by AlejaV...@gmail.com on 2 Mar 2009 at 6:42

GoogleCodeExporter commented 8 years ago
Ok, I found out what the problem was. It's not a bug in xhtmlrenderer and 
doesn't
need any change in any code...
The problem is that when the Java web application tries to load the css of 
jmesa to
export as a pdf, it tries to download it using a secure path (https:\\...). For 
this,
the Java default keystore of ssl trusted certificates
(%JAVA_HOME%\jre\lib\security\cacerts) MUST have the certificate of the server 
that
hosts the application. 
Java doesn't ask if you trust the server (even if it's the server running the 
java
app...) like the browser does, it will just throw the exception and tell that 
can't
load the css (some HandShakeSSLException)
So I close my own Issue, ;)
By the way, thanks for the good work and the best "table creator" I've seen.

Cheers from Spain

Original comment by AlejaV...@gmail.com on 3 Mar 2009 at 8:51

GoogleCodeExporter commented 8 years ago
I forgot, if someone has the same problem and is using Tomcat this would help:

If you created your SSL Tomcat certificate like this:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA -validity 3650
then you have it in your OWN keystore (located in a .keystore file in your home
directory, the same in Windows and Unix)
You need it in the java keystore, so you can export it from there and import it 
to
the java keystore like this:
%JAVA_HOME%\jre\lib\security>keytool -export -alias tomcat -file tomcat.crt
%JAVA_HOME%\jre\lib\security>keytool -import -alias tomcat -file tomcat.crt 
-keystore
cacerts

Hope this can help someone,

cheers

Original comment by AlejaV...@gmail.com on 3 Mar 2009 at 8:55

GoogleCodeExporter commented 8 years ago

Original comment by jeff.johnston.mn@gmail.com on 4 Mar 2009 at 8:03

GoogleCodeExporter commented 8 years ago
Is there another way to overcome this issue? I mean setting the jmesa-pdf.css 
in Java
code.

Original comment by duongl...@gmail.com on 1 Apr 2009 at 9:20

GoogleCodeExporter commented 8 years ago
Hi Alex

I have exactly the same problem that you faced.  I am new to the SSL stuff. 

I am rendering a PDF document using xhtmlrender and everything was fine until 
we moved to https.  I am facing the same problem when reading the style sheets 
through https.

I tried out the steps you've given for tomcat (generating a certificate, 
exporting and importing into java).  But the last step fails saying - 
keytool error: java.io.IOException: Keystore was tampered with, or password was 
incorrect

I've given the right password - i tried the pwd i gave while generating the 
certificate, i tried the default 'changeit' but it throws the same error.

Can you help???!!!!

Thanks
Hese.

Original comment by 1024h...@gmail.com on 29 Sep 2010 at 2:42