gpt4 book ai didi

java - 如何使用 Java 代码将文档添加到 Alfresco Repository?

转载 作者:行者123 更新时间:2023-11-29 06:58:15 25 4
gpt4 key购买 nike

编辑:显然我必须制作一个 AMP 并将其映射到 Alfresco.war。但是现在我不能访问我写的代码,所以我想我将不得不使用 Webscripts 之类的。有人可以提供一个示例,说明如何使用 Java 支持的网络脚本将文档添加到 Alfresco 存储库吗?

原始问题:

我在 google 范围内搜索了一种使用 Java 代码将文档添加到 Alfresco Repository 的方法。但是我找不到可行的方法。我知道如何将文档添加到存储库:使用 NodeService。但问题是我无法获得 NodeService 的实例。我试过用@Autowired 注入(inject)它,我试过使用 bean,我试过使用 ApplicationContext。没有一种方法有效...

方式一:
在类中注入(inject):

@Autowired
NodeService nodeService

方法#2:
在 service-context.xml 中:

<bean id="somerandombeanname" class="management.FileManager" >
<property name="moduleId" value="${project.artifactId}" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="nodeService" ref="NodeService" />
<property name="transactionService" ref="TransactionService" />
<property name="contentService" ref="ContentService" />
</bean>

在类中,我为所有服务和 serviceRegistry 添加了 getter 和 setter:

private NodeService nodeService;

public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}

方式三:

appContext = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");

serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

nodeService = serviceRegistry.getNodeService();

方法#1 和#2 给了我一个 NullPointerException,只是声明 NodeService 为空。由于 AlfrescoRuntimeException 未能初始化 keystore ,方式 #3 给出了一英里长的 StackTrace:

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ssl.keyStore' defined in class path resource [alfresco/encryption-context.xml]: Invocation of init method failed; nested exception is org.alfresco.error.AlfrescoRuntimeException: 04180000 Failed to initialize keystore:
Location: E:/Alfresco/alf_data/keystore/ssl.keystore
Provider: null
Type: JCEKS
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at management.FileManager.<init>(FileManager.java:36)
at simple.start.main(start.java:25)
... 5 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: 04180000 Failed to initialize keystore:
Location: E:/Alfresco/alf_data/keystore/ssl.keystore
Provider: null
Type: JCEKS
at org.alfresco.encryption.AlfrescoKeyStoreImpl.loadKeyStore(AlfrescoKeyStoreImpl.java:566)
at org.alfresco.encryption.AlfrescoKeyStoreImpl.safeInit(AlfrescoKeyStoreImpl.java:537)
at org.alfresco.encryption.AlfrescoKeyStoreImpl.init(AlfrescoKeyStoreImpl.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1639)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1580)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1510)
... 18 more
Caused by: java.lang.IllegalArgumentException: name
at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:494)
at sun.misc.URLClassPath.findResource(URLClassPath.java:176)
at java.net.URLClassLoader$2.run(URLClassLoader.java:551)
at java.net.URLClassLoader$2.run(URLClassLoader.java:549)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:548)
at java.lang.ClassLoader.getResource(ClassLoader.java:1147)
at org.springframework.core.io.ClassPathResource.resolveURL(ClassPathResource.java:147)
at org.springframework.core.io.ClassPathResource.exists(ClassPathResource.java:135)
at org.alfresco.encryption.SpringKeyResourceLoader.getSafeInputStream(SpringKeyResourceLoader.java:67)
at org.alfresco.encryption.SpringKeyResourceLoader.loadKeyMetaData(SpringKeyResourceLoader.java:133)
at org.alfresco.encryption.AlfrescoKeyStoreImpl$KeyInfoManager.loadKeyMetaData(AlfrescoKeyStoreImpl.java:1016)
at org.alfresco.encryption.AlfrescoKeyStoreImpl$KeyInfoManager.<init>(AlfrescoKeyStoreImpl.java:998)
at org.alfresco.encryption.AlfrescoKeyStoreImpl.getKeyInfoManager(AlfrescoKeyStoreImpl.java:395)
at org.alfresco.encryption.AlfrescoKeyStoreImpl.loadKeyStore(AlfrescoKeyStoreImpl.java:560)
... 27 more

是的, keystore 存在,是的,我已经重新生成了一个新的 keystore 。

我使用的是 Alfresco 5.0.1,并且我在 Repository 端(不是共享)工作。

最佳答案

@Autowired
NodeService nodeService

不能在露天使用

您需要使用适当的 setter 方法注入(inject)它。您的 bean 应该如下所示。

<bean id="somerandombeanname" class="management.FileManager" >
<property name="moduleId" value="${project.artifactId}" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="nodeService" ref="NodeService" />
<property name="transactionService" ref="TransactionService" />
<property name="contentService" ref="ContentService" />
</bean>

您的 java 类应包含以下用于注入(inject) nodeService 的内容。

private NodeService nodeService;

public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}

关于java - 如何使用 Java 代码将文档添加到 Alfresco Repository?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30304918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com