【问题标题】:how to send response as String using class mediator in wso2 esb如何使用 wso2 esb 中的类调解器将响应作为字符串发送
【发布时间】:2017-07-16 20:07:45
【问题描述】:

在我的项目中,我创建了一些代理。传输类型是 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 客户端。我在班级调解员中设置了这个字符串

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>

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

【问题讨论】:

    标签: wso2esb


    【解决方案1】:

    像这样改变你的payloadFactory:

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

    像这样更改属性消息类型:

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

    (见axis2.xml,默认情况下PlainTextFormatter类关联text/plain:&lt;messageFormatter contentType="text/plain" class="org.apache.axis2.format.PlainTextFormatter"/&gt;

    【讨论】:

    • @Jean-Mechil。当我通过 tcp 客户端发送请求时,我将分隔符添加到请求中。例如-:请求+“?” .但是当来到响应分隔符附加响应时。作为WZ2OCS2?。如何从响应中删除该分隔符。谢谢
    猜你喜欢
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2023-03-24
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多