0

我尝试在 Alfresco Enterprise 4.1.5 的 javascript 控制台中使用带有 json 字符串或 json 对象作为参数的jsonUtils.toObject方法,并得到以下错误。

参考:

http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2Fapi-ws-obj-jsonUtils.html

toObject(jsonString) 接受 JSON 字符串并将其转换为原生 JavaScript 对象。

toObject(jsonObject) 获取 JSON 对象并将其转换为原生 JavaScript 对象。

测试 1

var jsonString = '{"test": "test"}';
logger.log( jsonUtils.toObject(jsonString) );

错误:

500 Internal Error
An error inside the HTTP server which prevented it from fulfilling the request.
10080038 Wrapped Exception (with status template): 10080143 Failed to execute script 'Javascript Console Script': 10080142 TypeError: Cannot find default value for object. (fb91e06fb1303a88bc57085eaaf9692f.js#2)

Wrapped Exception (with status template): 10080063 Failed to execute script 'Javascript Console Script': 10080062 TypeError: Cannot find default value for object. (b7b11bfd779a718cabdce9ea9162012f.js#5)
 org.springframework.extensions.webscripts.WebScriptException: 10080013 Wrapped Exception (with status template): 10080063 Failed to execute script 'Javascript Console Script': 10080062 TypeError: Cannot find default value for object. (b7b11bfd779a718cabdce9ea9162012f.js#5)
    at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)
    at de.fme.jsconsole.ExecuteWebscript.executeScriptContent(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.access$100(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$2.execute(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$2.execute(Unknown Source)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:401)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:291)
    at de.fme.jsconsole.ExecuteWebscript.runWithTransactionIfNeeded(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.access$000(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$1.doWork(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$1.doWork(Unknown Source)
    at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
    at de.fme.jsconsole.ExecuteWebscript.runScriptWithTransactionAndAuthentication(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.execute(Unknown Source)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:365)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:517)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.alfresco.scripts.ScriptException: 10080063 Failed to execute script 'Javascript Console Script': 10080062 TypeError: Cannot find default value for object. (b7b11bfd779a718cabdce9ea9162012f.js#5)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:202)
    at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:212)
    at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:174)
    at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
    ... 36 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: 10080062 TypeError: Cannot find default value for object. (b7b11bfd779a718cabdce9ea9162012f.js#5)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:516)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:198)
    ... 39 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for object. (b7b11bfd779a718cabdce9ea9162012f.js#5)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
    at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3368)
    at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:758)
    at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:677)
    at org.mozilla.javascript.ScriptRuntime.toString(ScriptRuntime.java:707)
    at org.mozilla.javascript.NativeJavaObject.coerceTypeImpl(NativeJavaObject.java:633)
    at org.mozilla.javascript.Context.jsToJava(Context.java:1705)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:209)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
    at org.mozilla.javascript.gen.c19._c0(b7b11bfd779a718cabdce9ea9162012f.js:5)
    at org.mozilla.javascript.gen.c19.call(b7b11bfd779a718cabdce9ea9162012f.js)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
    at org.mozilla.javascript.gen.c19.call(b7b11bfd779a718cabdce9ea9162012f.js)
    at org.mozilla.javascript.gen.c19.exec(b7b11bfd779a718cabdce9ea9162012f.js)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:492)         

测试 2

var jsonString = "{'test': 'test'}"; 
logger.log( jsonUtils.toObject(jsonString) );

错误:

500 Internal Error
An error inside the HTTP server which prevented it from fulfilling the request.
10080036 Wrapped Exception (with status template): 10080132 Failed to execute script 'Javascript Console Script': null

org.springframework.extensions.webscripts.WebScriptException: 10080037 Wrapped Exception (with status template): 10080138 Failed to execute script 'Javascript Console Script': null
    at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)
    at de.fme.jsconsole.ExecuteWebscript.executeScriptContent(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.access$100(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$2.execute(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$2.execute(Unknown Source)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:401)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:291)
    at de.fme.jsconsole.ExecuteWebscript.runWithTransactionIfNeeded(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.access$000(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$1.doWork(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript$1.doWork(Unknown Source)
    at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
    at de.fme.jsconsole.ExecuteWebscript.runScriptWithTransactionAndAuthentication(Unknown Source)
    at de.fme.jsconsole.ExecuteWebscript.execute(Unknown Source)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:365)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:517)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.alfresco.scripts.ScriptException: 10080138 Failed to execute script 'Javascript Console Script': null
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:202)
    at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:212)
    at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:174)
    at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
    ... 36 more
Caused by: java.lang.NullPointerException
    at org.springframework.extensions.webscripts.json.JSONUtils.toObject(JSONUtils.java:138)
    at org.springframework.extensions.webscripts.json.JSONUtils.toObject(JSONUtils.java:118)
    at sun.reflect.GeneratedMethodAccessor582.invoke(Unknown Source)
    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:155)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
    at org.mozilla.javascript.gen.c48._c0(9070d44753d964f375056b15cfef5a86.js:7)
    at org.mozilla.javascript.gen.c48.call(9070d44753d964f375056b15cfef5a86.js)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
    at org.mozilla.javascript.gen.c48.call(9070d44753d964f375056b15cfef5a86.js)
    at org.mozilla.javascript.gen.c48.exec(9070d44753d964f375056b15cfef5a86.js)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:492)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:198)
    ... 39 more 

测试 3

var jsonString = {'test': 'test'};
logger.log( jsonUtils.toObject(jsonString) );  

错误:

500 Internal Error
An error inside the HTTP server which prevented it from fulfilling the request.
10080041 Wrapped Exception (with status template): 10080162 Failed to execute script 'Javascript Console Script': null
4

1 回答 1

1

您不能在 JSON 字符串中使用单引号,必须使用双引号。因此,您在上面的测试 1中的代码应该可以在您在控制台之外运行的 Web 脚本中运行。

var jsonString = '{"test": "test"}';
logger.log( jsonUtils.toObject(jsonString) );

当在控制台中运行相同的代码时,您仍然会抛出异常,即

10080062 TypeError:找不到对象的默认值。(b7b11bfd779a718cabdce9ea9162012f.js#5)

这看起来特定于JavaScript 控制台,所以请在那里提出问题

哦,显然你可以在此期间继续使用eval()。如果您从 Alfresco 来源或您控制的来源获取数据,那么这是相对安全的。

于 2013-11-26T15:19:06.227 回答