如何从XPages系统事件中的文件系统中删除文件。

huangapple go评论67阅读模式
英文:

How to remove a File from the File System in a XPages System Event

问题

我想在会话终止时删除一个文件,然而,当我尝试从文件系统修改文件时,我遇到了一个Notes安全异常。

以下是我尝试过的方法:

File f = getSourceFile();    
f.delete(); // java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig (Accessing or modifiying this File is prohibited)

FileUtils.clearFile(f); // java.lang.IllegalStateException: NotesContext is not initialized for the Thread

这是我获取文件的方法:

public File getSourceFile() {
    return new File(this.absolutePath);
}

我还尝试过使用doPrivileged,但导致了相同的IllegalStateException

AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {	
        File f = getSourceFile();
        if(f.exists()){
            FileUtil.deleteFile(f);
        }
    }
});

我猜可以重新初始化NotesContext,但我认为那不是一个优雅的解决方案。

堆栈跟踪:

(非法状态)

java.lang.IllegalStateException: NotesContext not initialized for the thread
    at com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent(NotesContext.java:123)
    at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.findClass(ModuleClassLoader.java:438)
    at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:924)
    ...

(安全)

java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig
    at lotus.notes.AgentSecurityManager.checkDelete(Unknown Source)
    at java.io.File.delete(File.java:1047)
    ...

我无法找到解决方法。

英文:

I want to remove a File, when a Session is terminated, however, when trying to modify a File from the File System, I get a Notes Security Exception.

Here is what I have tried:

File f = getSourceFile();    
f.delete(); // java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig (Accessing or modifiying this File is prohibited)
			
FileUtils.clearFile(f); // java.lang.IllegalStateException: NotesContext is not initialized for the Thread 

This is how I retrieve my File:

public File getSourceFile() {
	return new File(this.absolutePath);
}

I also tried using doPrivileged but that caused the same IllegalStateException:

AccessController.doPrivileged(new PrivilegedAction() { // java.lang.IllegalStateException: NotesContext is not initialized for the Thread
	public Object run() {	
		File f = getSourceFile();
			if(f.exists()){
				FileUtil.deleteFile(f);
		    }
	}
});

I guess it would be Possible to reinitialize the NotesContext somehow, but I don't think that would be an elegant solution.

The Stacktraces:

(Illegal State)

java.lang.IllegalStateException: NotesContext not initialized for the thread
at com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent(NotesContext.java:123)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.findClass(ModuleClassLoader.java:438)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:924)
at java.lang.ClassLoader.loadClass(ClassLoader.java:869)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.loadClass(ModuleClassLoader.java:403)
at java.lang.ClassLoader.loadClass(ClassLoader.java:852)
at de.iV.beans.ticket.file.FileWrapper.clear(FileWrapper.java:90)
at de.iV.beans.ticket.Ticket.clearFiles(Ticket.java:155)
at de.iV.session.CustomSessionListener.sessionDestroyed(CustomSessionListener.java:46)
at com.ibm.xsp.application.ApplicationSessionListener.sessionDestroyed(ApplicationSessionListener.java:53)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.notifySessionRemoved(ComponentModule.java:370)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.checkSessionTimeout(ComponentModule.java:239)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.checkTimeout(NSFComponentModule.java:213)
at com.ibm.domino.xsp.module.nsf.NSFService.checkTimeout(NSFService.java:281)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.checkTimeout(LCDEnvironment.java:247)
at com.ibm.designer.runtime.domino.bootstrap.BootstrapEnvironment.tellCommand(BootstrapEnvironment.java:388)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.tell(XspCmdManager.java:92

(Security)

    java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig
at lotus.notes.AgentSecurityManager.checkDelete(Unknown Source)
at java.io.File.delete(File.java:1047)
at de.iV.beans.ticket.file.FileWrapper.clear(FileWrapper.java:94)
at de.iV.beans.ticket.Ticket.clearFiles(Ticket.java:155)
at de.iV.session.CustomSessionListener.sessionDestroyed(CustomSessionListener.java:46)
at com.ibm.xsp.application.ApplicationSessionListener.sessionDestroyed(ApplicationSessionListener.java:53)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.notifySessionRemoved(ComponentModule.java:370)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.checkSessionTimeout(ComponentModule.java:239)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.checkTimeout(NSFComponentModule.java:213)
at com.ibm.domino.xsp.module.nsf.NSFService.checkTimeout(NSFService.java:281)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.checkTimeout(LCDEnvironment.java:247)
at com.ibm.designer.runtime.domino.bootstrap.BootstrapEnvironment.tellCommand(BootstrapEnvironment.java:388)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.tell(XspCmdManager.java:92)

I was not able to figure out a workaround.

答案1

得分: 1

你有两个选择:

  • 编辑java.policy文件(或创建java.pol文件 - 不适用于11.0)
  • 将你的代码移到一个osgi插件中

对于后者:它并不像听起来那么可怕。你的插件将存放在一个updatesite.nsf中。

查看这个幻灯片获取入门信息。

英文:

You have 2 options:

  • Edit java.policy (or create java.pol - not on 11.0)
  • Move your code into an osgi plugin

For the later: it isn't as scary as it sounds. Your plugin would live in an updatesite.nsf

Check this deck for getting started info.

答案2

得分: 1

我进行了一个快速测试,一切都没有问题。ND9和ND10。

一个会话监听器,在“会话销毁”事件中删除文件,无需修改java.policy。

编辑:
啊,明白了。与文件删除无关。这是一个在从“会话销毁”事件访问您的NSF中的类时出现的类加载器问题。

英文:

I did a quick test, and everything worked without a problem. ND9 & ND10.

A Session listener, a file deletion in "Session Destroyed"-Event, no java.policy modification.

EDIT:
Ah, got it. It has nothing to do with the file deletion. It is a ClassLoader problem when accessing classes in your NSF from the "Session Destroyed"-Event.

huangapple
  • 本文由 发表于 2020年3月16日 19:41:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/60705331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定