本主题仅适用于 IBM Business Automation Workflow Advanced 配置。

XML 文档验证

XML 文档和业务对象可使用验证服务进行验证。

此外,其他服务需要某些最低标准,否则它们会抛出运行时异常。 其中之一是 BOXMLSerializer

您可以使用 BOXMLSerializer 来验证 XML 文档,然后再由服务请求处理这些文档。 BOXMLSerializer 会验证 XML 文档的结构,以确定是否存在以下任何类型的错误:
  • 无效 XML 文档,例如,缺少某些元素标记的 XML 文档。
  • 格式不严谨的 XML 文档,例如,缺少闭合标记的 XML 文档。
  • 包含解析错误(例如,实体声明中的错误)的文档。
BOXMLSerializer 发现错误时,将抛出异常,并提供问题详细信息。
可以为与以下服务相关的 XML 文档的导入和/或导出执行验证:
  • HTTP
  • JAXRPC Web Service
  • JAX-WS Web Service
  • JMS 服务
  • MQ 服务
对于 HTTP、JAXRPC 和 JAX-WS 服务,BOXMLSerializer 将通过下列方式生成异常:
  • 导入 -
    1. SCA 组件调用此服务。
    2. 此服务调用目标 URL。
    3. 目标 URL 以无效 XML 异常响应。
    4. 服务失败并生成运行时异常和消息。
  • 导出 -
    1. 服务客户机调用服务导出。
    2. 服务客户机发送无效 XML。
    3. 对于此服务,导出失败并生成异常和消息。
对于 JMS 和 MQ 消息传递服务,以如下方式生成异常:
  • 导入 -
    1. 导入调用 JMS 或 MQ 服务。
    2. 此服务返回响应。
    3. 此服务返回无效 XML 异常。
    4. 导入失败并生成消息。
  • 导出 -
    1. MQ 或 JMS 客户机调用导出。
    2. 客户机发送无效 XML。
    3. 导出失败并生成异常和消息。

可查看 XML 验证异常生成的任何消息的日志。 以下示例是由 BOXMLSerializer 所验证的不正确 XML 编码生成的消息

  • JAXWS 导入
    javax.xml.ws.WebServiceException: org.apache.axiom.om.OMException: 
     javax.xml.stream.XMLStreamException: Element type "TestResponse" must be 
     followed by either attribute specifications, ">" or "/>".
    
    javax.xml.ws.WebServiceException: org.apache.axiom.soap.SOAPProcessingException: 
    	First Element must contain the local name, Envelope
  • JAXRPC import
    [9/11/08 15:16:27:417 CDT] 0000003e ExceptionUtil E   
    	CNTR0020E: EJB threw an unexpected (non-declared) 
    	 exception during invocation of method 
      "transactionNotSupportedActivitySessionNotSupported" on bean 
    	 "BeanId(WSXMLValidationApp#WSXMLValidationEJB.jar#Module, null)". 
      Exception data: WebServicesFault
     faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
     faultString: org.xml.sax.SAXParseException: Element type "TestResponse" 
       must be followed by either 
    		attribute specifications, ">" or "/>". Message being parsed: 
        <?xml version="1.0"?><TestResponse 
    		xmlns="http://WSXMLValidation"<firstName>Bob</firstName>
        <lastName>Smith</lastName></TestResponse>
     faultActor: null
     faultDetail: 
    [9/11/08 15:16:35:135 CDT] 0000003f ExceptionUtil E   CNTR0020E: EJB threw an 
      unexpected (non-declared) exception during invocation of method 
      "transactionNotSupportedActivitySessionNotSupported" on bean 
    		"BeanId(WSXMLValidationApp#WSXMLValidationEJB.jar#Module, null)". 
     Exception data: WebServicesFault
     faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
     faultString: org.xml.sax.SAXException: WSWS3066E: Error: Expected 'envelope' 
       but found  TestResponse 
    		Message being parsed: <?xml version="1.0"?><TestResponse 
       xmlns="http://WSXMLValidation">
    		<firstName>Bob</firstName><middleName>John</middleName>
       <lastName>Smith</lastName>
       </TestResponse>
     faultActor: null
     faultDetail: 
  • JAXRPC/JAXWS 导出
    [9/11/08 15:35:13:401 CDT] 00000064 WebServicesSe E 
      com.ibm.ws.webservices.engine.transport.http.WebServicesServlet 
      getSoapAction WSWS3112E: 
    	  Error: Generating WebServicesFault due to missing SOAPAction.
                        WebServicesFault
     faultCode: Client.NoSOAPAction
     faultString: WSWS3147E: Error: no SOAPAction header!
     faultActor: null
     faultDetail: 

有关验证服务的更多信息,请参阅“参考”部分中“生成的 API 和 SPI”文档中的 BOInstanceValidator 接口。