Free Support Forum - aspose.cloud

Performance document saving bad after applying java security policy

We have an issue with the performance of writing the file to the filesystem(Document.Save()) after we deploy it to our cloud environment (where some java security is applied).

The file generation and saving is locally (without emulating cloud security 2-3 sec) and in the cloud (with the security rules below) 10-12 seconds.
Does anyone have experience to solve this problem?

Security policy:
ALLOW {
[org.osgi.service.condpermadmin.BundleLocationCondition “project.jar"]
(java.util.PropertyPermission "com.ctc.wstx.” “read”)
(org.osgi.framework.AdminPermission “" "” )
(org.osgi.framework.PackagePermission “" “exportonly,import” )
(org.osgi.framework.ServicePermission "” “get,register”)
(org.osgi.framework.BundlePermission “" “provide,require, host,fragment”)
(org.osgi.service.event.TopicPermission "” “publish,subscribe”)
(java.lang.reflect.ReflectPermission “suppressAccessChecks”)
(java.lang.RuntimePermission “accessClassInPackage.com.sun.org.apache.xerces.internal." “”)
(java.lang.RuntimePermission “accessClassInPackage.sun.misc” “”)
(java.lang.RuntimePermission “accessDeclaredMembers”)
(java.lang.RuntimePermission “getProtectionDomain”)
(java.lang.RuntimePermission “getClassLoader”)
(java.lang.RuntimePermission “modifyThread” “”)
(java.lang.RuntimePermission “setContextClassLoader”)
(java.lang.RuntimePermission “setFactory”)
(java.io.FilePermission “{DeploymentDir}/data/tmp/-” “read,write,delete,execute”)
(java.io.FilePermission “{DeploymentDir}/model/resources/-” “read”)
(java.io.FilePermission “{DeploymentDir}/model/lib/-” “read”)
(java.net.NetPermission “getProxySelector” “”)
(java.net.NetPermission “specifyStreamHandler” “”)
(java.security.SecurityPermission “insertProvider.BC” “”)
(java.security.SecurityPermission “putProviderProperty.BC” “”)
(java.util.logging.LoggingPermission “control” “”)
(java.util.PropertyPermission “com.google.gdata.DisableCookieHandler” “read”)
(java.util.PropertyPermission “com.sun.jersey.core.util.ReaderWriter.BufferSize” “read”)
(java.util.PropertyPermission “com.sun.xml.fastinfoset.parser.buffer-size” “read”)
(java.util.PropertyPermission “com.sun.xml.fastinfoset.parser.string-interning” “read”)
(java.util.PropertyPermission “com.sun.xml.fastinfoset.serializer.character-encoding-scheme” “read”)
(java.util.PropertyPermission “file.encoding” “read”)
(java.util.PropertyPermission “file.separator” “read”)
(java.util.PropertyPermission “glyphlist_ext” “read”)
(java.util.PropertyPermission “HSSFRow.ColInitialCapacity” “read”)
(java.util.PropertyPermission “HSSFSheet.RowInitialCapacity” “read”)
(java.util.PropertyPermission “HSSFWorkbook.SheetInitialCapacity” “read”)
(java.util.PropertyPermission “hornetq.version.property.filename” “read”)
(java.util.PropertyPermission “http.strictPostRedirect” “read”)
(java.util.PropertyPermission “https.cipherSuites” “read”)
(java.util.PropertyPermission “https.protocols” “read”)
(java.util.PropertyPermission “http://java.sun.com/xml/dom/properties/ancestor-check” “read”)
(java.util.PropertyPermission "ical4j.” “read,write”)
(java.util.PropertyPermission “imgscalr." “read,write”)
(java.util.PropertyPermission “java.home” “read”)
(java.util.PropertyPermission “java.io.tmpdir” “read,write”)
(java.util.PropertyPermission “java.protocol.handler.pkgs” “read, write”)
(java.util.PropertyPermission “java.specification.version” “read”)
(java.util.PropertyPermission “java.vendor” “read”)
(java.util.PropertyPermission “java.vendor.url” “read”)
(java.util.PropertyPermission “java.version” “read”)
(java.util.PropertyPermission “java.vm.name” “read”)
(java.util.PropertyPermission “java.vm.vendor” “read”)
(java.util.PropertyPermission “java.vm.version” “read”)
(java.util.PropertyPermission “javax.net.ssl.keyStore” “write”)
(java.util.PropertyPermission “javax.net.ssl.keyStorePassword” “read,write”)
(java.util.PropertyPermission “javax.net.ssl.trustStore” “read,write”)
(java.util.PropertyPermission “javax.net.ssl.trustStorePassword” “read,write”)
(java.util.PropertyPermission “jco.destinations.dir” “read”)
(java.util.PropertyPermission “line.separator” “read,write”)
(java.util.PropertyPermission “mail.smtp.auth” “read,write”)
(java.util.PropertyPermission “mail.smtp.host” “read,write”)
(java.util.PropertyPermission “mail.smtp.password” “read,write”)
(java.util.PropertyPermission “mail.smtp.port” “read,write”)
(java.util.PropertyPermission “mail.smtp.starttls.enable” “read,write”)
(java.util.PropertyPermission “mail.smtp.user” “read,write”)
(java.util.PropertyPermission “mapAnyUriToUri” “read”)
(java.util.PropertyPermission “mustache.compile” “read,write”)
(java.util.PropertyPermission “mustache.debug” “read,write”)
(java.util.PropertyPermission “nd.org.xml.sax.parser read” “read,write”)
(java.util.PropertyPermission “nd.org.xml.sax.parser” “read,write”)
(java.util.PropertyPermission "net.fortuna.” “read,write”)
(java.util.PropertyPermission “org.apache." “read,write”)
(java.util.PropertyPermission “org.bouncycastle.pkcs1.strict” “read”)
(java.util.PropertyPermission “org.glassfish.web.rfc2109_cookie_names_enforced” “read”)
(java.util.PropertyPermission “org.hornetq.opt.directblast” “read”)
(java.util.PropertyPermission “org.hornetq.ssl.keyStoreProvider” “read”)
(java.util.PropertyPermission “org.hornetq.ssl.trustStoreProvider” “read”)
(java.util.PropertyPermission "org.imgscalr.” “read,write”)
(java.util.PropertyPermission “org.jboss.netty.debug” “read”)
(java.util.PropertyPermission “org.springframework." “read write”)
(java.util.PropertyPermission "org.owasp.” “read,write”)
(java.util.PropertyPermission “org.xml.sax.parser” “read,write”)
(java.util.PropertyPermission “os.arch” “read”)
(java.util.PropertyPermission “os.name” “read”)
(java.util.PropertyPermission “os.version” “read”)
(java.util.PropertyPermission “path.separator” “read”)
(java.util.PropertyPermission “pdftextstripper.drop” “read”)
(java.util.PropertyPermission “pdftextstripper.indent” “read”)
(java.util.PropertyPermission “poi.keep.tmp.files” “read,write”)
(java.util.PropertyPermission “saaj.lazy.contentlength” “read”)
(java.util.PropertyPermission “ssl.KeyManagerFactory.algorithm” “read,write”)
(java.util.PropertyPermission “smack.disabledClasses” “read,write”)
(java.util.PropertyPermission “smack.provider.file” “read,write”)
(java.util.PropertyPermission “sun.arch.data.model” “read,write”)
(java.util.PropertyPermission “twitter4j.http.httpClient” “read,write”)
(java.util.PropertyPermission “twitter4j.loggerFactory” “read,write”)
(java.util.PropertyPermission “user.dir” “read”)
(java.util.PropertyPermission “webdriver.remote.shorten_log_messages” “read”)
(java.net.SocketPermission “*” “connect, accept”)
(java.net.SocketPermission “localhost:0” “listen,resolve”)
(javax.xml.bind.JAXBPermission “setDatatypeConverter”)
(org.bouncycastle.jce.ProviderConfigurationPermission “BC” “ecImplicitlyCA, threadLocalEcImplicitlyCA”)
} "Permissions for the project bundle"

ALLOW {
[org.osgi.service.condpermadmin.BundleLocationCondition “*project.jar” “!”]
(java.security.AllPermission)
} “AllPermission to everything except project bundle”

Hi Pim,

Thanks for your inquiry. Please note that CPU performance and memory usage all depend on complexity and size of the documents you are loading/generating.

Could you please share the complete detail of your use case along with input document? Please share how are you getting conversion time at cloud environment. We will then provide you more information about your query.
The specs are: 512MB Ram and 1 core. I can reproduce its behaviour on my local machine.
By setting the java heap to 512 and emulate cloud security (rules above): slow by not emulating cloud security fast generation of documents. So it's not the Memory or CPU.

we had already added this line to the policy (because of the clear error aspose needed this permission: (java.util.PropertyPermission "com.ctc.wstx.*" "read") )

The complete code for generating a document Word.docx to PDF:

// BEGIN USER CODE
// init logging
ILogNode log = Core.getLogger("DocGen");
IContext context = this.getContext();
this.WordTemplate.commit();
log.debug("Word template committed");
FontSettings.setFontsFolder(Core.getConfiguration().getResourcesPath().getAbsolutePath() + File.separator, false);
Document template = new Document(Core.getFileDocumentContent(context, this.__WordTemplate));

// get HTML fields and pass as List
List htmlFields = Core.retrieveXPathQuery(context, "//" + FieldMapping.entityName + "[RenderAsHTML = true()][" + FieldMapping.MemberNames.FieldMapping_Table + "/" + Table.entityName + "/" + Table.MemberNames.Table_TemplateType + " = '" + this.TemplateTypeParameter1.getGUID() + "']");
ArrayList htmlFieldsAsArray = new ArrayList();
for(IMendixObject htmlField : htmlFields){
htmlFieldsAsArray.add(FieldMapping.initialize(context, htmlField).getName());
}
template.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertHtml(htmlFieldsAsArray));
SectionCollection sectoins = template.getSections();
int i = 0;
int merges = sectoins.toArray().length;
merges *= 3; // each secction may have header and footer
for (i=0; i < merges; i++){
ApprontoMergeImplementation parentTable = new ApprontoMergeImplementation(context, "Container", this.TemplateTypeParameter1, this.RootContextObject);
template.getMailMerge().executeWithRegions(parentTable);
}
//template.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
log.info(" merge done");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
template.save(stream, ApprontoMergeImplementation.determineOutputCode(this.MergeInputParameter1.getOutputType()));
log.info(" template.save done");
Core.storeFileDocumentContent(context, this.__OutputDoc, new ByteArrayInputStream(stream.toByteArray()));
this.OutputDoc.commit();
log.info("Word template committed");

return true;
// END USER CODE

code took 1 sec to come to " template.save(stream, ..... " which is http://www.aspose.com/api/java/words/com.aspose.words/classes/document/methods/save(java.io.OutputStream,int)/
after that is took 10 sec to get the line of storing it actual to disk at Core.storeFileDocumentContent with the new stream:

FAST LOG
2016-10-17 20:21:01.299 DocGen merge done
2016-10-17 20:21:03.823 DocGen template.save done
2016-10-17 20:21:03.831 DocGen Word template committed
SLOW LOG
2016-10-17 20:21:53.284 DocGen merge done
2016-10-17 20:22:01.447 DocGen template.save done
2016-10-17 20:22:01.455 DocGen Word template committed



We have this performance situation for every document. I attached a sample of one.

thanks for the support,




Hi Pim,

Thanks for your inquiry. You are using older version of Aspose.Words. Please try Aspose.Words for Java 16.10.0.

If you still face problem, please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.