在 WSO2 中,ESB 在进入 api 之前验证 XML

In WSO2 ESB is validate XML before coming to the api

有没有办法验证 XML 加入 WSO2 ESB API 因为为了验证。

当错误的 XML 出现在我的 API 时,我收到一条错误消息。这是我在 API 之前遇到的错误,我想在此之前进行验证。

[2018-10-19 10:00:03,531] ERROR - LogMediator Could not build full log message: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag ; expected .

正在发送XML

<Request>
    <DeleteServiceRequest> 
       <ServiceLineId>12344455</ServiceLineId> 

</Request> 

Header 的 API

<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="testAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>

问题是要验证消息,您需要先构建它。您收到的消息格式不正确 xml,因此 API 第一次尝试构建消息时会失败。但是,还需要验证消息的 XML 构建,因此 xml 验证中介也将失败。

所以不,当您收到的消息不正确 XML 时,您无法验证 XML。 (从技术上讲,它不是 XML)。通常这是您向客户端发回错误的时候。由于他们在调用 API 时出现了技术错误,您可以将您遇到的实际错误提供给他们,以便他们知道要修复什么。

您可以使用以下属性获取有关您的错误的信息,然后使用此信息构建错误消息以发送回客户端。例如,以下故障序列将记录错误详细信息并将简单的错误消息发送回客户端。

      <faultSequence>
         <log level="custom">
            <property name="text" value="An unexpected error occured"/>
            <property expression="get-property('ERROR_MESSAGE')" name="message"/>
            <property expression="get-property('ERROR_DETAIL')" name="detail"/>
            <property expression="get-property('ERROR_CODE')" name="code"/>
            <property expression="get-property('ERROR_DETAIL')" name="detail"/>
         </log>
         <payloadFactory media-type="xml">
            <format>
               <ERROR xmlns="">
                  <MESSAGE>You broke it</MESSAGE>
                  <DETAIL></DETAIL>
               </ERROR>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('ERROR_MESSAGE')"/>
            </args>
         </payloadFactory>
         <respond/>
      </faultSequence>

您可能还想在返回消息之前将 http 状态代码设置为适当的值,例如:

<property name="HTTP_SC" value="500" scope="axis2"/>