2017-07-16 56 views
1

在我的項目中,我創建了一些代理。其中傳輸類型爲tcp。 我的回答是如何使用wso2中的類中介發送響應作爲字符串esb

{ 
"BillingSystem": { 
    "request_id": "20114140080000011479122000", 
    "request_timestamp": "12102012121200", 
    "response_timestamp": "12102012121300", 
    "action": "AddSubscription", 
    "username": "Cellcard ", 
    "result_code": "0", 
    "result_desc": "Success" 
} 
} 

我使用類中介抓住這個響應,並創建WZ2OCS2:使用響應@ 1479122000#:1:14:14008:1。我需要發送此字符串到tcp客戶端。我在班上meditor

context.setProperty("responseClientValue", responseClientValue); 

集後在課堂調解員這個值我用的有效載荷工廠調停和調停財產後設置此字符串。

<payloadFactory description="" media-type="xml"> 
     <format> 
      <name xmlns="">$1</name> 
     </format> 
     <args> 
      <arg evaluator="xml" expression="get-property('responseClientValue')"/> 
     </args> 
</payloadFactory> 

物業中介

<property name="messageType" scope="axis2" type="STRING" value="application/text"/> 

當我運行項目它顯示XML代碼

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><name>WZ2OCS2:1:14:14008:1:@1479122000#</name></soapenv:Body></soapenv:Envelope>? 

這裏是我的代理服務

<?xml version="1.0" encoding="UTF-8"?> 
 
<proxy name="SurepayBillingErrorHandlingProxy" startOnLoad="true" transports="tcp" xmlns="http://ws.apache.org/ns/synapse"> 
 
    <target> 
 
     <inSequence> 
 
      <class description="" name="esb.cellcard.billing.SurepayMediator"/> 
 
      <property name="messageType" scope="axis2" type="STRING" value="application/json"/> 
 
      <send> 
 
       <endpoint key="SurpayBillingEP"/> 
 
      </send> 
 
     </inSequence> 
 
     <outSequence> 
 
      <class name="esb.cellcard.billing.ResponseRequestId"/> 
 
      <payloadFactory description="" media-type="xml"> 
 
       <format> 
 
        <name xmlns="">$1</name> 
 
       </format> 
 
       <args> 
 
        <arg evaluator="xml" expression="get-property('responseClientValue')"/> 
 
       </args> 
 
      </payloadFactory> 
 
      <property name="messageType" scope="axis2" type="STRING" value="application/text"/> 
 
      <send/> 
 
     </outSequence> 
 
     <faultSequence/> 
 
    </target> 
 
    <parameter name="transport.tcp.responseClient">true</parameter> 
 
    <parameter name="transport.tcp.inputType">string</parameter> 
 
    <parameter name="transport.tcp.recordDelimiter">?</parameter> 
 
    <parameter name="transport.tcp.contentType">text/plain</parameter> 
 
    <parameter name="transport.tcp.port">6050</parameter> 
 
    <parameter name="transport.tcp.recordDelimiterType">character</parameter> 
 
</proxy>

我怎樣才能得到字符串值。謝謝

回答

0

更改payloadFactory這樣的:

<payloadFactory> 
    <format> 
     <text xmlns="http://ws.apache.org/commons/ns/payload">$1</text> 
    </format> 
    <args> 
     <arg evaluator="xml" expression="$ctx:responseClientValue"/> 
</payloadFactory> 

更改屬性爲messageType這樣的:

<property name="messageType" scope="axis2" type="STRING" value="text/plain"/> 

(見axis2.xml,默認情況下,PlainTextFormatter類與text/plain的相關:<messageFormatter contentType="text/plain" class="org.apache.axis2.format.PlainTextFormatter"/>

+0

謝謝讓米歇爾。 – Dev4World

+0

@ Jean-Mechil。當我通過tcp客戶端發送請求時,我將分隔符添加到請求中。前 - :請求+「?」但是當響應分隔符附帶響應時。如WZ2OCS2 ?.如何從響應中刪除該分隔符。謝謝 – Dev4World