如何发送没有200错误WSO2重复调用的邮件

时间:2018-10-09 09:51:45

标签: wso2 wso2esb

我正在使用wso2 ESB 6.3.0 我的完整功能是:如果完成任何发送邮件处理的响应,但调用服务rest api,但是要求没有200个状态码remaimimg任何发送邮件的状态码(例如:iam将错误代码或成功代码发送给发送发送邮件reming 200错误代码(如果有任何错误代码)发送电子邮件。如果有任何错误,请建议我。

<?xml version="1.0" encoding="UTF-8"?>
<api context="/first" name="firston" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
            <log level="full"/>
            <send>
                <endpoint key="firstapi"/>
            </send>
        </inSequence>
        <outSequence>
            <switch source="get-property('axis2','HTTP_SC')">
                <case regex="200">
                    <log description="200log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="200reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="200reshttpsc"/>
                    </log>
                </case>
                <case regex="400">
                    <log description="400log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="400reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="400reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="400reshttpsc"/>
                    </log>
                </case>
                <case regex="404">
                    <log description="404log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="404reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="404reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="404reshttpsc"/>
                    </log>
                </case>
                <case regex="500">
                    <log description="500log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="500reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="500reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="500reshttpsc"/>
                    </log>
                </case>
                <default>
                    <log description="reslog" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
                    </log>
                </default>
            </switch>
            <clone continueParent="true">
                <target>
                    <sequence>
                        <sequence key="sendthemail"/>
                    </sequence>
                </target>
            </clone>
            <send/>
        </outSequence>
        <faultSequence>
            <switch source="get-property('axis2','HTTP_SC')">
                <case regex="200">
                    <log description="200log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="200errorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="200errormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="200httpsc"/>
                    </log>
                </case>
                <case regex="400">
                    <log description="400log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="400errorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="400errormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="400httpsc"/>
                    </log>
                </case>
                <case regex="404">
                    <log description="404log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="404errorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="404errormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="404httpsc"/>
                    </log>
                </case>
                <case regex="500">
                    <log description="500log" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="500reserrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="500reserrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="500reshttpsc"/>
                    </log>
                </case>
                <default>
                    <log description="faultlog" level="custom">
                        <property expression="$ctx:ERROR_CODE" name="faulterrorcode"/>
                        <property expression="$ctx:ERROR_MESSAGE" name="faulterrormessage"/>
                        <property expression="get-property('axis2','HTTP_SC')" name="faulthttpsc"/>
                    </log>
                </default>
            </switch>
            <clone continueParent="true">
                <target>
                    <sequence>
                        <sequence key="sendthemail"/>
                    </sequence>
                </target>
            </clone>
            <send/>
        </faultSequence>
    </resource>
</api>

所有代码都工作于任何状态代码200或404或500等,任何状态代码发送邮件我的要求是状态代码!= 200保留任何状态代码发送邮件,请任何一个建议我

1 个答案:

答案 0 :(得分:1)

这很简单,下面是代码。

 <switch source="get-property('axis2','HTTP_SC')">
                    <case regex="200"><!-- Do not do anything here as it's success -->
                        <log description="200log" level="custom">
                            <property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>

                        </log>
                    </case>

                    <default><!-- Put your logic here to send mail -->
                        <log description="reslog" level="custom">
                            <property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
                            <property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
                            <property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
                        </log>
                    </default>
                </switch>