gpt4 book ai didi

端点方法中的 Spring-ws SoapHeader 字段访问

转载 作者:行者123 更新时间:2023-12-05 00:24:06 25 4
gpt4 key购买 nike

我们正在使用 spring-ws 2.2.0 开发一个合约优先的 WebService。我们正在尝试使用名为 AuthToken 的自定义标签来管理身份验证。 ,位于 SoapHeader 中。AuthToken具有以下结构:

<authToken>
<username>USERNAME</xa:username>
<password>PASSWORD</xa:password>
</authToken>

我们能够在 SoapHeader 中生成包含指定自定义身份验证标记的 WSDL 模式。
问题是当客户端对我们的服务器执行调用时,我们无法在 Ws Endpoint 实现中解码 AuthToken 标记(位于 SoapHeader 中)。

使用 @RequestPayload绑定(bind)方法签名中的注释( handleMethodRequest,如下例中指定),我们能够访问未编码的有效负载内容(位于 SoapBody 中)。
我们试图用 SoapHeader 内容做同样的事情,但没有成功。
在以下代码示例中,我们向您展示了我们想要获得的内容:
1
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, @SoapHeader(value = "authToken") AuthToken authToken) { }

2
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, AuthToken authToken) { }

3
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, org.springframework.ws.soap.SoapHeader header) { }

4
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, MessageContext messageContext) { }

在情况 1、2 中,我们得到以下错误:
No adapter for endpoint [MethodResponse EndpointImplementation.handleMethodRequest(MethodRequest, AuthToken) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

在案例 3、4 中,我们没有错误,但我们无法处理 SoapHeader 或 MessageContext(分别在案例 3 和 4 中)以达到我们的目的,访问 AuthToken检索用户名和密码子元素。

在网上寻找解决方案时,我们发现许多有相同问题的人使用 Spring 拦截器来处理身份验证。
按照“拦截器方式”,我们应该访问 AuthToken拦截器内部。不幸的是,我们需要将handleMethodRequest 方法中的AuthToken 字段用于其他目的,例如加载用户特定的数据,在 handleMethodRequest 之外无法访问。 .
因此我们不能遵循这种方式,因为我们需要在 handleMethodRequest 中引用用户特定的数据。方法。

有谁知道我们该如何解决这个问题?提前致谢。

最佳答案

对于该用例,唯一支持的注释和参数类型组合是 @SoapHeaderSoapHeaderElement . Spring-WS 目前不支持 unmarshalling headers .

关于端点方法中的 Spring-ws SoapHeader 字段访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26997194/

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