我想在IBM连接中捕获文件上传事件,并采取一些措施。如果满足特定条件,则应将该文件存储在系统中,否则应使用消息拒绝该文件。
为此,我探索了(事件前处理程序钩子)。我遵循了创建jar、部署和更改配置所需的必要步骤,但当文件上传到连接中时,我的代码似乎没有被调用。
不确定,问题在哪里,因为我也没有任何错误。
PS:我尝试过Post事件处理程序钩子,它成功地工作了。
下面是片段
public class PreHandlerEvents implements PreEventHandler{
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void handleEvent(MutableEvent arg0) throws EventHandlerException {
String content = "This is the content to write into file";
File file = new File("filenamePre.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileWriter fw;
try {
fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}events-config.xml
<preHandler enabled="true" name="PreHandlerEvents" class="com.connections.PreHandlerEvents">
<subscriptions>
<subscription source="*" type="*" eventName="*"/>
</subscriptions>
</preHandler>
</preHandlers>发布于 2016-08-19 10:51:57
与其使用PreEventHandler,不如在<preHandler .../>中使用EventHandler。
示例代码:
public class CustomEventHandler implements EventHandler {
public void init() throws EventHandlerInitException {}
public void destroy() {}
@Override
public void handleEvent(Event event) throws EventHandlerException {
System.out.println(" +++ Event: " + event.getName());
}
}https://stackoverflow.com/questions/38472176
复制相似问题