gpt4 book ai didi

java - 如何 with marshaller works

转载 作者:行者123 更新时间:2023-11-30 11:15:47 27 4
gpt4 key购买 nike

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

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

我认为 spring-ws 将它用于取消/编码请求响应,但我错了,因为它必须像

<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 与 marshaller 的等价物是什么

最佳答案

简单的 JAX-WS 提供者 web 服务实现,因为我们知道只有在有大量 xml 文件数据输入时才需要这种类型的实现,JAXB 将是巨大的 xml 数据的性能痛点

众所周知,SEI web 服务易于实现和维护,但无法对 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"/>

我希望您了解什么是 marshaller/unmarshaller 和提供者基于 web 服务以及来自 soap Message 的有效负载数据。

<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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com