【问题标题】:Getting raw XML parameter in JAX-WS webservice method在 JAX-WS webservice 方法中获取原始 XML 参数
【发布时间】:2010-11-18 07:39:59
【问题描述】:

如何实现这样的目标:

@WebService(endpointInterface = "ru.citc.techtest.cxfconcepts.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    public String sayHi(DOMSource xml) {
        return "Hello";
    }
}

我需要一个用于处理的原始 XML(SAX 或 DOM)。同时我想利用 JAX-WS 的现有方法路由。(我使用 Apache CXF) 返回值可以是任何类型。

【问题讨论】:

    标签: java web-services jax-ws cxf


    【解决方案1】:

    我相信这会奏效:

    
    @WebService(wsdlLocation = "....")
    @DataBinding(org.apache.cxf.databinding.source.SourceDataBinding.class)
    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 
    public class HelloWorldImpl implements HelloWorld {
         public Source sayHi(Source xml) {
            return xml;
        }
    }
    

    默认情况下,您应该获得一个 StaxSource(它是 SAXSource 的子类),以便您可以将其传递到您的 XML 处理库等。您可以返回 Source 的任何子类。但是,您也可以更具体地使用:

    
    public Source sayHi(DOMSource xml) 
    

    如果你知道你需要它作为一个 DOM。其实我觉得:

    
    public Source sayHi(XMLStreamReader xml) 
    

    也可以。

    【讨论】:

    • 丹尼尔,再次感谢。 Typpo Souce -> 来源
    猜你喜欢
    • 2015-07-23
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2011-02-02
    • 1970-01-01
    相关资源
    最近更新 更多