Data Weaveを使用してXMLを変換し、既存のノードでは問題が発生しています。例えば、XMLMulesoft:既存のディープノードがない場合のデフォルト値
<a>
<b>
<c>
value
</c>
</b>
</a>
抽出{:$ .A、2:$のa.b、3:1の$ A.B.C}のすべてのノード時に正常に動作し、b及びcが存在します。
ノードbが空で、ノードcのデフォルト値を持つときを判断する方法は何ですか?
これは実際の例です。実際のデータには深度レベルが多く、各レベルは空である可能性があります。たぶん私は/ otherwiseを使うべきですが、各変数のデータ構造全体を繰り返す必要があります。ここで
ミュール流れです:
*******************************************************************************************************
* xml2flatSO * default * DEPLOYED *
*******************************************************************************************************
INFO 2016-09-30 13:57:29,271 [[xml2flatSO].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileIn\xml_in_good.xml
INFO 2016-09-30 13:57:37,892 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: {
"a": {
"b": {
"c": "GOOD"
}
}
}
INFO 2016-09-30 13:57:42,334 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.file.mule.default.dispatcher.546298364'. Object is: FileMessageDispatcher
INFO 2016-09-30 13:57:42,334 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.file.mule.default.dispatcher.546298364'. Object is: FileMessageDispatcher
INFO 2016-09-30 13:57:42,335 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.transport.file.FileConnector: Writing file to: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileOut\out.txt
INFO 2016-09-30 13:57:52,448 [[xml2flatSO].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileIn\xml_in_bad.xml
INFO 2016-09-30 13:57:55,979 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: {
"a": ""
}
ERROR 2016-09-30 13:58:16,403 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Exception while executing:
b: payload.a.b default {},
^
Type mismatch for 'Value Selector' operator
found :string, :name
required :datetime, :name or
required :localdatetime, :name or
required :object, :name or
required :time, :name or
required :array, :name or
required :date, :name or
required :localtime, :name or
required :period, :name
Payload : {
"a": ""
}
Payload Type : java.lang.String
Element : /xml2flatFlow/processors/3 @ xml2flatSO:xml2flat.xml:37 (Json2Json)
Element XML : <dw:transform-message metadata:id="15c2b229-fb5a-4430-be89-c446e79bfa2e" doc:name="Json2Json">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json" mimeType="application/json"></dw:input-payload>
<dw:set-payload>%dw 1.0%output application/json---{a: payload.a default {},b: payload.a.b default {},c: payload.a.b.c default ""}</dw:set-payload>
</dw:transform-message>
--------------------------------------------------------------------------------
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.UnexpectedOperationTypesException: Type mismatch for 'Value Selector' operator
found :string, :name
required :datetime, :name or
required :localdatetime, :name or
required :object, :name or
required :time, :name or
required :array, :name or
required :date, :name or
required :localtime, :name or
required :period, :name
at com.mulesoft.weave.engine.ast.OpNode$class.doExecuteAutoCoercion(OpNode.scala:79)
at com.mulesoft.weave.engine.ast.BinaryOpNode.doExecuteAutoCoercion(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.OpNode$class.doExecute(OpNode.scala:33)
at com.mulesoft.weave.engine.ast.BinaryOpNode.doExecute(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.BinaryOpNode.execute(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.selectors.NullSafeNode.doExecute(NullSafeNode.scala:16)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.selectors.NullSafeNode.execute(NullSafeNode.scala:10)
at com.mulesoft.weave.engine.ast.conditional.DefaultNode.doExecute(DefaultNode.scala:13)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.conditional.DefaultNode.execute(DefaultNode.scala:10)
at com.mulesoft.weave.engine.ast.structure.KeyValuePairNode.doExecute(KeyValuePairNode.scala:12)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.structure.KeyValuePairNode.execute(KeyValuePairNode.scala:10)
at com.mulesoft.weave.engine.ast.structure.ObjectNode$$anonfun$4.apply(DynamicObjectNode.scala:39)
at com.mulesoft.weave.engine.ast.structure.ObjectNode$$anonfun$4.apply(DynamicObjectNode.scala:38)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:742)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.doExecute(DynamicObjectNode.scala:38)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.execute(DynamicObjectNode.scala:28)
at com.mulesoft.weave.engine.ast.ValueNode$class.write(AstNode.scala:28)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.write(DynamicObjectNode.scala:28)
at com.mulesoft.weave.engine.Engine.write(Engine.scala:165)
at com.mulesoft.weave.engine.Engine.execute(Engine.scala:88)
at com.mulesoft.weave.engine.Engine.execute(Engine.scala:103)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy$$anonfun$execute$1.apply(DebugWeaveExecutorStrategy.scala:30)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy$$anonfun$execute$1.apply(DebugWeaveExecutorStrategy.scala:28)
at scala.Option.map(Option.scala:146)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy.execute(DebugWeaveExecutorStrategy.scala:28)
at com.mulesoft.weave.mule.WeaveMessageProcessor.execute(WeaveMessageProcessor.scala:117)
at com.mulesoft.weave.mule.WeaveMessageProcessor.process(WeaveMessageProcessor.scala:65)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:108)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.interceptor.AbstractEnvelopeInterceptor.processBlocking(AbstractEnvelopeInterceptor.java:58)
at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:123)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:208)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:201)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:200)
at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:53)
at org.mule.work.WorkerContext.run(WorkerContext.java:286)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
********************************************************************************
どれ提案:ここ
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="xml2flatFlow" doc:description="To run copy src/main/resources/*.xml files to src/test/resources/FileIn
Good working example is xml_in_good.xml
Issues:
1) Should be working with Streams but from Json2Flat there is no way to FileOut. "Load everything to memory" is required but it kills stream. What is the way to make it Stream and work with huge files?
2) FlatFile field have particular length. Transformation should cut the length. Instead it produces exception. Should be option oe way to force the length of the string.
Example: xml_in_bad_too_long.xml
3) Main issue - I cannot figure out how process empty nodes.
Example: xml_in_bad.xml
Provided example is simlpiest. In reality I have very long xpath like payload.a.b.c.d.e.f.g.h
I tried to do when/otherwise, default, h?, internal Java program - nothing works.
I believe that processor File2Json is not necessary but I'd added it to make sure XML processor have no influence on the flow. ">
<file:inbound-endpoint path="src\test\resources\FileIn" moveToDirectory="src\test\resources\FileProcessed" responseTimeout="10000" doc:name="FileIn"/>
<dw:transform-message metadata:id="24cbc998-ba7d-44f7-a3fa-cb502d352e87" doc:name="File2Json">
<dw:input-payload mimeType="application/xml"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<dw:transform-message metadata:id="15c2b229-fb5a-4430-be89-c446e79bfa2e" doc:name="Json2Json">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json" mimeType="application/json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
a: payload.a default {},
b: payload.a.b default {},
c: payload.a.b.c default ""
}]]></dw:set-payload>
</dw:transform-message>
<dw:transform-message metadata:id="8ef7c277-ec47-4564-9ece-eac11c27c891" doc:name="Json2Flat">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output text/plain schemaPath = "flatfile.ffd" , segmentIdent = ""
---
[{
field_0: payload.c default "---"
}]]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer doc:name="Load everythin to memory"/>
<file:outbound-endpoint path="src/test/resources/FileOut" outputPattern="out.txt" responseTimeout="10000" doc:name="FileOut"/>
</flow>
</mule>
はログがありますか?
良いアプローチですが、bがないとDWがエラーを生成します。私の実際のxpathはpayload.a.b.c.d.e.f.g.hに似ていて、これらのリンクのどれかが欠けている可能性があります。 – Alex
どのバージョンが使用されていますか。私のためにDWがうまく動作していてもbが欠けています。 – AnupamBhusari
最新のものバージョン:6.1.1 ビルドID:201609131828 同じ例を試してみますが、入力はです。 – Alex