English 中文(简体)
Mule - 临时返回JSON和XML?
原标题:Mule - Returning in JSON and XML on runtime..?

在穆莱,目前我使用一个“JavaObject ToJSON”习俗变压器(作为反应变压器),将一个POJO改为“JSON”,即我的构成部分类别回归一个 Java目标(ListHashMap),这一变压器将其转换成“JSON”,并将结果退回。

我的法典如下:

<flow name="OfferingDetails">
    <http:inbound-endpoint address="http://localhost:1212/jcore/offering/details" 
transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJSON">  
    </http:inbound-endpoint>

    <component class="main.java.com.raman.jcore.OfferingDetails"/>
</flow>

现今 我想回头来谈谈XML的结果。 为此,我可以使用另一个能够以类似方式做到的“JavaObject ToXML”习俗变压器。


But my query how can i do this dynamically. Like if i give choice to Client on how it wants the data. And he can hit the URL like

  • "http://localhost:1212/jcore/offering/details/?response=json"
  • "http://localhost:1212/jcore/offering/details.json/"

页: 1

  • "http://localhost:1212/jcore/offering/details/?response=xml"
  • "http://localhost:1212/jcore/offering/details.xml/

这样一来,就可以在<><>>><>>> 定期<><><><>/strong>上更换变压器,并将结果退回到相应的标签上。 是否有办法这样做?

还是除了变换者外,任何其他工作?

请帮助我。 我是幸运的。

最佳回答

在应对阶段使用选择路径信息处理器选择正确的变压器。

部分内容如下:

<flow name="OfferingDetails">
  <http:inbound-endpoint address="http://localhost:1212/jcore/offering/details"
                         transformer-refs="HttpParams" />  

  <component class="main.java.com.raman.jcore.OfferingDetails"/>

  <response>
    <choice>
      <when expression="message.getInboundProperty( http.request.path ).contains( json )" evaluator="groovy">
        <transformer ref="JavaObjectToJSON" />
      </when>
      <otherwise>
        <transformer ref="JavaObjectToXML" />
      </otherwise>
    </choice>
  <response>
</flow>
问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签