问题描述
我是Web服务的新手,因此我已经使用wso2 esb 4.0.6通过HTTP/https创建了一个简单的Web服务.现在,我的要求是从响应中删除标记,即我需要纯文本作为响应,下面的代码段将使您对我的要求有一个简短的了解.
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>
我可以得到以下回复<success>Your request for subscription is being processed.</success>
我只想从响应中删除<success> </success>
标签.
I just want to remove the <success> </success>
tags from the response.
预先感谢
推荐答案
可能有点晚了,但是最近我也遇到了这个问题,这就是使它工作的方法.
May be this is bit late, but I too have came across this recently, and here's how you can make it work.
- 确保在ESB/repository/conf/axis2/axis2.xml中启用了plainTextFormatter.
-
在您的代理服务中,设置"messageType"属性,如下所示
- Make sure in ESB/repository/conf/axis2/axis2.xml plainTextFormatter is enabled.
In your proxy service set 'messageType' property as shown below
添加有效载荷文本元素.请参阅下面给出的示例代理服务的无序顺序
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>
在这种情况下,我对后端服务(HelloService)的响应如下.
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>
请参见下面有关使用curl命令的GET请求的请求和响应
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 !!!
谢谢萨吉斯
这篇关于使用wso2 esb 4.0.6将响应转换为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!