如何获得有效的 Alfresco 应用程序上下文来创建文件夹?
How do I get a valid Alfresco application context to create folders?
我正在修改 InboundSMTP 以便为新邮件创建文件夹。似乎需要 fileFolderService.create,以及文件夹内容类型的参数。从那开始我需要一个 ServiceRegistry,它又需要 ApplicationContext。
这是我正在尝试做的事情:
ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/application-context.xml");
ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
FileFolderService fileFolderService=serviceRegistry.getFileFolderService();
FileInfo object = fileFolderService.create(nodeRef, messageSubject, ContentModel.TYPE_FOLDER);
但是,这会导致入站电子邮件被拒绝。我可以注释掉最后 3 行,但它仍然以同样的方式失败,所以我的 ApplicationContext 调用有问题。即使只是那个调用,我也会收到以下错误(这对我来说毫无意义):
ERROR [org.springframework.extensions.surf.util.AbstractLifecycleBean] [org.subethamail.smtp.server.Session-/2001:470:c27d:18:0:0:0:17:62204] 06300186 Email message processing failed
org.alfresco.error.AlfrescoRuntimeException: 06300186 Email message processing failed
at org.alfresco.email.server.EmailServiceImpl.processMessage(EmailServiceImpl.java:324)
at org.alfresco.email.server.EmailServiceImpl.importMessage(EmailServiceImpl.java:180)
at org.alfresco.email.server.impl.subetha.SubethaEmailServer$Handler.processDelivery(SubethaEmailServer.java:223)
at org.alfresco.email.server.impl.subetha.SubethaEmailServer$Handler.data(SubethaEmailServer.java:184)
at org.subethamail.smtp.command.DataCommand.execute(DataCommand.java:61)
at org.subethamail.smtp.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:27)
at org.subethamail.smtp.server.CommandHandler.handleCommand(CommandHandler.java:98)
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:222)
at org.subethamail.smtp.server.Session.run(Session.java:125)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 06300185 Not all patches could be applied
at org.alfresco.repo.admin.patch.PatchExecuter.applyOutstandingPatches(PatchExecuter.java:111)
at org.alfresco.repo.admin.patch.PatchExecuter.doWork(PatchExecuter.java:124)
at org.alfresco.repo.admin.patch.PatchExecuter.doWork(PatchExecuter.java:120)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:548)
at org.alfresco.repo.admin.patch.PatchExecuter.onBootstrap(PatchExecuter.java:128)
at org.springframework.extensions.surf.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:56)
at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEventInternal(SafeApplicationEventMulticaster.java:209)
at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEvent(SafeApplicationEventMulticaster.java:180)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.sscorp.CustomFolderEmailMessageHandler.addAlfrescoContent(CustomFolderEmailMessageHandler.java:132)
at com.sscorp.CustomFolderEmailMessageHandler.processMessage(CustomFolderEmailMessageHandler.java:94)
at org.alfresco.email.server.EmailServiceImpl.execute(EmailServiceImpl.java:296)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:342)
at org.alfresco.email.server.EmailServiceImpl.doWork(EmailServiceImpl.java:304)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:548)
at org.alfresco.email.server.EmailServiceImpl.processMessage(EmailServiceImpl.java:307)
... 8 more
我在尝试获取 ApplicationContext 时做错了什么?或者,我是否应该尝试另一种 approach/is 在 Alfresco 中以编程方式创建文件夹的 更好的 方法?
在这种情况下,您不需要注入应用程序上下文。
修改电子邮件处理的最佳做法涉及创建自定义处理程序。下面是定义这个的重要代码:
public class CustomFolderEmailMessageHandler extends AbstractEmailMessageHandler {
public void processMessage(NodeRef nodeRef, EmailMessage message) {
NodeService nodeService = getNodeService();
}
}
抽象 class 有一个 getNodeService()
方法,它为您提供节点服务。这是 FileFolderService 的详细版本。
您应该使用 FolderEmailMessageHandler 作为指南:https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/java/org/alfresco/email/server/handler/FolderEmailMessageHandler.java
为了注册您的消息处理程序,您需要覆盖 emailService bean:
https://wiki.alfresco.com/wiki/Inbound_SMTP_Email_Server_Configuration#Implementing_A_Custom_Node_Handler
您几乎肯定不想获取您需要执行的应用程序上下文!
如果你想要 "all the common services",请不要获取上下文。相反,请 Spring 给你 Alfresco ServiceRegistry。它可以作为 ID 为 ServiceRegistry
的 bean 提供,并且为您可能需要的主要服务提供方便的 getter
但在你的情况下,如果你知道你想要 FileFolderService
,请向 spring 索取你的豆子!如果您要覆盖 documentEmailMessageHandler
bean(例如),您需要一个像这样的 bean:
<bean id="documentEmailMessageHandler"
parent="emailMessageHandlerBase"
class="com.something.else.DocumentEmailMessageHandler">
<property name="fileFolderService" ref="FileFolderService"/>
</bean>
然后在您的自定义实现中,提供一个方法 setFileFolderService(FileFolderService fileFolderService)
来保存服务供以后使用。如果这对您来说是新的,请遵循任何标准 spring 教程!
如果您确实确实需要 Spring 应用程序上下文,请遵循正常的 Spring 模式并让您的 bean class 实现 ApplicationContextAware interface,并且 spring 将在初始化期间为您设置上下文
我正在修改 InboundSMTP 以便为新邮件创建文件夹。似乎需要 fileFolderService.create,以及文件夹内容类型的参数。从那开始我需要一个 ServiceRegistry,它又需要 ApplicationContext。
这是我正在尝试做的事情:
ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/application-context.xml");
ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
FileFolderService fileFolderService=serviceRegistry.getFileFolderService();
FileInfo object = fileFolderService.create(nodeRef, messageSubject, ContentModel.TYPE_FOLDER);
但是,这会导致入站电子邮件被拒绝。我可以注释掉最后 3 行,但它仍然以同样的方式失败,所以我的 ApplicationContext 调用有问题。即使只是那个调用,我也会收到以下错误(这对我来说毫无意义):
ERROR [org.springframework.extensions.surf.util.AbstractLifecycleBean] [org.subethamail.smtp.server.Session-/2001:470:c27d:18:0:0:0:17:62204] 06300186 Email message processing failed
org.alfresco.error.AlfrescoRuntimeException: 06300186 Email message processing failed
at org.alfresco.email.server.EmailServiceImpl.processMessage(EmailServiceImpl.java:324)
at org.alfresco.email.server.EmailServiceImpl.importMessage(EmailServiceImpl.java:180)
at org.alfresco.email.server.impl.subetha.SubethaEmailServer$Handler.processDelivery(SubethaEmailServer.java:223)
at org.alfresco.email.server.impl.subetha.SubethaEmailServer$Handler.data(SubethaEmailServer.java:184)
at org.subethamail.smtp.command.DataCommand.execute(DataCommand.java:61)
at org.subethamail.smtp.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:27)
at org.subethamail.smtp.server.CommandHandler.handleCommand(CommandHandler.java:98)
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:222)
at org.subethamail.smtp.server.Session.run(Session.java:125)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 06300185 Not all patches could be applied
at org.alfresco.repo.admin.patch.PatchExecuter.applyOutstandingPatches(PatchExecuter.java:111)
at org.alfresco.repo.admin.patch.PatchExecuter.doWork(PatchExecuter.java:124)
at org.alfresco.repo.admin.patch.PatchExecuter.doWork(PatchExecuter.java:120)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:548)
at org.alfresco.repo.admin.patch.PatchExecuter.onBootstrap(PatchExecuter.java:128)
at org.springframework.extensions.surf.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:56)
at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEventInternal(SafeApplicationEventMulticaster.java:209)
at org.alfresco.repo.management.SafeApplicationEventMulticaster.multicastEvent(SafeApplicationEventMulticaster.java:180)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.sscorp.CustomFolderEmailMessageHandler.addAlfrescoContent(CustomFolderEmailMessageHandler.java:132)
at com.sscorp.CustomFolderEmailMessageHandler.processMessage(CustomFolderEmailMessageHandler.java:94)
at org.alfresco.email.server.EmailServiceImpl.execute(EmailServiceImpl.java:296)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:342)
at org.alfresco.email.server.EmailServiceImpl.doWork(EmailServiceImpl.java:304)
at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:548)
at org.alfresco.email.server.EmailServiceImpl.processMessage(EmailServiceImpl.java:307)
... 8 more
我在尝试获取 ApplicationContext 时做错了什么?或者,我是否应该尝试另一种 approach/is 在 Alfresco 中以编程方式创建文件夹的 更好的 方法?
在这种情况下,您不需要注入应用程序上下文。
修改电子邮件处理的最佳做法涉及创建自定义处理程序。下面是定义这个的重要代码:
public class CustomFolderEmailMessageHandler extends AbstractEmailMessageHandler {
public void processMessage(NodeRef nodeRef, EmailMessage message) {
NodeService nodeService = getNodeService();
}
}
抽象 class 有一个 getNodeService()
方法,它为您提供节点服务。这是 FileFolderService 的详细版本。
您应该使用 FolderEmailMessageHandler 作为指南:https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/java/org/alfresco/email/server/handler/FolderEmailMessageHandler.java
为了注册您的消息处理程序,您需要覆盖 emailService bean: https://wiki.alfresco.com/wiki/Inbound_SMTP_Email_Server_Configuration#Implementing_A_Custom_Node_Handler
您几乎肯定不想获取您需要执行的应用程序上下文!
如果你想要 "all the common services",请不要获取上下文。相反,请 Spring 给你 Alfresco ServiceRegistry。它可以作为 ID 为 ServiceRegistry
的 bean 提供,并且为您可能需要的主要服务提供方便的 getter
但在你的情况下,如果你知道你想要 FileFolderService
,请向 spring 索取你的豆子!如果您要覆盖 documentEmailMessageHandler
bean(例如),您需要一个像这样的 bean:
<bean id="documentEmailMessageHandler"
parent="emailMessageHandlerBase"
class="com.something.else.DocumentEmailMessageHandler">
<property name="fileFolderService" ref="FileFolderService"/>
</bean>
然后在您的自定义实现中,提供一个方法 setFileFolderService(FileFolderService fileFolderService)
来保存服务供以后使用。如果这对您来说是新的,请遵循任何标准 spring 教程!
如果您确实确实需要 Spring 应用程序上下文,请遵循正常的 Spring 模式并让您的 bean class 实现 ApplicationContextAware interface,并且 spring 将在初始化期间为您设置上下文