使用 wso2 esb 4.0.6 将响应转换为纯文本 [英] Transform response to plain-text using wso2 esb 4.0.6

查看:19
本文介绍了使用 wso2 esb 4.0.6 将响应转换为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<case regex="POST">

我能够得到以下响应<success>您的订阅请求正在处理中.</success>

我只想删除 <success></success> 来自响应的标签.

提前致谢

解决方案

可能有点晚了,但我最近也遇到了这个问题,下面是如何让它工作的方法.

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

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

<块引用>

<有效载荷工厂><格式><ms11:text xmlns:ms11="http://ws.apache.org/commons/ns/payload">$1</ms11:text></格式><参数><arg xmlns:ns="http://www.wso2.org/types" 表达式="$body/ns:greetResponse/return/text()"/></args></有效负载工厂>

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

<?xml 版本='1.0' 编码='utf-8'?><soapenv:信封 xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:身体><ns:greetResponse xmlns:ns="http://www.wso2.org/types"><return>Hello World,测试!!!</return></ns:greetResponse></soapenv:Body></soapenv:信封>

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

curl -X GET "http://localhost:8280/services/TestProxy/greet?name=Test" -v* 即将 connect() 到 localhost 端口 8280 (#0)* 尝试 127.0.0.1... 已连接>GET/services/TestProxy/greet?name=Test HTTP/1.1>用户代理: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>主机:本地主机:8280>接受: */*><HTTP/1.1 200 正常<内容类型:文本/纯文本;字符集=UTF-8<服务器:WSO2 碳服务器<变化:接受编码<日期:格林威治标准时间 2013 年 9 月 25 日星期三 06:08:21<传输编码:分块<* 连接 #0 到主机 localhost 保持不变* 关闭连接 #0世界你好,测试!!!

谢谢萨吉特

I'm new to web-service and somehow I have created a simple web-service over http/https using wso2 esb 4.0.6. Now my requirement is to remove the tag from response i.e. i need plain text in response, below code snippets will give u a brief idea of my requirement.

<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>

I'm able to get the below response <success>Your request for subscription is being processed.</success>

I just want to remove the <success> </success> tags from the response.

Thanks in advance

解决方案

May be this is bit late, but I too have came across this recently, and here's how you can make it work.

  1. Make sure in ESB/repository/conf/axis2/axis2.xml plainTextFormatter is enabled.
  2. In your proxy service set 'messageType' property as shown below

  3. Add a payload text element. Please refer to the out sequence of the sample proxy service given below

<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>

In this scenario my response from the backend service (HelloService) is as follows.

<?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> 

See below the request and response for the GET request using curl command

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 !!! 

Thanks Sajith

这篇关于使用 wso2 esb 4.0.6 将响应转换为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