如何使用wso2 esb中的类中介将响应作为String发送

时间:2017-07-16 20:07:45

标签: wso2esb

在我的项目中,我创建了一些代理。传输类型是tcp 。 我的回答是

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

我使用类介体捕获此响应并使用该响应创建WZ2OCS2:1:14:14008:1:@ 1479122000#。我需要将此字符串发送到 tcp客户端。我在类meditor中设置了这个String

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>

我怎样才能获得字符串值。谢谢

1 个答案:

答案 0 :(得分: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"/>