我试图将简单的XHTML文件转换为PDF,并使用Flying Saucer和iText这样做.它在Java中没有问题,但是,当我尝试使用相同的代码创建Lotus Notes代理时,我得到了一个例外,我不确定如何处理.
代码:
import lotus.domino.*;
import java.io.*;
import com.lowagie.text.DocumentException;
import org.xhtmlrenderer.pdf.ITextRenderer;
import org.xhtmlrenderer.util.XRLog;
import java.util.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
String received = agentContext.getDocumentContext().
getItemValueString("Query_String");
String[] split;
split = received.split("&");
String url = split[1];
split = url.split("/");
String outputFile = split[split.length-1];
String direc = session.getEnvironmentString("Directory", true);
outputFile = direc + "\\" + outputFile + ".pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
System.exit(0);
} catch(Exception e) {
e.printStackTrace();
}
}
}
这产生以下结果:
09-05-2011 13:33:29 HTTP JVM: Could not initialize configuration for Flying Saucer library. Message is: Can’t find resource for bundle java.util.PropertyResourceBundle, key access_properties_not_allowed
09-05-2011 13:33:29 HTTP JVM: java.util.MissingResourceException: Can’t find resource for bundle java.util.PropertyResourceBundle, key access_properties_not_allowed
09-05-2011 13:33:29 HTTP JVM: at java.util.MissingResourceException.(MissingResourceException.java:50)
09-05-2011 13:33:29 HTTP JVM: at java.util.ResourceBundle.getObject(ResourceBundle.java:400)
09-05-2011 13:33:29 HTTP JVM: at java.util.ResourceBundle.getString(ResourceBundle.java:421)
09-05-2011 13:33:29 HTTP JVM: at lotus.notes.JavaString.getString(Unknown Source)
09-05-2011 13:33:29 HTTP JVM: at lotus.notes.AgentSecurityManager.checkPropertiesAccess(Unknown Source)
09-05-2011 13:33:30 HTTP JVM: at java.lang.System.getProperties(System.java:323)
09-05-2011 13:33:30 HTTP JVM: at org.xhtmlrenderer.util.Configuration.loadSystemProperties(Configuration.java:419)
09-05-2011 13:33:30 HTTP JVM: at org.xhtmlrenderer.util.Configuration.(Configuration.java:147)
09-05-2011 13:33:30 HTTP JVM: at org.xhtmlrenderer.util.Configuration.instance(Configuration.java:742)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.Configuration.valueFor(Configuration.java:463)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.Configuration.isTrue(Configuration.java:709)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.XRLog.init(XRLog.java:250)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.XRLog.log(XRLog.java:203)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.XRLog.render(XRLog.java:194)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.util.XRLog.render(XRLog.java:190)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.layout.SharedContext.(SharedContext.java:107)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:111)
09-05-2011 13:33:31 HTTP JVM: at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:102)
09-05-2011 13:33:31 HTTP JVM: at JavaAgent.NotesMain(Unknown Source)
09-05-2011 13:33:31 HTTP JVM: at lotus.domino.AgentBase.runNotes(Unknown Source)
09-05-2011 13:33:31 HTTP JVM: at lotus.domino.NotesThread.run(Unknown Source)
违规行是
ITextRenderer renderer = new ITextRenderer();
谷歌搜索“access_properties_not_allowed”几乎没有任何内容.
解决方法:
1)Notes / Domino中的代理在代理属性中具有其他安全功能,用于设置代理的安全级别.默认情况下,此设置设置为不允许受限操作(默认设置为“不允许受限操作”).
要使代理程序运行该属性,必须将其设置为以下选项之一:
“允许限制操作”
“允许具有完全管理权限的受限操作”
该属性位于“代理属性”对话框的第二个选项卡(密钥选项卡)上.
2)由于已经解释了“通往yamburg之路”,JVM的安全管理器不允许访问系统的属性,因为安全策略未指定允许此操作.
您必须更改Java虚拟机(JVM)的安全策略才能允许访问系统属性.为此,您可以添加“permission java.security.AllPermission;”行.到Notes / Domino目录中的“/jvm/lib/security/java.policy”文件.
进行更改后,java.policy文件将与此类似:
grant {
permission java.security.AllPermission;
permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
// ... and so on ...
}
重新启动客户端/服务器后,任何需要访问System.getProperties()的Java程序现在都将被授予访问权限.