0

我通过在我的大多数服务中调用 DSS 来返回 JSON 响应。可以使用参数向我的源 RESTApi 发出请求。我不断检查传入的参数,但在某些情况下可能会丢失请求。

使用 500 个 HTTP 代码生成的错误消息向最终用户展示了有关我的数据库的一些信息。这是一条如下所示的错误消息:

{
    "Fault": {
        "faultcode": "axis2ns25:DATABASE_ERROR",
        "faultstring": "DS Code: DATABASE_ERROR\nNested Exception:-\njavax.xml.stream.XMLStreamException: 
                    DS Fault Message: Error in 'SQLQuery.processStoredProcQuery': You have an error in your SQL syntax; check 
                    the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1\nDS Code: DATABASE_ERROR\nSource Data Service:-\nName: getMetricsService\nLocation: C:\\IntegrationStudio\\runtime\\microesb\\tmp\\carbonapps\\-1234\\1TestCompositeApplication_1.0.0.car\\MetricsService_1.0.0\\MetricsService-1.0.0.dbs\nDescription:
                   \nDefault Namespace: http://ws.wso2.org/dataservice\nCurrent Request Name: _get_getmetricwithweek_type\nCurrent Params:  
                  {type=10}\nNested Exception:-\njava.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the
                   manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1\n\n",
        "detail": ""
    }
}

我可以通过在 inSequence 阶段过滤 http 500 代码来捕获传入的错误代码,但我无法了解错误的内容,如果它出于不同的原因接收到 http 500 代码,我必须给出相同的错误消息。

<resource methods="GET" uri-template="/metric/{type}/{interval}">
   <inSequence>
       <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING" />
       ....
       <header action="remove" name="Content-Type" scope="transport"/>
       <header name="Accept" scope="transport" value="application/json"/>
       <call>
           <endpoint key="getMetricWithDayEP"/>
       </call>

        <!-- Check HTTP Code -->
 <filter regex="500" source="$axis2:HTTP_SC">
                <then>
                    <log level="custom">
                        <property expression="$axis2:HTTP_SC" name="HTTP" xmlns:ns="http://org.apache.synapse/xsd"/>
                        <property name="text" value="An unexpected error occured for service"/>
                        <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/>
                        <property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/>
                        <property expression="get-property('DATABASE_ERROR')" name="DATABASE_ERROR"/>
                        <property expression="get-property('INCOMPATIBLE_PARAMETERS_ERROR')" name="INCOMPATIBLE_PARAMETERS_ERROR"/>
                        <property expression="get-property('ERROR_DETAIL')" name="ERROR_DETAIL"/>
                        <property expression="get-property('ERROR_EXCEPTION')" name="ERROR_EXCEPTION"/>
                    </log>
                     <respond/>
                </then>
                <else>
                    <enrich>
                        <source clone="true" type="body"/>
                        <target property="metric" type="property"/>
                    </enrich>
                    <payloadFactory media-type="json">
                        <format>$1</format>
                        <args>
                            <arg evaluator="xml" expression="$ctx:metric"/>
                        </args>
                    </payloadFactory>                    
                    <respond/>
                </else>
            </filter>
   </inSequence>
    
    <outSequence/>
    <faultSequence>

     <filter regex="500" source="$axis2:HTTP_SC">
                <then>
                    <property name="errorCode" scope="default" type="INTEGER" value="500"/>            
                    <sequence key="ErrorHandling"/>
                </then>
                <else>
                    <property name="errorCode" scope="default" type="INTEGER" value="11006"/>            
                    <sequence key="ErrorHandling"/>
                </else>
            </filter>
            
    </faultSequence>


</resource>

DSS错误的消息和我的日志如下:

[2021-12-17 13:00:30,226] ERROR {DBInOutMessageReceiver} - Error in in-out message receiver DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processStoredProcQuery': You have an error 
in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 
'NULL' at line 1
DS Code: DATABASE_ERROR
Source Data Service:-
Name: getMetricsService
Location: C:\Users\IntegrationStudio\runtime\microesb\tmp\carbonapps\TestCompositeApplication_1.0.0.car\MetricsService_1.0.0\MetricsService
Description: 
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: _get_getmetricwithweek_type
Current Params: {type=10}
Nested Exception:-
java.sql.SQLSyntaxErrorException: You have an error 
in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 'NULL' at line 1


[2021-12-17 13:00:30,254]  INFO {LogMediator} - {api:Metrics} HTTP = 500, text = An unexpected error occured for service, ERROR_MESSAGE = null, ERROR_CODE = null, DATABASE_ERROR = null, INCOMPATIBLE_PARAMETERS_ERROR = null, ERROR_DETAIL = null, ERROR_EXCEPTION = null


有没有办法查询我在 DSS 中得到的 SQL 错误,get-property("DATABASE_ERROR")或者读取Fault错误对象的内容并发送不同的有效负载?

谢谢大家。

4

0 回答 0