java - 如何<sws :annotation-driven/> with marshaller works

标签 java spring-ws

当在我的应用程序上下文中添加此行时,此编码器设置在哪里?

<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller" />

我认为 spring-ws 使用它来取消/编码(marshal)请求响应,但我错了,因为它一定是这样的

<bean id="marshallingPayloadMethodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
    <constructor-arg ref="marshaller" />
</bean> 

更新:

sws:annotation

应该相当于

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>

那么什么相当于 sws:annotation with marshaller

最佳答案

简单的 JAX-WS 提供程序 Web 服务实现,我们知道仅当存在巨大的 xml 文件数据输入时才需要这种类型实现,JAXB 对于巨大的 xml 数据将带来性能痛苦

据我们所知,SEI Webservices 易于实现和维护,但在 SOAP 消息中的大量数据的 xml 数据解析上失败。

使用 Spring-ws 和提供者有效负载,我们可以实现 JAX-WS 提供者 Web 服务

spring-ws如何在提供者基础soap xml消息中工作。

xml配置

<sws:annotation-driven/>

<sws:dynamic-wsdl id="DataLoadService" portTypeName="publishMessage"
            locationUri="/soap/services" targetNamespace="http://www.informatica.com/wsdl/">
            <sws:xsd location="https://sample.application/publishMessage.xsd" />
</sws:dynamic-wsdl>

以上配置将从远程位置读取 xsd 并为 Web 服务方法公开生成 wsdl 文件。如果需要,我们可以通过配置类来使用应用程序编码/联合国编码。

java实现

@Endpoint
public class DataLoadServiceEndPoint {

    @PayloadRoot(localPart = "publishMessageRequest", namespace = "http://www.informatica.com/wsdl/")
    @ResponsePayload
    public Element processRequest(@RequestPayload Element requestNode) {
    .....
    }
}

上述端点将接收 xml 元素文档,即来自soapMessage的有效负载数据。

spring-ws marshal/unmarshal 的历史

oxm 命名空间来定义您的编码器:

<oxm:jaxb2-marshaller id="marshaller" >
    <oxm:class-to-be-bound name="...xml elements.."/>
</oxm:jaxb2-marshaller>

Or 
<oxm:jaxb2-marshaller id="marshaller" contextPath="xx.aa.ws"/>

spring 2.x 后的最新 spring 版本删除了对 GenericMarshallingMethodEndpointAdapter 和 PayloadRootAnnotationMethodEndpointMapping 的引用,将两者替换为“sws 命名空间”

<sws:annotation-driven  />

OR explicitly specify the marshaller/unmarshaller:

<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller"/>

我希望您了解什么是编码器/解码器以及提供程序基础 Web 服务,其中包含来自 SOAP 消息的有效负载数据。

<sws:annotation-driven /> - for the default xsd/schema based payload i.e.


    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "SampleRequest")
    @ResponsePayload
    public Element processRequest(@RequestPayload Element requestNode)  throws Exception {
    
    }

<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller" />

When we want to use Objects as @PayloadRoot value not schema xml then we need to implement our own marshall/unmarshall adapters.

    i.e.
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "SampleRequest")
    @ResponsePayload
    public SampleRequest processRequest(@RequestPayload SampleRequest sampleRequest) throws Exception {
    
    }

for details

关于java - 如何<sws :annotation-driven/> with marshaller works,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25199921/

相关文章:

java - java中如何识别文件中的字符串并打印行?

java - 如何将SOAP消息转换为SPRING WS的webServiceTemplate.sendSourceAndReceiveToResult

java - 如何访问 Spring Soap 端点中的 SOAP header ?

java - Spring WS/启动: How to set WebServiceTemplate property in client interceptor?

java - 一个类在 JVM 中占用多少空间?

Java 投资返回率复合计算器

java - 在 flutter 中添加Firebase包时出错

java - 如何为 Spring 的 WebServiceTemplate 创建模拟对象?

java - 如何在 Spring Soap 客户端上添加自定义 header

java - Android.App.Activity - 包不存在