【问题标题】:Expose multiple static wsdl files - Spring WS公开多个静态 wsdl 文件 - Spring WS
【发布时间】:2016-05-12 22:43:42
【问题描述】:

我正在尝试使用 SpringWS 和 Spring Boot 为 2 个不同的静态 WSDL 公开 2 个不同的端点。

我遇到的问题是声明了两个 SimpleWsdl11Definition bean 并且只公开了一个。

这些是我的配置文件:

@EnableWs
@Configuration
public class AWSConfig extends WsConfigurerAdapter 
{
    @Bean
    public ServletRegistrationBean aMessageDispatcherServlet(ApplicationContext applicationContext) 
    {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "Av1/*");
    }

    @Bean(name = "AV1")
    public SimpleWsdl11Definition simpleWsdl11Definition() 
    {
        SimpleWsdl11Definition simpleWsdl11Definition = new SimpleWsdl11Definition();
        simpleWsdl11Definition.setWsdl(new ClassPathResource("wsdl/AV1.wsdl"));
        return simpleWsdl11Definition;
    }

    @Bean(name = "ASchema")
    public XsdSchema aSchema() 
    {
        return new SimpleXsdSchema(new ClassPathResource("xsd/A.xsd"));
    }
}

@EnableWs
@Configuration
public class BWSConfig 
{
    @Bean
    public ServletRegistrationBean bMessageDispatcherServlet(ApplicationContext applicationContext) 
    {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "Bv1/*");
    }

    @Bean(name = "BV1")
    public SimpleWsdl11Definition simpleWsdl11Definition() 
    {
        SimpleWsdl11Definition simpleWsdl11Definition = new SimpleWsdl11Definition();
        simpleWsdl11Definition.setWsdl(wsdl/BV1.wsdl"));
        return simpleWsdl11Definition;
    }

    @Bean(name = "bSchema")
    public XsdSchema bSchema() 
    {
        return new SimpleXsdSchema(new ClassPathResource("xsd/BV1.xsd"));
    }
}

只有 AV1.wsdl 可以访问。谁能告诉我我错过了什么...

【问题讨论】:

    标签: java spring web-services soap wsdl


    【解决方案1】:

    下面的 bean 定义创建了一个名为 MessageDispatcherServlet,并带有一个覆盖的 getWsdlDefinition 方法。如果满足 url 条件,则原始代码中的此方法从 spring 启动的 WsdlDefinitions 列表中选择要公开的 wsdl。下面的覆盖可以选择正确的,而不是 spring 晦涩的解决方案。手动将 url 与 wsdl 定义配对。

    @Bean(name = "servlet-a")
        public ServletRegistrationBean messageDispatcherServletA(ApplicationContext applicationContext) {
            MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        public ServletRegistrationBean messageDispatcherServletA(
                ApplicationContext applicationContext,
                @Qualifier("A") final Wsdl11Definition a) {
                   MessageDispatcherServlet servlet = new MessageDispatcherServlet(){           
                   private static final long serialVersionUID = 8547901522243924975L;
                   @Override
                   protected WsdlDefinition getWsdlDefinition(HttpServletRequest request) {
                    if (yourMethodCheckingForRightExposeUrl(request)) {
                        return a;
                    }
                    else {
                        return null;
                    }
                }           
            };
            servlet.setApplicationContext(applicationContext);
            servlet.setMessageReceiverBeanName("yourSpecificReceiverBeanName");
            ServletRegistrationBean bean = new ServletRegistrationBean(servlet, "/ws/your-endpoint/*"); // star needed to allow any urls
            bean.setName("servlet-a");
            return bean;
        }
    }
    

    在您的示例中,WsdlDefininition 参数可以具有限定名称“BV1”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      相关资源
      最近更新 更多