我正在尝试将我的 SOAP 服务从 xml 配置文件迁移到配置类,但我遇到了安全拦截器问题。
我有以下内容:
<sws:interceptors>
<sws:payloadRoot namespaceUri="namespace1">
<ref bean="myXwsSecurityInterceptor"/>
</sws:payloadRoot>
</sws:interceptors>
在我的配置类中,我通过扩展 WsConfigurerAdapter 并覆盖 addInterceptors 来注册拦截器:
@Configuration
public class AppConfig extends WsConfigurerAdapter {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
interceptors.add(myXwsSecurityInterceptor);
}
}
但通过这种方式,我不指定任何有效负载namespaceUri,这意味着它会拦截每个请求,但我不希望这样,因为我的应用程序中有不同的 SOAP 服务。
我找不到任何解决方案。
有人可以帮忙吗?
谢谢
最佳答案
我也找不到任何答案,但我找到了解决方案。您必须将智能拦截器添加到您的上下文中。智能拦截器包含方法shouldIntercept。我发现 addInterceptor 方法仅添加适用于整个上下文的普通拦截器。
您甚至不需要扩展 WsConfigurerAdapter 来添加智能拦截器,您只需要向上下文添加新的 bean 即可。这是我所做的:
@Bean
public SmartEndpointInterceptor addSmartEndpointInterceptor()
{
try
{
//init myXwsSecurityInterceptor
PayloadRootSmartSoapEndpointInterceptor smartInterceptor =
new PayloadRootSmartSoapEndpointInterceptor(myXwsSecurityInterceptor, "namespace1", null);
return smartInterceptor;
}
catch (IOException ioe)
{
}
return null;
}
PayloadRootSmartSoapEndpointInterceptor 具有与(命名空间和 localName)相同的属性 - 您指定应调用委托(delegate)拦截器 (myXwsSecurityInterceptor) 的命名空间和本地名称。
关于xml - Spring <sws :interceptors> to annotation based configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32498463/