在 JAX-WS Web 服务方法中获取原始 XML 参数

发布于 2024-10-02 17:12:23 字数 331 浏览 1 评论 0原文

如何实现类似的目标:

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

How to achieve something like that:

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

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

I need a raw XML for processing (SAX or DOM). In same time I want to leverage existing method routing of JAX-WS.(I use Apache CXF)
Returned value may be any type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浴红衣 2024-10-09 17:12:23

我相信这会起作用:


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

也可以。

I believe this will work:


@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;
    }
}

By default, you should get a StaxSource (which is a subclass of SAXSource) so you can pass that into your XML processing library and such. You can return any subclass of Source. However, you can also be more specific and use:


public Source sayHi(DOMSource xml) 

if you know you need it as a DOM. I actually think:


public Source sayHi(XMLStreamReader xml) 

would work as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文