Exception on https resources in PDF Extension with classic rendering

OS: Linux 4.14.281-212.502.amzn2.aarch64 (also x86_64)
Java Version: OpenJDK Runtime Environment Corretto-11.0.15.9.1 (build 11.0.15+9-LTS)
Tomcat Version: 9.0.58-1 (with and without Tomcat native)
Lucee Version: 5.3.9.141 (also 5.3.8.206)
PDF Extension: 1.1.0.7 (also 1.0.0.80 and 1.1.0.15-SNAPSHOT)

When using <cfdocument type="classic">, the rendering process encounters java.lang.ClassCastException: class sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to class com.sun.net.ssl.HttpsURLConnection whenever an external image is included in the document. I encountered this for the first time when upgrading a legacy component to Lucee 5.3 on an EC2 instance running Amazon Linux. I’ve tried numerous variations with older (and newer versions of Lucee and the PDF extension). I’ve also tested on Intel and ARM processors, and I’ve disabled Tomcat Native to determine whether OpenSSL bindings were part of the issue.

In a somewhat strange twist, I can run a virtually identical configuration locally in Docker without any issues. In this case, the only notable difference would be the Linux Kernel version (Docker on my Mac is running a Linux 5 kernel).

I did find one bit of evidence that this is not unique to me: java.lang.ClassCastException: class sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to class com.sun.net.ssl.HttpsURLConnection - Stack Overflow. This issue noted that the error came from pd4ml and was resolved by updating the version. Based on stack traces (see below), I suspect this could be the same issue.

We’re examining the level of effort to move to the modern rendering engine, though it may be substantial due to very different behavior with headers / footers (now rendered in margins instead of outside of margins). Any assistance with this would be much appreciated!

Stack Trace:

BlockElement(body) {margin-left=8, display=block, font-size=16, font-family=Serif, line-height=scale (1.2000000476837158), margin-top=8, margin-bottom=8, margin-right=8}
java.lang.ClassCastException: class sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to class com.sun.net.ssl.HttpsURLConnection (sun.net.www.protocol.https.Http
sURLConnectionImpl and com.sun.net.ssl.HttpsURLConnection are in module java.base of loader 'bootstrap')
at org.zefer.cache.d.getResourceAsBytes(Unknown Source)
at org.zefer.cache.ResourceCache.getObject(Unknown Source)
at org.zefer.cache.ResourceCache.getObject(Unknown Source)
at org.zefer.cache.ResourceCache.getImage(Unknown Source)
at org.zefer.html.doc.p.nullvoid(Unknown Source)
at org.zefer.html.doc.p.o?0000(Unknown Source)
at org.zefer.html.doc.p.?00000(Unknown Source)
at org.zefer.html.doc.view.b.o00000(Unknown Source)
at org.zefer.html.doc.db.o00000(Unknown Source)
at org.zefer.html.doc.view.d.o00000(Unknown Source)
at org.zefer.html.doc.db.o00000(Unknown Source)
at org.zefer.html.doc.Document.layout(Unknown Source)
at org.zefer.pd4ml.PD4ML.o00000(Unknown Source)
at org.zefer.pd4ml.PD4ML.o00000(Unknown Source)
at org.zefer.pd4ml.PD4ML.render(Unknown Source)
at org.zefer.pd4ml.PD4ML.render(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.lucee.extension.pdf.pd4ml.PDFByReflection.invoke(PDFByReflection.java:227)
at org.lucee.extension.pdf.pd4ml.PDFByReflection.render(PDFByReflection.java:199)
at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.content(PD4MLPDFDocument.java:132)
at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument._render(PD4MLPDFDocument.java:105)
at org.lucee.extension.pdf.PDFDocument.render(PDFDocument.java:360)
at org.lucee.extension.pdf.tag.Document.renderInital(Document.java:830)
at org.lucee.extension.pdf.tag.Document._doAfterBody(Document.java:728)
at org.lucee.extension.pdf.tag.Document.doAfterBody(Document.java:680)
at _public.subsystems.record.views.print.export_cfm$cf.call(/public/subsystems/record/views/print/export.cfm:308)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1043)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:935)
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:916)
at fw1.framework.one_cfc$cf.udfCallc(/libs/fw1/framework/one.cfc:1928)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350)
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:786)
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1762)
at fw1.framework.one_cfc$cf.udfCall6(/libs/fw1/framework/one.cfc:913)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350)
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:697)
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:585)
at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1932)
at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:444)
at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:218)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2475)
at org.lucee.extension.pdf.pd4ml.PDFByReflection.render(PDFByReflection.java:199)
at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument.content(PD4MLPDFDocument.java:132)
at org.lucee.extension.pdf.pd4ml.PD4MLPDFDocument._render(PD4MLPDFDocument.java:105)
at org.lucee.extension.pdf.PDFDocument.render(PDFDocument.java:360)
at org.lucee.extension.pdf.tag.Document.renderInital(Document.java:830)
at org.lucee.extension.pdf.tag.Document._doAfterBody(Document.java:728)
at org.lucee.extension.pdf.tag.Document.doAfterBody(Document.java:680)
at _public.subsystems.record.views.print.export_cfm$cf.call(/public/subsystems/record/views/print/export.cfm:308)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1043)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:935)
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:916)
at fw1.framework.one_cfc$cf.udfCallc(/libs/fw1/framework/one.cfc:1928)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350)
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:786)
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1762)
at fw1.framework.one_cfc$cf.udfCall6(/libs/fw1/framework/one.cfc:913)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:935)
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:916)
at fw1.framework.one_cfc$cf.udfCallc(/libs/fw1/framework/one.cfc:1928)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350)
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:786)
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1762)
at fw1.framework.one_cfc$cf.udfCall6(/libs/fw1/framework/one.cfc:913)
at fw1.framework.one_cfc$cf.udfCall(/libs/fw1/framework/one.cfc)
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:350)
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:697)
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:585)
at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1932)
at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:444)
at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:218)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2475)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2465)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2436)
at lucee.runtime.engine.Request.exe(Request.java:45)
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1198)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1144)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:183)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:769)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1735)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)

