【问题标题】:Error when trying to create custom Json to XML transformer in Mule尝试在 Mule 中创建自定义 Json 到 XML 转换器时出错
【发布时间】:2017-06-02 07:13:11
【问题描述】:

我正在尝试在 mule(自定义转换器)中创建自定义 Json 到 XML 的转换,它只是一对一的直接映射值,而不是复杂的转换。

这是我的流程:

<?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>

我正在使用这些文件来配置我的 Json to XML 组件

jsonFile.json:

{
  "inData": "value"
}

xml 文件:outData.xml

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

设置元数据:

现在我部署应用程序时没有任何问题,

但是当我使用邮递员发送带有有效负载的 POST 数据时我收到了这些错误:

这是控制台的完整输出:

*******************************************************************************************************
*            - - + 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)

知道导致错误的原因吗?

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

注意:

我正在尝试创建此自定义转换器,因为我现在只使用Mule server 3.8.1 CE,我将很快获得企业版版本,这就是我尝试在社区版服务器中部署的原因时间。

【问题讨论】:

    标签: json xml mule anypoint-studio transformer


    【解决方案1】:

    请参考以下链接创建自定义 json 到 xml 转换器

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

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多