cancel
Showing results for 
Search instead for 
Did you mean: 

Probulem JavaScript API processTemplate

sugai
Champ in-the-making
Champ in-the-making
Smiley Sad Hi,

I could use the JavaScript API processTemplate on the Alfresco-community-tomcat-1.4.0 and 2.0.0.
Now, I have installed the Alfresco-community-tomcat-2.1.0.
The following script can not execute on Alfresco, only 2.1.0.
Input form<html><head><title>***** ex_listDocsSpace.html *****</title></head><body><form method="POST" action="http://vaio-sugai:8080/alfresco/command/script/execute" accept-charset="UTF-8" ><br>JavaScript call from HTML form<br><br><input type="text" name="scriptPath" size="100" value="/Company Home/User Homes/ex_listDocsSpace.js"><br><br><input type="text" name="spacePath" size="100" value="User Homes"><br><br><input type="text" name="templatePath" size="100" value="User Homes/ex_listDocsSpace.ftl"><br><br><input type="submit"></form></body></html>[JavaScript code]var arg = new Array();arg = args;var script = arg["scriptPath"];var spacePath = arg["spacePath"];var templatePath = arg["templatePath"];var result = "args check !" + "<br>";result +=  "arg[script] : "  + script + "<br>";result +=  "arg[spacePath] : "  + spacePath + "<br>";result +=  "arg[templatePath] : "  + templatePath + "<br><br>";   // 10space = userhome;var spaceNode = space.childByNamePath(spacePath);if ( spaceNode == null) {     result +=  "spaceNode not found !" + "<br>"; } else {     result += "spaceNode.name = " + spaceNode.name + "<br>";}// Get templateNode var templateNode = space.childByNamePath(templatePath);result += "templateNodeName = " + templateNode.name + "<br>";// set spaceNode to current spacespace = spaceNode;// Execute processTemplate var outString = new String("");outString +=  space.processTemplate(templateNode);result += outString + "<br>";                  result;[Template]<#– Renders list of all the documents in the Space –> <table> <#list space.children as child>    <#if child.isDocument>       <tr><td>${child.properties.name}</td></tr>    </#if> </#list> </table>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
    system error messages

    org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.TemplateException
    caused by:
    java.lang.NullPointerException
My PC is running Windows XP Home Edition Version 2002 Service Pack 2.
Are there any changes ?
Please advice me.
13 REPLIES 13

kevinr
Star Contributor
Star Contributor
Looks like the exception is coming from the Template service rather than the script service - can you execute the template by itself i.e. in the client or via URL? If so do you get the same error?

Thanks,

Kevin

sugai
Champ in-the-making
Champ in-the-making
Thank you for your quick answer.
I had tried your advice. Result is following.

can you execute the template by itself i.e. in the client ‍
I can execute the template any space in the web client , from the template  /Company%20Home/Data%20Dictionary/Presentation%20Templates/ex_listDocSpace.ftl

can you execute the template by itself i.e.  via URL?‍
I had tested 2 cases of URL content servlet execution.


Case1
http://crs-sugai:8080/alfresco/template?templatePath=/Company%20Home/Data%20Dictionary/Presentation%...

Case2
http://crs-sugai:8080/alfresco/template?templatePath=/Company%20Home/User%20Homes/ex_listDocSpace.ft...

The following same error(java.lang.IllegalArgumentException: Unable to resolve item Path) appeared.

java.lang.IllegalArgumentException: Unable to resolve item Path: /Company Home/Data Dictionary/Presentation Templates/ex_listDocSpace.ftl詳細をé‍‍‍‍‍‍

kevinr
Star Contributor
Star Contributor
The error:
java.lang.IllegalArgumentException: Unable to resolve item Path: /Company Home/Data Dictionary/Presentation Templates/ex_listDocSpace.ftl ‍‍‍
suggests that one of the folders in the path cannot be found - have you renamed or localised any of the folders names?

Thanks,

Kevin

sugai
Champ in-the-making
Champ in-the-making
Thank you for your suggestion.
I made a mistake. I have confirmed,TemplateCommandServlet works correctly.
However, processTemplate API does not yet work. I have made simple script for test.

