gpt4 book ai didi

java - Alfresco java webscript 的 ServiceRegistry 为空

转载 作者:行者123 更新时间:2023-11-29 02:59:29 24 4
gpt4 key购买 nike

我在露天创建了一个一体式放大器。在 repo-amp 我已经创建了一个 java webscript,我想将文件名作为特定工作区的 json 返回。 java代码如下

.
.
.

public class Fields extends AbstractWebScript
{

private ServiceRegistry serviceRegistry;

public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
try
{
NodeService nodeService = serviceRegistry.getNodeService();
String parameter=req.getParameter("nodeRef");
NodeRef nodeRef=new NodeRef(parameter);

Map<QName, Serializable> props = nodeService.getProperties(nodeRef);

// Fetch a few common properties
String name = (String)props.get(ContentModel.PROP_NAME);
String title = (String)props.get(ContentModel.PROP_TITLE);

JSONObject obj = new JSONObject();

// put some data on it
obj.put(title,name);
/
// build a JSON string and send it back
String jsonString = obj.toString();
res.getWriter().write(jsonString);
}
catch(JSONException e)
{
throw new WebScriptException("Unable to serialize JSON");
}
}

在 webscript-context.xml 中定义脚本如下

    <bean id="webscript.fields.get" 
class="com.test.testa.demoamp.Fields"
parent="webscript">

</bean>

然后我创建一个配置 xml 文件 fields.get.desc.xml

<webscript>
<shortname>Fields</shortname>
<description>Hands back a little bit of JSON</description>
<url>/api/fields?nodeRef={nodeRef}</url>
<authentication>user</authentication>
<format default="json"></format>
<property name="serviceRegistry" ref="ServiceRegistry" />
</webscript>

当我从浏览器执行脚本时出现以下错误

http://localhost:8080/alfresco/service/api/fields?nodeRef=workspace://SpacesStore/f96e024a-0a13-4bf9-905e-2ae3f5bcf450

{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},

"message" : "java.lang.NullPointerException",
"exception" : "java.lang.NullPointerException",

"callstack" :
[
"" ,"java.lang.NullPointerException"
,"com.test.testa.demoamp.Fields_docx$$EPf3jZCD.execute(Fields_docx.java:94)"
,"com.test.testa.demoamp.Fields_docx$$DPf3jZCD.execute(Unknown Source)"
,"com.test.testa.demoamp.Fields_docx.execute(Fields_docx.java)"
,"org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:482)"
,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:457)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:551)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:619)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:399)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:280)"
,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)"
,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)"
,"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)"
,"javax.servlet.http.HttpServlet.service(HttpServlet.java:728)"
,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)"
,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
,"org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)"
,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)"
,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
,"org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)"
,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)"
,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)"
,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)"
,"org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)"
,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)"
,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)"
,"org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)"
,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)"
,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)"
,"org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)"
,"org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)"
,"org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)"
,"java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)"
,"java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)"
,"java.lang.Thread.run(Thread.java:745)"

],

"server" : "Community v5.0.0 (d r99759-b2) schema 8,022",
"time" : "Mar 10, 2016 6:12:10 PM"
}

我已经尝试了各种类型的身份验证,但都不起作用。缺少什么并且 noderef 为空?

最佳答案

您的 bean 定义需要更新以将 serviceregistry 注入(inject)您的 bean

 <bean id="webscript.fields.get" 
class="com.test.testa.demoamp.Fields"
parent="webscript">
<property name="serviceRegistry" ref="ServiceRegistry"/>
</bean>

希望这能解决您的问题。

对于每个依赖项注入(inject),您需要在上下文文件中引用条目并将 bean 声明为具有 getter setter 的属性。

关于java - Alfresco java webscript 的 ServiceRegistry 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35921898/

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