Converting the SOAP Messages to Plain Text Mail
If you need to convert the SOAP message to a plain text mail (without any XML in it), follow the instructions below.
1) Download a distribution of the WSO2 ESB. For example, wso2esb-2.1.1.zip
.
2) Extract the zip file. The folder created will be referred as ESB_HOME
. For example, wso2esb-2.1.1
.
3) Uncomment the mail TransportSender
and {TransportReceiver}} from axis2.xml. For example, ESB_HOME/conf/axis2.xml
.
<transportSender name="mailto"> <parameter name="mail.smtp.host">smtp.gmail.com</parameter> <parameter name="mail.smtp.port">587</parameter> <parameter name="mail.smtp.starttls.enable">true</parameter> <parameter name="mail.smtp.auth">true</parameter> <parameter name="mail.smtp.user">synapse.demo.0</parameter> <parameter name="mail.smtp.password">mailpassword</parameter> <parameter name="mail.smtp.from">synapse.demo.0@gmail.com</parameter> </transportSender> <transportReceiver name="mailto"> </transportReceiver>
4) Add the following line to axis2.xml's MessageFormatters
.
<messageFormatter contentType="text/plain"/>
5) Build the SimpleStockQuote
service (which is residing inside the samples). For example, ESB_HOME/samples/axis2Server/src/SimpleStockQuoteService
.
6) Run sample axis2Server
.
7) Go to the ESB_HOME/bin
and run the script which starts wso2server. For example, wso2server.bat
for windows environments or wso2server.sh
for linux environments.
8) Then the server will be started. You can access the management console using the following URL https://<host>:<port>/carbon/
.
9) Log into the Management Console using following credentials.
username: admin
password: admin
10) Create a Proxy Service using the following Proxy configuration. See how to create a Proxy Service here.
<!-- Using the mail transport --> <definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="StockQuoteProxy" transports="mailto"> Â Â Â <parameter name="transport.mail.Address">synapse.demo.1@gmail.com</parameter> Â Â Â <parameter name="transport.mail.Protocol">pop3</parameter> Â Â Â <parameter name="transport.PollInterval">5</parameter> Â Â Â <parameter name="mail.pop3.host">pop.gmail.com</parameter> Â Â Â <parameter name="mail.pop3.port">995</parameter> Â Â Â <parameter name="mail.pop3.user">synapse.demo.1</parameter> Â Â Â <parameter name="mail.pop3.password">mailpassword</parameter> Â Â Â <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter> Â Â Â <parameter name="mail.pop3.socketFactory.fallback">false</parameter> Â Â Â <parameter name="mail.pop3.socketFactory.port">995</parameter> Â Â Â <parameter name="transport.mail.ContentType">application/xml</parameter> Â Â Â <target> Â Â Â Â Â Â Â <inSequence> Â Â Â Â Â Â Â Â Â Â Â <property name="senderAddress" expression="get-property('transport', 'From')"/> Â Â Â Â Â Â Â Â Â Â Â <log level="full"> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <property name="Sender Address" expression="get-property('senderAddress')"/> Â Â Â Â Â Â Â Â Â Â Â </log> Â Â Â Â Â Â Â Â Â Â Â <send> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <endpoint> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </endpoint> Â Â Â Â Â Â Â Â Â Â Â </send> Â Â Â Â Â Â Â </inSequence> Â Â Â Â Â Â Â <outSequence> Â Â Â Â Â Â Â Â Â Â Â <property name="Subject" value="Custom Subject for Response" scope="transport"/> Â Â Â Â Â <property name="messageType" value="text/plain" scope="axis2-client"/> Â Â Â <script language="js"><![CDATA[ Â Â Â Â Â Â Â Â Â Â Â Â Â mc.setPayloadXML(<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">Plain text received!</ns:text>); Â Â Â Â Â ]]></script> Â Â Â Â Â Â Â Â Â Â Â <header name="To" expression="fn:concat('mailto:', get-property('senderAddress'))"/> Â Â Â Â Â Â Â Â Â Â Â <log level="full"> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <property name="message" value="Response message"/> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <property name="Sender Address" expression="get-property('senderAddress')"/> Â Â Â Â Â Â Â Â Â Â Â </log> Â Â Â Â Â Â Â Â Â Â Â <send/> Â Â Â Â Â Â Â </outSequence> Â Â Â </target> Â Â Â <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>
11) Send an email to synapse.demo.1@gmail.com
.
12) You will receive the response in plain text.
See the source article here.