1

I am trying to validate the contents of a pdf letter for my test automation. For that, first I am trying to download the pdf file to my local machine and validate. But I am not able to download the file properly with Java. The pdf is present as an embedded document in a page which requires me to log in first. The html looks like below

<td colspan="2" style="vertical-align:top;" id="frameCell_24743998"><iframe id="viewFrame_24743998" src="https://wewewe.net/ewr/ww/desk/ViewQCWalzPDFAction.do?recordId=24743998&amp;we=we&amp;partitionId=16515&amp;Id=1561024580039s79n0a" height="550" width="800" style="width: 1254px;"></iframe><br></td>

So I have got the url and tried to download the file using

FileUtils.copyURLToFile(new URL("https://wewewe.net/ewr/ww/desk/ViewQCWalzPDFAction.do?recordId=24743998&amp;we=we&amp;partitionId=16515&amp;Id=1561024580039s79n0a"), new File("C:\\workspace\\dfdf\\dfdffddf\\dd.pdf"));

But it is showing

java.net.ConnectException: Connection timed out: Exception.

So is this because I haven't logged in to the application and trying to download. Is there any other way to download it?

SurajSr
  • 141
  • 10

1 Answers1

1

Is there any other way to download it?

That very much depends on how exactly that web page is built.

It might for example be possible to use cookies with your Java code, see here for some instructions how to do that. Meaning: you can enable your java code to appear "authorised".

If all of that doesn't work (and adapting the server to be allow "programmatic" access to such files isn't an option), then you could use automation tools such as selenium to do a "browser like" connection+download. See there for guidance.

GhostCat
  • 137,827
  • 25
  • 176
  • 248