JavaScript code (/Company Home/test_processTemplate.js)
var result = new String(""); var space = companyhome;var document = space.childByNamePath("doc_info.ftl");var template = space.childByNamePath("doc_info.ftl");result +=  document.processTemplate(template);result;‍‍‍‍‍‍‍‍

template (/Company Home/doc_info.ftl)
I copied doc_info.ftl from /Company Home/Data Dictionary/Presentation Templates to /Company Home.

execute ( via Script Command Servlet )

http://crs-sugai:8080/alfresco/command/script/execute?scriptPath=/Company%20Home/test_processTemplat...‍‍‍

This Script and template works correctly on the Alfresco-community-2.0.0.
But did'nt work on the Alfresco-community-2.1.0.
Error messages

org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)caused by:org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)caused by:org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)caused by:org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)caused by:org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)caused by:org.alfresco.service.cmr.repository.TemplateExceptioncaused by:java.lang.NullPointerExceptionShow Detailsorg.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)at org.alfresco.web.app.servlet.CommandServlet.service(CommandServlet.java:194)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)at java.lang.Thread.run(Thread.java:619)Caused by: org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:171)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)at $Proxy48.executeScript(Unknown Source)at org.alfresco.web.app.servlet.command.ExecuteScriptCommand.execute(ExecuteScriptCommand.java:103)at org.alfresco.web.app.servlet.command.ScriptCommandProcessor.process(ScriptCommandProcessor.java:146)at org.alfresco.web.app.servlet.CommandServlet.service(CommandServlet.java:159)… 15 moreCaused by: org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/e70c1871-5aa7-11dc-88c4-6b68314a45f1': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:146)at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:167)… 37 moreCaused by: org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:518)at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:142)… 38 moreCaused by: org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#11)at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1705)at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:157)at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:201)at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:64)at org.mozilla.javascript.gen.c2._c0(AlfrescoScript:11)at org.mozilla.javascript.gen.c2.call(AlfrescoScript)at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)at org.mozilla.javascript.gen.c2.call(AlfrescoScript)at org.mozilla.javascript.gen.c2.exec(AlfrescoScript)at org.mozilla.javascript.Context.evaluateString(Context.java:1144)at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:510)… 39 moreCaused by: org.alfresco.service.cmr.repository.TemplateExceptionat org.alfresco.repo.processor.TemplateServiceImpl.processTemplateString(TemplateServiceImpl.java:218)at org.alfresco.repo.processor.TemplateServiceImpl.processTemplateString(TemplateServiceImpl.java:229)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:238)at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)at $Proxy94.processTemplateString(Unknown Source)at org.alfresco.repo.jscript.ScriptNode.processTemplate(ScriptNode.java:1882)at org.alfresco.repo.jscript.ScriptNode.processTemplate(ScriptNode.java:1785)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:142)… 49 moreCaused by: java.lang.NullPointerExceptionat org.alfresco.repo.processor.TemplateServiceImpl.processTemplateString(TemplateServiceImpl.java:210)… 75 moreアプリケーションã‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

kevinr
Star Contributor
Star Contributor
One our of engineers has investigated and found the bug:
http://issues.alfresco.com/browse/AR-1731

Thanks for raising this!

Kevin

suleyman
Champ in-the-making
Champ in-the-making
Is it possible to run processTemplate in 2.1 final?
Is there a workaround for this problem? It's for me not possible to use a nightly build version.

sugai
Champ in-the-making
Champ in-the-making
I am waiting for the bug to be fixed.

thanks.

kevinr
Star Contributor
Star Contributor
It has been fixed: http://issues.alfresco.com/browse/CHK-1260
— TemplateServiceImpl.java    (revision 6672)+++ TemplateServiceImpl.java    (revision 6673)@@ -78,7 +78,11 @@      * @see org.alfresco.service.cmr.repository.TemplateService#getTemplateProcessor(java.lang.String)      */     public TemplateProcessor getTemplateProcessor(String engine)-    {+    {+        if (engine == null)+        {+           engine = this.defaultTemplateEngine;+        }         return this.processors.get(engine);     }‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks,

Kevin

suleyman
Champ in-the-making
Champ in-the-making
Thx for the fix. Do you have new compiled java class that I can use. I don't know much about java and eclipse. I have downloaded de sdk en opent it in ecplise but I can not edit it.

Sugai can you send me de class file when you change it?