I am trying to provide an automate healthcheck for my service that uses Aspose words for java.
Hi Sharadha,
Thanks for your inquiry. Yes, in this case, Aspose.Words fro Java will throw similar to the following error:
java.lang.IllegalStateException: The subscription included in this license allows free upgrades until 04 Dec 2013, but this version of the product was released on 31 May 2014. Please renew the subscription or use a previous version of the product.
Secondly, I am afraid, the License class doesn’t expose any built-in methods to check/track the status whether a license is properly applied or not. However, if you want to be sure, you can try creating your own custom method to do this job. To do this you could create a blank document and export this to a stream. Then reload this and check the first paragraph in the body for the evaluation message. Please see the following code:
License license = new License();
Document doc = null;
try
{
license.setLicense(getMyDir() + "Aspose.Words.lic");
}
catch (Exception ex)
{
// do nothing
}
if (isLicenseSet())
{
System.out.println("License is applied. You are good to go");
}
else
{
System.out.println("Something wrong with License");
}
private static boolean isLicenseSet()
{
try
{
// We will insert this text at the beggining of the document.
// If the license set this text will be in th efirt paragraph,
// if not an evaluation watermark will be in the first paragraph.
String text = "This is text used to check if the license is set";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write(text);
// Save and open the document. If Aspose.Words works in evaluation mode it will add a watermark.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.DOC);
InputStream inStream = new ByteArrayInputStream(baos.toByteArray());
doc = new Document(inStream);
// Check text of the first paragraph.
return (doc.getFirstSection().getBody().getFirstParagraph().toString(SaveFormat.TEXT).trim().equals(text));
}
catch (Exception ex)
{
// do nothing
}
return false;
}
I hope, this helps.
Best regards,