向Alfresco Sites API提交JSON时出现500错误
我正在尝试通过网站的API来创建一个站点(显然是这样 :-)) 我发送了以下内容:
payload={'description':'My description', 'visibility':'PUBLIC',
'site-preset':'site-dashboard','title':'My Site name', "shortName":'my-site-name'}
作为:
requests.post('http://<myserver>:8080/alfresco/service/api/sites',
auth=('admin','XXXXX'), data=json.dumps(payload))
用Python写的。我收到了一个500错误,下面有详细信息。我还需要在请求中添加什么才能让这个工作呢?我找不到相关文档,除了这个链接:http://docs.alfresco.com/3.4/references/RESTful-SiteSitesPost.html,而且我一直在使用这个例子:https://forums.alfresco.com/forum/developer-discussions/alfresco-api/create-site-alfresco-using-open-cmis-extension-07312013,但是我定义的内容比这些要多。
下面明确指出site.shortName没有定义,那么我应该如何在我传给站点API的JSON中定义shortName,以便alfresco的站点API能够识别它呢?任何文档的参考也非常欢迎。
错误日志如下:
{u'callstack': [u'',
u'freemarker.core.InvalidReferenceException: Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.',
u'freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)',
u'freemarker.core.Expression.getStringValue(Expression.java:118)',
u'freemarker.core.AddConcatExpression._getAsTemplateModel(AddConcatExpression.java:98)',
u'freemarker.core.Expression.getAsTemplateModel(Expression.java:89)',
u'freemarker.core.ListLiteral.getModelList(ListLiteral.java:119)',
u'freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:91)',
u'freemarker.core.Expression.getAsTemplateModel(Expression.java:89)',
u'freemarker.core.Expression.getStringValue(Expression.java:93)',
u'freemarker.core.DollarVariable.accept(DollarVariable.java:76)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.EscapeBlock.accept(EscapeBlock.java:84)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.Macro$Context.runMacro(Macro.java:172)',
u'freemarker.core.Environment.visit(Environment.java:614)',
u'freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.Macro$Context.runMacro(Macro.java:172)',
u'freemarker.core.Environment.visit(Environment.java:614)',
u'freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.MixedContent.accept(MixedContent.java:92)',
u'freemarker.core.Environment.visit(Environment.java:221)',
u'freemarker.core.Environment.process(Environment.java:199)',
u'org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:218)',
u'org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:896)',
u'org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)',
u'org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)',
u'org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:429)',
u'org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:452)',
u'org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:491)',
u'org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:529)',
u'org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:341)',
u'org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)',
u'org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)',
u'org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)',
u'javax.servlet.http.HttpServlet.service(HttpServlet.java:727)',
u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)',
u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
u'org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)',
u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)',
u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
u'org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)',
u'org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)',
u'org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)',
u'org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)',
u'org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)',
u'org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)',
u'org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)',
u'org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)',
u'org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)',
u'org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)',
u'org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)',
u'org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)',
u'org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)',
u'org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)',
u'java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)',
u'java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)',
u'java.lang.Thread.run(Thread.java:724)',
u"org.alfresco.service.cmr.repository.TemplateException: 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:222)',
u"org.springframework.extensions.webscripts.WebScriptException: 06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)'],
u'exception': u"org.springframework.extensions.webscripts.WebScriptException - 06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'message': u"06020018 Wrapped Exception (with status template): 06020108 Error during processing of the template 'Expression site.shortName is undefined on line 9, column 56 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.",
u'server': u'Community v4.2.0 (r63893-b12) schema 6,033',
u'status': {u'code': 500,
u'description': u'An error inside the HTTP server which prevented it from fulfilling the request.',
u'name': u'Internal Error'},
u'time': u'02-Jul-2014 15:15:01'}
更新:
在部分感谢Jeff的回答后,我通过在仓库中创建一个可用的站点,然后使用enable-site.get.js(可以在网上搜索)来完成这个过程,成功创建了一个可用的站点。太棒了,一个可用的站点!关键是要在JavaScript层调用siteData.newPreset("site-dashboard", )(如果我理解错了,请有人纠正我),以便在AVM存储中生成所需的XML,这样站点才能使用。create-site应该能做到这一点;不过我还没有成功,所以我采用了这个两步的过程。很多人似乎已经成功使用create-site了。
create-site需要OAuth认证。我之前提到的错误是因为没有正确传递格式化的JSON;我用curl(Jeff Potts建议的)和Postman(一个Chromium应用)进行了多次测试。现在我很开心(虽然我仍然不明白为什么create-site没有任何反应,不过我已经找到了解决方案)。
1 个回答
首先,要知道成功调用这个方法并不会让你的Alfresco Share网站正常运行。这一点在site.post这个网页脚本的文档中有说明,你可以在这里找到相关信息:
http://localhost:8080/alfresco/s/script/org/alfresco/repository/site/sites.post
如果你不打算创建一个可以正常使用的Alfresco Share网站,但还是想在存储层上创建网站的文件夹结构(这个网页脚本就是干这个的),那么你需要提供的内容应该是这样的:
{"title":"Test Site 1","visibility":"PUBLIC","description":"","sitePreset":"site-dashboard","shortName":"test-site-1"}
注意,这里用的是“sitePreset”,而不是你最开始用的“site-preset”。
当我在本地的4.2.f服务器上使用以下curl命令调用这个方法时,我得到了成功的响应:
curl -uadmin:admin -X POST "http://localhost:8080/alfresco/service/api/sites" -H "content-type: application/json" -d@/var/tmp/site.json
截至4.2.f版本,目前没有支持的方式可以通过编程来创建一个Share网站。