【问题标题】:Transform response to plain-text using wso2 esb 4.0.6使用 wso2 esb 4.0.6 将响应转换为纯文本
【发布时间】:2013-05-12 13:57:34
【问题描述】:

我是 web 服务的新手,不知何故,我使用 wso2 esb 4.0.6 通过 http/https 创建了一个简单的 web 服务。现在我的要求是从响应中删除标签,即我需要纯文本作为响应,下面的代码 sn-ps 将让您简要了解我的要求。

<case regex="POST">
   <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
       <enrich>
     <source type="inline" clone="true">
         <success xmlns="">Your request for subscription is being processed.</success>
     </source>
     <target type="body"/>
    </enrich>
     <header name="To" action="remove"/>
      <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
      <property name="RESPONSE" value="true" scope="default" type="STRING"/>
      <property name="ContentType" value="text/plain" scope="axis2"/>
</case>

我能够得到以下回复&lt;success&gt;Your request for subscription is being processed.&lt;/success&gt;

我只想从响应中删除&lt;success&gt; &lt;/success&gt; 标签。

提前致谢

【问题讨论】:

    标签: web-services axis2 wso2 wso2esb synapse


    【解决方案1】:

    可能这有点晚了,但我最近也遇到了这个问题,下面是如何让它发挥作用。

    1. 确保在 ESB/repository/conf/axis2/axis2.xml 中启用了 plainTextFormatter。
    2. 在你的代理服务中设置'messageType'属性如下图

    3. 添加有效负载文本元素。请参考下面给出的示例代理服务的出序列

    <outSequence>
             <payloadFactory>
                <format>
                   <ms11:text xmlns:ms11="http://ws.apache.org/commons/ns/payload">$1</ms11:text>
                </format>
                <args>
                   <arg xmlns:ns="http://www.wso2.org/types" expression="$body/ns:greetResponse/return/text()"/>
                </args>
             </payloadFactory>
             <property name="messageType" value="text/plain" scope="axis2"/>
             <log level="full"/>
             <send/>
          </outSequence>
    

    在这种情况下,我从后端服务 (HelloService) 的响应如下。

    <?xml version='1.0' encoding='utf-8'?> 
      <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> 
      <soapenv:Body> 
        <ns:greetResponse xmlns:ns="http://www.wso2.org/types"> 
          <return>Hello World, Test !!!</return> 
       </ns:greetResponse> 
     </soapenv:Body> 
    </soapenv:Envelope> 
    

    查看下面使用 curl 命令的 GET 请求的请求和响应

    curl -X GET "http://localhost:8280/services/TestProxy/greet?name=Test" -v 
    * About to connect() to localhost port 8280 (#0) 
    * Trying 127.0.0.1... connected 
    > GET /services/TestProxy/greet?name=Test HTTP/1.1 
    > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 
    > Host: localhost:8280 
    > Accept: */* 
    > 
    < HTTP/1.1 200 OK 
    < Content-Type: text/plain; charset=UTF-8 
    < Server: WSO2 Carbon Server 
    < Vary: Accept-Encoding 
    < Date: Wed, 25 Sep 2013 06:08:21 GMT 
    < Transfer-Encoding: chunked 
    < 
    * Connection #0 to host localhost left intact 
    * Closing connection #0 
    Hello World, Test !!! 
    

    谢谢 萨吉特

    【讨论】:

      【解决方案2】:

      只需将整个信封定义为内联源。 例如:

       <inSequence>
               <enrich>
                  <source type="inline" clone="true">
                     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">                        
                        <soapenv:Body>     Your request for subscription is being processed.   </soapenv:Body>               
                     </soapenv:Envelope>
                  </source>
                  <target type="envelope"/>
               </enrich>
               <header name="To" action="remove"/>
               <property name="RESPONSE" value="true" scope="default" type="STRING"/>
               <property name="Content-Type" value="text/plain" scope="transport" type="STRING"/>
               <send/>
            </inSequence>
      

      【讨论】:

      • 感谢您的回复。我已经尝试过你上面的 sn-p,但我没有得到任何回应。请提出一些方法来获取唯一的纯文本作为响应。
      • 对于上述内容,您将得到如下响应; schemas.xmlsoap.org/soap/envelope"> 正在处理您的订阅请求。 上面没有得到任何东西是什么意思?那么你的配置已经磨损了
      • 抱歉造成误解,我已经用相同的配置测试了其他网络服务。他们工作正常,实际上在调用此网络服务后,我得到 作为响应。我只需要 您的订阅请求是正在处理中。 作为响应,即没有任何成功标记。
      • 我已经在控制台上使用 Curl & 尝试了上述问题我得到了以下结果 &gt; GET /services/SampleProxy?param=123456789 HTTP/1.1 &gt; User-Agent: curl/7.19.5 (i586-pc-mingw32msvc) libcurl/7.19.5 zlib/1.2.3 &gt; Host: myhost:8280 &gt; Accept: */* &lt; HTTP/1.1 200 OK &lt; Host: localhost:8280 &lt; RESPONSE: true &lt; Content-Type: text/plain -- &lt; Server: WSO2-PassThrough-HTTP -- -- * Connection #0 to host myhost left intact * Closing connection #0 在日志中我得到了所需的响应,即 你的请求正在处理订阅。 请在 adv 中建议.Thnx
      猜你喜欢
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 2015-01-21
      相关资源
      最近更新 更多