我在露天创造了一体化放大器。内部repo-amp l已经创建了一个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>
我创建了一个config 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>
当我从浏览器执行脚本时,我收到以下错误
{
"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为空?
答案 0 :(得分:4)
您的bean定义需要更新以将serviceregistry注入您的bean
<bean id="webscript.fields.get"
class="com.test.testa.demoamp.Fields"
parent="webscript">
<property name="serviceRegistry" ref="ServiceRegistry"/>
</bean>
希望这可以解决您的问题。
对于每个依赖注入,您需要在上下文文件中引用条目,并将bean声明为具有getter setter的属性。