Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was able to do this with calling a Java routine from the adapter to call the back-end service that returns the PDF as a <code>byte[]</code>. Once the <code>byte[]</code> is retrieved I <code>base64</code> encode it in the Java routine, URI encode it in the adapter, then do the reverse in the client js code. The Java code uses the Apache <code>HttpClient</code>. I tried the plain return type as well as others with no luck.</p> <p><a href="http://www.samnunnally.com/?p=41" rel="nofollow" title="Java code example">Java example here</a> </p> <p>Adapter code:</p> <pre><code>var service = new ServiceClient(); var pdf = service.getUnsecureContentBase64(url); result.pdf = encodeURIComponent(pdf); return result; </code></pre> <p>Client code:</p> <pre><code>onSuccess : function (response){ var pdfText = decodeURIComponent(response.invocationResult.pdf); var pdf = base64DecToArr(pdfText); //use pdf byte[] to pass to Mozilla pdf.js var pdfText = decodeURIComponent(response.invocationResult.pdf); var pdf = base64DecToArr(pdfText); PDFJS.disableWorker = false; PDFJS.getDocument(pdf).then(function (pdfDoc) { //use pdfDoc to render }); } </code></pre> <p>Java code:</p> <pre><code>public class ServiceClient { public String getUnsecureContentBase64(String url) throws ClientProtocolException, IOException { byte[] result = getUnsecureContent(url); return Base64.encodeBase64String(result); } public byte[] getUnsecureContent(String url) throws ClientProtocolException, IOException { byte[] result = null; CloseableHttpClient httpclient = null; try { httpclient = HttpClientBuilder.create() .setRedirectStrategy(new LaxRedirectStrategy()).build(); HttpGet httpget = new HttpGet(url); // Create a response handler ResponseHandler&lt;byte[]&gt; handler = new ResponseHandler&lt;byte[]&gt;() { public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toByteArray(entity); } else { return null; } } }; result = httpclient.execute(httpget, handler); } finally { if (httpclient != null) { httpclient.close(); } } return result; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload