简体   繁体   English

尝试在Mule中创建自定义Json到XML转换器时出错

[英]Error when trying to create custom Json to XML transformer in Mule

I'm trying to create a custom Json to XML conversion in mule (custom transformer), its just a one to one direct mapping values, not a complex transformation. 我正在尝试在m子(自定义转换器)中创建自定义Json到XML的转换,它只是一对一的直接映射值,而不是复杂的转换。

here is my flow: 这是我的流程:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/test" doc:name="HTTP Listener Configuration"/>
    <flow name="test_finalFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <json:json-to-xml-transformer metadata:id="57c0cd3d-ece4-48fe-9adf-79fc36a31b12" doc:name="JSON to XML"/>
        <logger level="INFO" doc:name="Logger"/>
    </flow>
</mule>

在此处输入图片说明

I'm using theses files to configure my Json to XML component 我正在使用这些文件将Json to XML配置Json to XML组件

jsonFile.json: jsonFile.json:

{
  "inData": "value"
}

xml file: outData.xml xml文件:outData.xml

<?xml version='1.0' encoding='UTF-8'?>
<root>
    <outData>someValue</outData>
</root>

setting the metadata: 设置元数据:

在此处输入图片说明

在此处输入图片说明

right now when I deploy the application I do not have any problem, 现在,当我部署应用程序时,我没有任何问题,

but when I use postman to send a POST data with payload I got these errors: 但是当我使用邮递员发送带有有效载荷的POST数据时, 出现以下错误:

在此处输入图片说明

and this is the full output of the console: 这是控制台的完整输出:

*******************************************************************************************************
*            - - + APPLICATION + - -            *       - - + DOMAIN + - -       * - - + STATUS + - - *
*******************************************************************************************************
* test_final                                    * default                        * DEPLOYED           *
*******************************************************************************************************

ERROR 2017-01-17 21:23:29,014 [[test_final].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : java.io.IOException: Illegal character: <i> (javax.xml.stream.XMLStreamException)
Payload               : org.glassfish.grizzly.utils.BufferInputStream@526ed3db
Transformer           : JsonToXml{this=6993c8df, name='JsonToString', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.String, mimeType='text/xml', encoding='null'}, sourceTypes=[SimpleDataType{type=java.lang.String, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.InputStream, mimeType='*/*', encoding='null'}, SimpleDataType{type=[B, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.Reader, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.net.URL, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.File, mimeType='*/*', encoding='null'}]}
Element               : /test_finalFlow/processors/0 @ test_final:test_final.xml:13 (JSON to XML)
Element XML           : <json:json-to-xml-transformer metadata:id="57c0cd3d-ece4-48fe-9adf-79fc36a31b12" doc:name="JSON to XML"></json:json-to-xml-transformer>
--------------------------------------------------------------------------------
Root Exception stack trace:
java.io.IOException: Illegal character: <i>
    at de.odysseus.staxon.json.stream.impl.Yylex.yylex(Yylex.java:641)
    at de.odysseus.staxon.json.stream.impl.Yylex.nextSymbol(Yylex.java:271)
    at de.odysseus.staxon.json.stream.impl.JsonStreamSourceImpl.next(JsonStreamSourceImpl.java:107)
    at de.odysseus.staxon.json.stream.impl.JsonStreamSourceImpl.peek(JsonStreamSourceImpl.java:250)
    at de.odysseus.staxon.json.JsonXMLStreamReader.consume(JsonXMLStreamReader.java:128)
    at de.odysseus.staxon.json.JsonXMLStreamReader.consume(JsonXMLStreamReader.java:161)
    at de.odysseus.staxon.base.AbstractXMLStreamReader.initialize(AbstractXMLStreamReader.java:216)
    at de.odysseus.staxon.json.JsonXMLStreamReader.<init>(JsonXMLStreamReader.java:65)
    at de.odysseus.staxon.json.JsonXMLInputFactory.createXMLStreamReader(JsonXMLInputFactory.java:139)
    at de.odysseus.staxon.json.JsonXMLInputFactory.createXMLStreamReader(JsonXMLInputFactory.java:120)
    at de.odysseus.staxon.json.JsonXMLInputFactory.createXMLStreamReader(JsonXMLInputFactory.java:44)
    at org.mule.module.json.transformers.JsonToXml.doTransform(JsonToXml.java:55)
    at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:415)
    at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:366)
    at org.mule.DefaultMuleMessage.transformMessage(DefaultMuleMessage.java:1589)
    at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:1488)
    at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1462)
    at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1454)
    at org.mule.transformer.AbstractTransformer.process(AbstractTransformer.java:114)
    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:98)
    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.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
    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:98)
    at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
    at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:55)
    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)

Any idea about what causing the error ? 关于导致错误的原因有任何想法吗?

java.io.IOException: Illegal character: i ? java.io.IOException:非法字符:i?

Note: 注意:

I'm trying to create this custom transformer because I'm using just Mule server 3.8.1 CE right now , I'll get access soon to an enterprise edition version that's why I'm trying to deploy in a community edition server at this time. 我正在尝试创建此自定义转换器,因为我现在仅使用Mule server 3.8.1 CE ,因此我很快就可以访问企业版版本,这就是为什么我要在社区版服务器中进行部署的原因时间。

please refer the below link for creating a custom json to xml transformer 请参考以下链接以创建自定义json到xml转换器

https://docs.mulesoft.com/mule-user-guide/v/3.6/creating-custom-transformers https://docs.mulesoft.com/mule-user-guide/v/3.6/creating-custom-transformers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM