Authorization with Bearer Token from Java not working to download file...

12 views
Skip to first unread message

Dan Wellisch

unread,
Jun 4, 2021, 3:15:37 PMJun 4
to dotCMS User Group
Hello:

My code below is just for reference.  My problem is that the code is not authenticating to DOTCMS in order to get the specified file.

I know the path to the resource is correct!  As when I login via the browser to our dotCMS instance and then open another browser window,  I paste the url address in the browser address area and enter....the file downloads properly.  It is an excel file and it looks normal.

It feels like something on the dotCMS side is blocking my request....

Any ideas?  

Dan

                        urlConnection = url.openConnection();
                        urlConnection.setRequestProperty("Authorization", "Bearer " + APICallsUnitTests.token);
                        //urlConnection.setRequestProperty("Content-Type","application/octet-stream");
                        InputStream is = urlConnection.getInputStream();
                        Files.copy(is, Paths.get("artifact2.xslx"), StandardCopyOption.REPLACE_EXISTING);

jonathan...@dotcms.com

unread,
Jun 4, 2021, 4:09:02 PMJun 4
to dotCMS User Group
Hi,

I have checked this locally and I can access the asset even anon. just make sure it is publish.
The service returns 404, if the asset is only working version.

Best,
J

Dan Wellisch

unread,
Jun 8, 2021, 3:03:29 PMJun 8
to dotCMS User Group
Jonathan:

The problem is solved....instead of the Authorization key for the header, I needed the Cookie key with "access_token = <token>" as the value.
See below...

Perhaps, this will help someone else....thanks!

urlConnection.setRequestProperty("Cookie", "access_token=" + APICallsUnitTests.token);

jonathan...@dotcms.com

unread,
Jun 8, 2021, 4:21:39 PMJun 8
to dotCMS User Group
Cool, I am glad you get it working

Best,
J
Reply all
Reply to author
Forward
0 new messages