You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Justin Robinson <of...@fluidnotions.com> on 2015/08/07 14:58:29 UTC

Integrating Google Cloud Print - Issues with dynamic pdf generation download temp file via request that requires auth

I've just written an ofbiz component for integration with google cloud
print api.

A requirement was the printing of reports without requiring the user to
download locally. Also easy inclusion of print buttons (via ftl/html) in
any other component.

Since the reports are dynamically generated and I needed to parse a byte
array to gcp api, I need the component to trigger the report download
programitically.

I included a data attribute in the button with the url (usually a form post
request that usually results in the pdf being downloaded) the component
takes the url and
uses org.apache.http.impl.nio.client.CloseableHttpAsyncClient to download
the pdf to a temp location etc...

The approach guarantees it's easy for the client's developers to add print
cloud buttons to ftl's using already available pdf generation mechanisms.

What actually gets downloaded is the login html page. Which isn't
surprising.
I thought the solution would be to set cookies into
the org.apache.http.protocol.HttpContext included in the httpclient.execute
call.

So I stepped through the login code LoginWorker (ofbiz 10.04) and the only
place where a cookie is set is on line 632 name: ...aut
oLoginId, value: userLoginId setting this into the HttpClient doesn't
resolve the issue, which also makes sense if adding a userLoginId to
browser cookie was enough to requests that require auth it would be
pointless.

Using the following doesn't work either....
CredentialsProvider credsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials userCred = new
UsernamePasswordCredentials("admin", "ofbiz");
credsProvider.setCredentials(new AuthScope("localhost", 8080),  userCred);
CloseableHttpAsyncClient httpclient =
HttpAsyncClients.custom().setDefaultCredentialsProvider(credsProvider).build();

I imagine a similar sort of thing might need to be done when using Selenium
... Can anyone point me in the right direction here?