@cjc Ticket for this issue in Jira: LDEV-3583 Generate PDF with Image from s3 not show up in JDK 11
Yes, as you mentioned it’s an issue in the PD4ML.
classic engine with HTTPS resources would work in java 8.

Can you please provide some more details (like test code, pdf produced by classic & modern engines) about the margin issue you faced in the PDF modern engine?

Thank you for your response and for the link to the ticket! I will be keeping an eye on it. Also, bookmarking Jira so that I can search for other issues.

Took me a bit, but I stripped down a page to create an example. There are definitely issues from an HTML standpoint here, but this was “good enough” under the classic engine.

Notice in test-classic.pdf, that the logo is displayed below the page margin and that page content moves down to make room. With test-modern.pdf, the logo is squeezed in and overflows the page margin. The remaining content starts immediately after the true margin so that the two sections overlap. There’s a similar issue with the footer. In classic, the bottom of the footer aligns with the top of the lower margin. In modern, the top of the footer aligns with the top of the lower margin.

These issues would be relatively easy to fix for one or two pages, but there are quite a few throughout the application. I understand that this works in Java 8, but since that also requires downgrading several other dependencies, it’s not an ideal scenario either.

<CFDocument format="PDF" marginleft=.25 marginright=.25 margintop=.1 marginbottom=.1 localURL="yes">
    <cfoutput>
        <cfdocumentitem type="header">
            <div align="center">
            <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width="300"/>
            </div>
            <h3 style="text-align:center">HEADER</h3>

        </cfdocumentitem>


                    <cfdocumentitem type="footer">
                        <p align="center" style="padding-top: 20px;"><font face="arial" size="-2" color="grey">footer stuff&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <div style="margin-top:8px;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</div>
                            </font>
                        </p>
                    </cfdocumentitem>
        <html>
            <head>
                <title>Title</title>
                <style>body{font-size:8pt}</style>
            </head>
            <body>
                <!--- Cover Sheet --->
                <div style="text-align:center;position: relative;left:-5px; margin-left:auto; margin-right:auto;">
                    <br/><br/><br/>
                    <h2>Stuff</h2>
                    <br/><br/><br/><br/><br/><br/>
                    <p>More stuff</p>
                </div>
                <cfdocumentitem type="pagebreak" />

                <h3>Section Heading</h3>

                <cfloop from="1" to="5" index="i">
                    <h4>Some Other Heading</h4>
                    <p>Lorem Ipsum Blah Blah ...</p>
                    <cfdocumentitem type="pagebreak" />

                </cfloop>
                        </body>
                </html>
        </cfoutput>
</CFDocument>

test-classic.pdf (23.2 KB)
test-modern.pdf (20.7 KB)