GraalVm-无法像javascript对象一样解析Java复杂对象

时间:2018-12-18 10:39:31

标签: javascript java graalvm

我正在尝试从nashorn迁移到graalvm(java 11)。我有很多Java脚本。

描述->作为Maven库连接到Java项目org.graalvm.js:graal-sdk,js,js-scriptengine,org.graalvm.truffle:truffle-api。版本1.0.0-rc9。
创建的ScriptEngine类似于'new ScriptEngineManager()。getEngineByName(“ graal.js”)';
然后,您可以在地图中以数组形式创建地图,例如:
< br />

Map mapOuter = new HashMap();
Map mapInner = new HashMap();
List arrayInner = new ArrayList();

mapInner.put("1", 3);
arrayInner.add(mapInner);
mapOuter.put("2", arrayInner);

然后将mapOuter转换为ProxyObject,例如ProxyObject.fromMap(mapOuter);
使用以下代码评估测试javascript:

function test(param) {
   &nbsp;&nbsp;print(param["2"]);
   &nbsp;&nbsp;param["2"].forEach(function(inArray){
   &nbsp;&nbsp;&nbsp;&nbsp;print(inArray);
   &nbsp;&nbsp;});
}

将调用以下错误:

  

javax.script.ScriptException:org.graalvm.polyglot.PolyglotException:TypeError:对异物的INVOKE失败的原因是:不支持消息:INVOKE

所以问题是:如何使graalvm正确地将复杂的Java对象转换为javascript函数?

p.s。在这个例子中我想要的是像这样调用对象:

  

print(param [“ 2”] [0] [“ 1”]);

它打印我3。

我尝试过的事情
尝试将externalMap的每个成员解析为ProxyObject / ProxyArray。

正在做什么 如果您更改javascript,如:

  

print(param [“ 2”] [0] .get(“ 1”));

它将打印3;

1 个答案:

答案 0 :(得分:0)

当前(2018年12月)不支持使用 2018-12-19 15:35:51,999 ERROR i.xxxx.ExtractorTask [thread-1] Execption Encountered - org.springframework.data.mongodb.UncategorizedMongoDbException: Interrupted acquiring a permit to retrieve an item from the pool ; nested exception is com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107) at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2135) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1978) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1784) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1767) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:641) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:606) at org.springframework.data.mongodb.repository.query.MongoQueryExecution$SingleEntityExecution.execute(MongoQueryExecution.java:173) at org.springframework.data.mongodb.repository.query.MongoQueryExecution$ResultProcessingExecution.execute(MongoQueryExecution.java:411) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:94) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy121.findOneById(Unknown Source) at sun.reflect.GeneratedMethodAccessor1821.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy121.findOneById(Unknown Source) at in.xxxx.TypeAProcessor.createPersistObjectLists(**TypeAProcessor.java:125**) at in.xxxx.service.FetchService.process(FetchService.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:180) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:112) at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48) at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:174) at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:72) at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:47) at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:764) at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:708) at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.access$2500(KafkaMessageListenerContainer.java:230) at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer$ListenerInvoker.run(KafkaMessageListenerContainer.java:975) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.lang.Thread.run(Thread.java:745) Caused by: com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool at com.mongodb.internal.connection.ConcurrentPool.acquirePermit(ConcurrentPool.java:186) at com.mongodb.internal.connection.ConcurrentPool.get(ConcurrentPool.java:126) at com.mongodb.connection.DefaultConnectionPool.getPooledConnection(DefaultConnectionPool.java:258) at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:99) at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:88) at com.mongodb.connection.DefaultServer.getConnection(DefaultServer.java:86) at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:86) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:429) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:404) at com.mongodb.operation.FindOperation.execute(FindOperation.java:510) at com.mongodb.operation.FindOperation.execute(FindOperation.java:81) at com.mongodb.Mongo.execute(Mongo.java:836) at com.mongodb.Mongo$2.execute(Mongo.java:823) at com.mongodb.DBCursor.initializeCursor(DBCursor.java:870) at com.mongodb.DBCursor.hasNext(DBCursor.java:142) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1964) ... 49 more Caused by: java.lang.InterruptedException at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326) at java.util.concurrent.Semaphore.tryAcquire(Semaphore.java:409) at com.mongodb.internal.connection.ConcurrentPool.acquirePermit(ConcurrentPool.java:180) ... 64 more 访问Java Map的值。您需要将映射转换为[]才能使ProxyObject工作。就像您对[]对象所做的一样。

否则,这是一个普通的Java映射,您可以在其上调用mapOuter以获取该值。