WSO2:将CSV消息转换为json wso2 esb。在prolog中出现意外字符'“'(代码34)失败;预期'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WSO2:将CSV消息转换为json wso2 esb。在prolog中出现意外字符'“'(代码34)失败;预期'相关的知识,希望对你有一定的参考价值。

我试图使用数据映射器将csv转换为json。以下是我写的代理服务。

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="csvtojson" startOnLoad="true" transports="http https vfs" 
xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property expression="$body/*[1]" name="body" scope="default" type="OM"/>
<log level="full">
<property name="PropertyName" value="Message tobe fed to mapper"/>
</log>
<datamapper config="gov:datamapper/csvtojsonmapping.dmc" 
inputSchema="gov:datamapper/csvtojsonmapping_inputSchema.json" 
inputType="CSV" 
outputSchema="gov:datamapper/csvtojsonmapping_outputSchema.json" 
outputType="JSON"/>
<log level="full">
<property name="property_name" value="aftermapping"/>
</log>
<property name="ContentType" scope="axis2" type="STRING" 
value="application/json"/>
<log description="" level="full">
<property name="property_name" value="msgpropertyset as json"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="https://www.google.com/"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="transport.vfs.FileURI">file:///tmp/in</parameter>
<parameter name="transport.vfs.ContentType">text/csv</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter 
name="transport.vfs.MoveAfterFailure">file:///tmp/failure</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.Build">false</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///tmp/out</parameter>
</proxy>

已经包含在axis2.xml文件中的两个下面:

执行服务时,我收到以下错误:

[2018-08-30 18:38:44,535] [EI-Core] ERROR - VFSTransportListener Error 
processing File URI : file:///tmp/in/test.csv
org.apache.axiom.om.OMException: 
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '"' (code 
34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
    at 
 org.apache.axiom.om.impl.builder.StAXOMBuilder.next
(StAXOMBuilder.java:296)
at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope
(StAXSOAPModelBuilder.java:204)
    at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init> 
(StAXSOAPModelBuilder.java:154)
    at 
org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder
(AbstractOMMetaFactory.java:73)
    at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder
(AbstractOMMetaFactory.java:79)
    at 
org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder
(OMXMLBuilderFacto ry.java:196)
    at org.apache.axis2.builder.SOAPBuilder.processDocument
 (SOAPBuilder.java:65)
    at org.apache.synapse.transport.vfs.VFSTransportListener.processFile
 (VFSTransportListener.java:822)
    at 
  org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory
 (VFSTransportListener.java:477)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll
 (VFSTransportListener.java:188)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll
 (VFSTransportListener.java:134)
    at 
 org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run
 (AbstractPollingTransportListener.java:67)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run
 (NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker
 (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run
 (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
 Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: 
 Unexpected character '"' (code 34) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar
 (StreamScanner.java:639)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog
 (BasicStreamReader.java:2052)
    at com.ctc.wstx.sr.BasicStreamReader.next 
 (BasicStreamReader.java:1134)
    at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next
 (XMLStreamReaderWrapper.java:225)
    at 
  (DisallowDoctypeDeclStreamReaderWrapper.java:34)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext
 (StAXOMBuilder.java:681)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next
 (StAXOMBuilder.java:214)
    ... 15 more

这是我放在/ tmp / in文件夹中的内容的内容如下:

ContactType,FirstName,MiddleName,LastName,Email,PhoneNumber,Company,Address1,Address2,Address3,Zip,Country,FacsimileTelephoneNumber,PartnerFinanceID 1,ABC,A,CBD,test @ test.com,123456789,Test,200WS,300 WSD, 400tyu,125kji,世界,4567894585,假

请帮助您输入。如果您需要我身边的更多信息,请告诉我...........

答案

您可以通过为axis2.xml中的text / csv内容类型配置org.apache.axis2.format.PlainTextBuilder和org.apache.axis2.format.PlainTextFormatter来访问CSV的请求/响应有效内容中的内容。例如:

<messageBuilder contenttype="text/csv" class="org.apache.axis2.format.PlainTextBuilder"/>
<messageFormatter contenttype="text/csv" class="org.apache.axis2.format.PlainTextFormatter"/>

请参考 - https://docs.wso2.com/display/ESB500/Working+with+Message+Builders+and+Formatters#WorkingwithMessageBuildersandFormatters-Handlingtext/csvmessages

以上是关于WSO2:将CSV消息转换为json wso2 esb。在prolog中出现意外字符'“'(代码34)失败;预期'的主要内容,如果未能解决你的问题,请参考以下文章

WSO2-MI

WSO2-MI

将 xml 转换为 json 的 WSO2 ESB 问题

WSO2:wso2中的xml到json数据映射esb:json消息包含在soap信封中

WSO2 Enterprise Integrator 6.6.0 使用 XSLT 将 XML 响应转换为 Json

WSO2 ESB 无法将完整的 JSON 数据转换为 XML