【问题标题】:Spring configure two @Endpoint, each with a unique wsdl fileSpring配置两个@Endpoint,每个都有一个唯一的wsdl文件
【发布时间】:2018-03-29 12:50:02
【问题描述】:

我已经能够获得一个带有 wsdl 文件的 @Endpoint:

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


    @Bean(name = "wsdl-event")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/event.wsdl"));
        return wsdl11Definition;
    }

    @Bean
    AnnotationActionEndpointMapping endpointMapping() {
        AnnotationActionEndpointMapping mapping = new AnnotationActionEndpointMapping();
        return mapping;
    }
}

但对于我的用例,我有两个需要处理的 wsdl 文件。最初我设置了一个 RestController 并从 xml POST 请求中解组了正文,但我现在想尝试纯弹簧方式。

我假设我需要创建两个 MessageDispatcherServlet,每个 wsdl 定义一个,但我不知道如何正确映射或注册我的端点。

有什么想法吗?

摆弄我创建了重复的(具有不同的 wsdl 和 bean 名称)WSDLdefinition bean,messageDispatcherServletServletRegistrationBean 给了我错误Servlet messageDispatcherServlet was not registered (possibly already registered?),而我的端点似乎出现了,但是 spring 返回一个 404对上述端点的任何请求。

Spring-ws 版本:3

【问题讨论】:

    标签: java spring soap spring-ws endpoint


    【解决方案1】:

    我的假设是每个 Spring @Enpoint 类都需要不同的路径。我现在意识到我只需要注册一个MessageDispatcherServlet 并定义处理传入请求所需的 wsdl 文件。

    由于我需要两个不同的 wsdl 文件,因此我可以通过创建一个包含 MessageDispatcherServletServletRegistrationBean 和两个 Wsdl11Definition bean(每个 wsdl 文件一个)来支持这两者,并在我的 @Endpoint 类中设置namespace 和 localPart 作为@PayloadRoot 注释的一部分。

    配置类

    // Configuration class
    @EnableWs
    @Configuration
    public class SpringConfiguration 
    {
        @Bean
        public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) 
        {
            MessageDispatcherServlet servlet = new MessageDispatcherServlet();
            servlet.setApplicationContext(applicationContext);
            servlet.setTransformWsdlLocations(true);
    
            return new ServletRegistrationBean(servlet, "/soap");
        }
    
        @Bean
        AnnotationActionEndpointMapping annotationActionEndpointMapping() 
        {
            AnnotationActionEndpointMapping mapping = new AnnotationActionEndpointMapping();
            // add any interceptors here for features like logging
            return mapping;
        }
    
        // wsdl file A
        @Bean(name="wsdl-definition-A")
        public Wsdl11Definition wsdl11DefinitionA()
        {
            SimpleWsdl11Definition def = new SimpleWsdl11Definition();
            wsdl11Definition.setWsdl(new ClassPathResource("wsdl/A.wsdl"));
    
            return wsdl11Definition;
        }
    
        // wsdl file B
        @Bean(name="wsdl-definition-B")
        public Wsdl11Definition wsdl11DefinitionA()
        {
            SimpleWsdl11Definition def = new SimpleWsdl11Definition();
            wsdl11Definition.setWsdl(new ClassPathResource("wsdl/B.wsdl"));
    
            return wsdl11Definition;
        }
    }
    

    如果您需要不同的端点路径而不是一个。我假设您需要调整上面定义的ServletRegistrationBean。现在所有内容都映射到"/soap"

    这里是端点:

    @Endpoint
    public class AServer
    {
        private final static String NAMESPACE_URI = "http://some.namespace/v3/idk/am/i/even/real";
        private final static String LOCALPART = "XMLElementName";
        private final SomeMarshaller marshaller;
    
        @Autowired
        public EventServer(EventReceiveMarshaller marshaller) 
        {
            // I use a marshaller class to simplify my life
            this.marshaller = marshaller; 
        }
    
        @Override
        @ResponsePayload
        @PayloadRoot(namespace = NAMESPACE_URI, localPart = LOCALPART)
        public JAXBElement<SomeResponseMessageType> triggerResponse(@RequestPayload JAXBElement<SomeRequestMessageType> msg) {
    
            // do something with the `msg` request
    
            // Send a OK response
            return this.marshaller.createReply(msg);
        }
    }
    

    然后BServerAServer 完全相同,除了NAMESPACE_URILOCALPART 因为它们依赖于它们各自的wsdl 文件。

    【讨论】:

    • 您好,我有相同的配置(一个带有多个 wsdl 和端点的soap WebService)。您提供的解决方案可以完成这项工作,但在我的情况下,我无法生成 wsdl。生成和显示 wsdl 的修复方法是将 ServletRegistrationBean 实例中声明的 url 映射从“/soap”更改为“/soap/*”
    • 能否请您在这里指导我:stackoverflow.com/questions/62081712/…
    猜你喜欢
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 2016-11-21
    • 2018-05-17
    • 1970-01-01
    相关资源
    最近更新 更多