WSO2 ESB使用文本/普通内容调用REST API

WSO2 ESB使用文本/普通内容调用REST API,rest,curl,wso2esb,Rest,Curl,Wso2esb,我需要在主体内容中使用纯文本调用RESTAPI 卷曲命令 curl-X POSThttp://mydomain.test.corp/token -H“内容类型:文本/普通”-d“授权类型=密码和用户名=测试密码和密码=123123” 正在给我想要的输出。如何将其构建为代理服务。我考虑使用payload mediator,但它只接受媒体类型xml/json 我无法在代理服务xml中保存grant\u type=password&username=testUName&password=123123,

我需要在主体内容中使用纯文本调用RESTAPI

卷曲命令

curl-X POSThttp://mydomain.test.corp/token -H“内容类型:文本/普通”-d“授权类型=密码和用户名=测试密码和密码=123123”

正在给我想要的输出。如何将其构建为代理服务。我考虑使用payload mediator,但它只接受媒体类型xml/json

我无法在代理服务xml中保存
grant\u type=password&username=testUName&password=123123
,因为我认为是带符号的

非常感谢您的帮助


谢谢。

使用payload mediator并构建包含纯文本作为此节点值的SOAP消息:

替换为
&或使用CDATA

指定消息类型(以便使用适当的messageFormatter):


只需发送此消息

完整样本:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" startOnLoad="true" trace="disable">
   <description/>
   <target>
      <inSequence>
         <payloadFactory media-type="xml">
            <format>
               <text xmlns="http://ws.apache.org/commons/ns/payload"><![CDATA[grant_type=password&username=testUName&password=123123]]></text>
            </format>
            <args/>
         </payloadFactory>
         <property name="messageType" value="text/plain" scope="axis2" type="STRING"/>
         <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
         <send>
            <endpoint>
               <address uri="http://localhost:8888/MockJSP.jsp"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
</proxy>

使用负载中介并构建一条SOAP消息,其中包含您的纯文本作为此节点的值:

替换为
&或使用CDATA

指定消息类型(以便使用适当的messageFormatter):


只需发送此消息

完整样本:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" startOnLoad="true" trace="disable">
   <description/>
   <target>
      <inSequence>
         <payloadFactory media-type="xml">
            <format>
               <text xmlns="http://ws.apache.org/commons/ns/payload"><![CDATA[grant_type=password&username=testUName&password=123123]]></text>
            </format>
            <args/>
         </payloadFactory>
         <property name="messageType" value="text/plain" scope="axis2" type="STRING"/>
         <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
         <send>
            <endpoint>
               <address uri="http://localhost:8888/MockJSP.jsp"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
</proxy>


非常感谢您的评论。当我使用
时,有效负载按原样运行(带有符号)
grant\u type=password&;用户名=testUName&;password=123123
这会导致错误响应。您可以尝试使用CDATA?您好,CDATA也可以将&;转换为&;这对我来说很有用:我用samplesorry Jean更新了我的答案,对我来说是amp;正在被记录,是否有任何与此相关的synapse属性启用?非常感谢您的评论。当我使用
时,有效负载按原样运行(带有符号)
grant\u type=password&;用户名=testUName&;password=123123
这会导致错误响应。您可以尝试使用CDATA?您好,CDATA也可以将&;转换为&;这对我来说很有用:我用samplesorry Jean更新了我的答案,对我来说是amp;正在被记录,是否有与此相关的synapse属性启用?