Transform response to plain-text using wso2 esb 4.

2019-09-06 21:25发布

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

2条回答
smile是对你的礼貌
2楼-- · 2019-09-06 21:35

Simply define the full envelope as inline source. Eg:

 <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>
查看更多
Animai°情兽
3楼-- · 2019-09-06 21:48

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

查看更多
登录 后发表回答