2014-07-14 69 views
1

一個JSON我有一個簡單的流,接收到REST返回數據庫連接器的數據,但沒有任何相應的數據被輸入到所述流騾ESB,在像格式

以下是XML:

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

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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" version="EE-3.5.0" 
    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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> 
    <db:generic-config name="Generic_Database_Configuration" url="jdbc:db2://localhost:50000/TEST:user=instuid;password=instpw;" driverClassName="com.ibm.db2.jcc.DB2Driver" doc:name="Generic Database Configuration"/> 
    <flow name="test2Flow1" doc:name="test2Flow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/> 
     <db:select config-ref="Generic_Database_Configuration" doc:name="Database" doc:description="test"> 
      <db:parameterized-query><![CDATA[SELECT ACCTNUM FROM xxx.ACCOUNT]]></db:parameterized-query> 
     </db:select> 
    </flow> 
</mule> 

從命令行的SQL(騾以外)返回以下結果:

db2 => SELECT ACCTNUM FROM xxx.ACCOUNT 

ACCTNUM 
---------- 
11111 
22222 

然後,流程執行完全配置的數據庫連接器,該數據10被傳遞到鄰utbound http連接器:

C:\curl>curl http://localhost:8081 
¼φ ♣sr ¶java.util.LinkedList♀)S]J`ê"♥ xpw♦ ☻sr $org.mule.util.CaseInsensitive 
HashMap¥╤┘∩gE╬ ♥ xpw♀[email protected]  ► ☺t ACCTNUMt 
11111  xsq ~ ☻w♀[email protected]  ► ☺q ~ ♦t 
22222  xx 

...所以你可以看到它從表'11111'和'22222'獲得變量。

我還不知道現在該怎麼做。我想獲取數據庫連接器的結果,並返回字符串'11111'和'22222'。以類似JSON的格式,但我不知道該怎麼做

請問有人能告訴我最簡單的方法來做到這一點,也許會提供一個例子嗎?

感謝

回答

4

是你正常的時候....只要把一個目的是JSON變壓器的DB連接器後,在最後像<json:object-to-json-transformer doc:name="Object to JSON"/> ...看到以下內容: -

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

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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" version="EE-3.5.0" 
    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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> 
    <db:generic-config name="Generic_Database_Configuration" url="jdbc:db2://localhost:50000/TEST:user=instuid;password=instpw;" driverClassName="com.ibm.db2.jcc.DB2Driver" doc:name="Generic Database Configuration"/> 
    <flow name="test2Flow1" doc:name="test2Flow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/> 
     <db:select config-ref="Generic_Database_Configuration" doc:name="Database" doc:description="test"> 
      <db:parameterized-query><![CDATA[SELECT ACCTNUM FROM xxx.ACCOUNT]]></db:parameterized-query> 
     </db:select> 
    <json:object-to-json-transformer doc:name="Object to JSON"/> 
    </flow> 
</mule>