在JAX-WS webservice方法中获取原始XML参数

时间:2010-11-18 07:39:59

标签: java web-services jax-ws cxf

如何实现这样的目标:

@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) 返回值可以是任何类型。

1 个答案:

答案 0 :(得分:3)

我相信这会奏效:


@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) 

也可以。

相关问题