Ton*_*ngo 4 spring web-services spring-ws soapheader
我们正在使用spring-ws 2.2.0开发一个契约优先的WebService.我们正在尝试使用AuthToken
位于SoapHeader中的自定义标记来管理身份验证.该AuthToken
结构如下:
<authToken>
<username>USERNAME</xa:username>
<password>PASSWORD</xa:password>
</authToken>
Run Code Online (Sandbox Code Playgroud)
我们能够在SoapHeader中生成包含指定自定义身份验证标记的WSDL模式.问题是当客户端对我们的服务器执行调用时,我们无法在Ws Endpoint实现中解组AuthToken标记(位于SoapHeader中).
使用@RequestPayload
绑定方法签名中的注释(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) { }
Run Code Online (Sandbox Code Playgroud)
在案例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?
Run Code Online (Sandbox Code Playgroud)
在案例3,4中,我们没有错误,但是我们无法处理SoapHeader或MessageContext(分别在案例3和4中)以达到我们的目的,访问AuthToken
以检索用户名和密码子元素.
在Web中寻找解决方案,我们发现许多具有相同问题的人使用Spring Interceptor来处理身份验证.按照"拦截器方式",我们应该访问AuthToken
拦截器内部.不幸的是,我们需要在handleMethodRequest方法中使用AuthToken字段用于其他目的,例如加载用户特定的数据,不能在外部访问handleMethodRequest
.因此我们不能遵循这种方式,因为我们需要在handleMethodRequest
方法中引用用户特定的数据.
有谁知道我们如何解决这个问题?提前致谢.
归档时间: |
|
查看次数: |
2257 次 |
最近记录: |