Java - 登录后从站点检索图像

时间:2022-10-20 08:25:18

Hey, folks. What I'm trying to do is write a Confluence plugin containing a servlet that generates a pdf based on the Active Directory. Anyway, there is an attachment repository on the confluence space. Problem is, when I try to create an IText image from the pdf, it gets all buggy. I'm assuming it is because the page is behind a login. Any other images work just fine.

嘿伙计。我要做的是编写一个Confluence插件,其中包含一个基于Active Directory生成pdf的servlet。无论如何,在汇合空间有一个附件库。问题是,当我尝试从pdf创建一个IText图像时,它会变成所有错误。我假设这是因为页面在登录后面。任何其他图像工作得很好。

At any rate, is there a way, in Java, I can retrieve the image in even just a byte[] after logging in with some sort of credentials?

无论如何,有没有办法,在Java中,我可以使用某种凭证登录后甚至只需一个字节[]检索图像?

Error Example:

Image portrait = Image.getInstance(new URL("http://*Local Network*/download/attachments/3409000/PdfTestImage.JPG"));

^^ throws java.io.IOException: http://*Local Network*/download/attachments/3409000/John.Doe.JPG is not a recognized imageformat. at com.itextpdf.text.Image.getInstance(Image.java:317)

^^抛出java.io.IOException:http:// * Local Network * / download / attachments / 3409000 / John.Doe.JPG不是可识别的图像格式。 at com.itextpdf.text.Image.getInstance(Image.java:317)

While

Image portrait = Image.getInstance(new URL("http://www.dominionpaper.ca/files/dominion-img/hedgehog.JPG"));

or anything else I put in there doesn't cause a problem. Any suggestions? I've used HttpClient before but I'm not positive if it'd be applicable.

或者我放在那里的任何其他东西都不会引起问题。有什么建议?我之前使用过HttpClient,但如果它适用的话我不肯定。

1 个解决方案

#1


0  

You problem description is quite confusing. Let me repeat it to make sure I've got it right: you need to extract an image from a password-protected site, but you are not logged in into that site (user may be logged in, but not your server-side code)?

你的问题描述很混乱。让我重复一遍以确保我做对了:您需要从受密码保护的站点提取图像,但您没有登录到该站点(用户可能已登录,但不是您的服务器端代码)?

Then I'd suggest to user HttpClient to provide the correct credentials and download the file to local storage where you can process it the way you like. Note that if the site uses MS SSO, the task could be quite complicated, as your code would need a service account with AD/Kerberos.

然后我建议用户HttpClient提供正确的凭据并将文件下载到本地存储,您可以按照自己喜欢的方式处理它。请注意,如果站点使用MS SSO,则任务可能非常复杂,因为您的代码需要具有AD / Kerberos的服务帐户。

#1


0  

You problem description is quite confusing. Let me repeat it to make sure I've got it right: you need to extract an image from a password-protected site, but you are not logged in into that site (user may be logged in, but not your server-side code)?

你的问题描述很混乱。让我重复一遍以确保我做对了:您需要从受密码保护的站点提取图像,但您没有登录到该站点(用户可能已登录,但不是您的服务器端代码)?

Then I'd suggest to user HttpClient to provide the correct credentials and download the file to local storage where you can process it the way you like. Note that if the site uses MS SSO, the task could be quite complicated, as your code would need a service account with AD/Kerberos.

然后我建议用户HttpClient提供正确的凭据并将文件下载到本地存储,您可以按照自己喜欢的方式处理它。请注意,如果站点使用MS SSO,则任务可能非常复杂,因为您的代码需要具有AD / Kerberos的服务帐户。