使用普通旧 XML (POX) 创建 Spring Web 服务 [英] Creating a Spring Web Service using Plain Old XML (POX)

查看:25
本文介绍了使用普通旧 XML (POX) 创建 Spring Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在为一个已经存在的应用程序编写一个 Spring Web 服务来与之对话.我让服务在接收请求并响应它的地方工作,但问题是,应用程序希望响应是普通的旧 XML (POX).我的响应当前附加了 SOAP 标头,如下所示:

So, I'm writing a Spring Web Service for an already-existing application to talk to. I have the service working to where it will receive a request and respond to it but the thing is, the application expects the response to be in Plain Old XML (POX). My response currently has SOAP headers attached to it like so:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
        <Person>
            <FirstName>John</FirstName>
            <LastName>Smith</LastName>
        </Person>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我需要它返回的是:

<Person>
    <FirstName>John</FirstName>
    <LastName>Smith</LastName>
</Person>

据我所知,Spring 非常有能力做到这一点,我认为这与 DomPoxMessageFactory 有关,但我发现的所有示例都使用旧版本的 SpringWS 喜欢 v1.5.甚至 Spring 发行版中的 POX 示例也是 3 年前编写的.感谢您的帮助!

From what I've found, Spring is very much capable of doing this and I think it has something to do with DomPoxMessageFactory but all the examples I've found have been with old versions of Spring WS like v1.5. Even the POX sample in the Spring distribution was written 3 years ago. Thanks for any help!

我也在使用 spring-ws v2.1.2.到目前为止,我的代码非常类似于您在此处找到的代码:http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

I am also using spring-ws v2.1.2. My code so far very much resembles what you will find here: http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

推荐答案

对我来说,我所需要的只是基于 Java 的配置:

For me, all I needed was this in the java-based configuration:

@Bean(name = "messageFactory")
public WebServiceMessageFactory messageFactory() {
    return new DomPoxMessageFactory();
}

这意味着 MessageDispatcherServlet 将切换到 POX 而不是默认的 SOAP.

This means MessageDispatcherServlet will switch to POX instead of default SOAP.

如果您使用基于 XML 的配置,则应该这样做:

If you're using XML-based config, this should do it:

<bean id="messageFactory" class="org.springframework.ws.pox.dom.DomPoxMessageFactory" />

来自 评论@loshad-vtapkah:

From comment by @loshad-vtapkah:

只有在 request.xml 中指定了命名空间时,此修改才有效.对于您提供的链接上指定的案例,名称空间被省略.因此,您需要为 CountryEndpount 设置空命名空间(检查PayloadRoot 注释)或扩展DomPoxMessage.createWebServiceMessage() 方法来更新文档节点命名空间.

This modification only works if namespace is specified in request.xml. For case specified on the link you've provided, namespace is omitted. So you will need either set empty namespace for CountryEndpount (check PayloadRoot annotation) or extend DomPoxMessage.createWebServiceMessage() method to update document nodes namespace.

这篇关于使用普通旧 XML (POX) 创建 Spring Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