如何在Apache CXF中将XML Schema添加到SoapMody的SoapMody中?

时间:2010-10-11 13:48:17

标签: soap cxf

有没有办法使用Apache CXF修改SoapBody消息?我试图在Phase.SEND模式下使用Interceptors功能尝试在SoapBody中添加带有结果的xml架构。我没有运气。

问题是我想用xml架构验证结果消息。 SoapBody的当前输出发送了带有xml架构的结果消息,该架构使用了在目标位置不可用的架构位置的引用。

为了验证结果响应消息,我在BindingProvider中的ResponseContext中添加了“schema-validation-enabled”为true;但是,我不确定它是否有效。

我尝试添加/ attache原始模式,而不是使用它的引用和SoapBody的响应消息。有没有办法使用注释或任何其他方法来使用给定的xml架构进行验证?

任何想法和回应都表示赞赏。

<?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="resultSet" targetNamespace="http://www.xxx.com/" xmlns:mstns="http://www.xxx.com/" xmlns="http://www.xxx.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="http://www.xxx.com/ResultSet.xsd">
      <xs:import namespace="http://www.xxx.com/ResultSet.xsd" schemaLocation="RalsDeviceService_app1.xsd" />
      <xs:element name="resultSet" msdata:IsDataSet="true" msdata:Locale="en-US">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="app1:ResultSet" />
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    <resultSet xmlns="http://www.xxx.com/">
      <ns2:ResultSet xmlns:ns2="http://www.xxx.com/ResultSet.xsd">
        <ns2:Results>
         ...
         ..
         .
    </resultSet>

1 个答案:

答案 0 :(得分:0)

关于这个问题我工作了三天=)Inteceptor方式没有错。这是我简单的演示实现

 public static class MySendingReturn extends AbstractPhaseInterceptor<Message> {

    public MySendingReturn() {
        super(Phase.SEND);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        XMLStreamWriter content = message.getContent(XMLStreamWriter.class);
        try {

            MySchema context = new MySchema();
            content.writeStartElement("testOperationWithParameter");
            content.writeStartElement("returnValue");
            content.writeCharacters("Halllllo-Return");
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }
}

XMLStreamWriter的当前元素是SoapMessage的BODY元素。这个拦截器我在我的服务实例上注册:

 service.getOutInterceptors().add(new MySendingReturn());
相关问题