Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26350

    Hi,

    We need to access a CSS file via HTTPS. I’ve read the threads and have realized that PD4ML does not support this (yet). Will you in the future?

    In the meantime, I am trying to implement the workaround you suggested. I have added the CustomFileResourceProvider class which is below. I have also added:

    <br /> HashMap map = new HashMap();<br /> map.put("pd4ml.extra.resource.loaders", "CustomFileResourceProvider");<br /> pd4ml.setDynamicParams(map);<br />

    After the creation of the pd4ml object. However, I do not understand where or when I need to call getResourceAsBytes. Could you please help me here?

    Thank you.

    Tim

    <br /> public byte[] getResourceAsBytes(String resource) throws IOException {<br /> ByteArrayOutputStream fos = new ByteArrayOutputStream();<br /> byte buffer[] = new byte[2048];<br /> <br /> InputStream is = null;<br /> <br /> PD4MLPrintPDF.so_log.debug("CustomFileResourceProvider - resource:" + resource + "n");<br /> URL src = new URL(resource);<br /> URLConnection urlConnect = src.openConnection();<br /> try {<br /> urlConnect.connect();<br /> } catch (Throwable e) {<br /> return new byte[0];<br /> }<br /> is = urlConnect.getInputStream();<br /> BufferedInputStream bis = new BufferedInputStream(is);<br /> <br /> int read;<br /> do {<br /> read = is.read(buffer, 0, buffer.length);<br /> if (read > 0) { // something to put down<br /> fos.write(buffer, 0, read);<br /> }<br /> } while (read > -1);<br /> <br /> fos.close();<br /> bis.close();<br /> is.close();<br /> <br /> return fos.toByteArray();<br /> }<br />

    #27909

    Nevermind. I’ve got it working.

    #27910

    Glad you got it working!

    Actually PD4ML does support HTTPS, but not in all environments. For example, Weblogic and WebSphere have SSL implementations not derived from the standard Java SSL classes, so they are not compatible with PD4ML.

    #27911

    Actually, i do have a question regarding this class. I’m noticing that the BufferedInputStream is created (bis), but never used. Should bis be used instead of is to read the data?

    Thanks,

    Tim

    Also, note how we modified it to catch and report the exceptions. Let me know if this is still ok, please.

    <br /> public byte[] getResourceAsBytes(String resource, boolean debugOn) throws IOException {<br /> ByteArrayOutputStream fos = new ByteArrayOutputStream();<br /> byte buffer[] = new byte[2048];<br /> <br /> InputStream is = null;<br /> BufferedInputStream bis = null;<br /> <br /> try {<br /> URL src = new URL(resource);<br /> URLConnection urlConnect = src.openConnection();<br /> urlConnect.connect();<br /> is = urlConnect.getInputStream();<br /> bis = new BufferedInputStream(is);<br /> <br /> int read;<br /> do {<br /> read = is.read(buffer, 0, buffer.length);<br /> if (read > 0) {<br /> fos.write(buffer, 0, read);<br /> }<br /> } while (read > -1);<br /> <br /> } catch (Exception e) {<br /> e.printStackTrace();<br /> return new byte[0];<br /> } finally {<br /> fos.close();<br /> bis.close();<br /> is.close();<br /> }<br /> <br /> return fos.toByteArray();<br /> }<br />

    #27912

    It is a copy-paste issue in the sample code.

    The line
    bis = new BufferedInputStream(is);
    may be deleted.

    Your modifications seems to be ok

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.