具有一个命名空间的多个 SOAP 端点本地部分 [英] Multiple SOAP endpoints with one namespace & localpart

查看:34
本文介绍了具有一个命名空间的多个 SOAP 端点本地部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SpringBoot 创建了一个 SOAP Web 服务服务器,并且能够成功创建一个端点.但是,我无法创建多个端点并使用不同的 URL 访问它们.我想通过 URL 来处理流程来访问.

I created a SOAP web service server with SpringBoot and I was able to successfully create one endpoint. However, I cannot create multiple endpoints and access them with different URLs. I want to handle the process by URL to access.

每个端点接收到的 SOAP 消息具有相同的架构.(命名空间和本地部分是一样的!!!)而且我不想公开 WSDL.

The SOAP message received by each endpoint has the same schema. (Namespace and localpart are the same !!!) And I don't want to make the WSDL public.

例如.

userA 将以下 SOAP 消息发送到以下 URL:http://soap.example.com/ws/userA

userA sends the following SOAP message to the following URL: http://soap.example.com/ws/userA

<S:Envelope>
    <SOAP-ENV:Header>
    </SOAP-ENV:Header>
    <S:Body>
        <testsoap:post
            xmlns:testsoap="http://soap.example.com/">
            <testsoap:message>
                I am UserA
            </testsoap:message>
        </testsoap:post>
    </S:Body>
</S:Envelope>

userB 将以下 SOAP 消息发送到 URL:http://soap.example.com/ws/userB

userB sends the following SOAP message to the URL: http://soap.example.com/ws/userB

<S:Envelope>
    <SOAP-ENV:Header>
    </SOAP-ENV:Header>
    <S:Body>
        <testsoap:post
            xmlns:testsoap="http://soap.example.com/">
            <testsoap:message>
                I am UserB
            </testsoap:message>
        </testsoap:post>
    </S:Body>
</S:Envelope>

源代码如下.

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Autowired
    CustomConfig customConfig;

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*");
    }
}

我想访问 http://soap.example.com/ws/userA

@Endpoint
public class SoapRequestEndpoint {
    private static final String NAMESPACE_URI = "http://soap.example.com/";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "post")
    @ResponsePayload
    public JAXBElement<PostResponse> postForA(MessageContext messageContext) {
        // do something for userA
    }
}

我想访问 http://soap.example.com/ws/userB

@Endpoint
public class SoapRequestEndpoint {
    private static final String NAMESPACE_URI = "http://soap.example.com/";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "post")
    @ResponsePayload
    public JAXBElement<PostResponse> postForB(MessageContext messageContext) {
        // do something for userB
    }
}

谢谢.

2019 年 9 月 24 日更新
从那以后我一直在努力,但我仍然不明白.我不认为它写在官方参考中.你有什么想法吗?

Updated on September 24th, 2019
I have worked hard since then, but I still don't understand. I don't think it's written in the official reference. Do you have any ideas?

2019 年 10 月 3 日更新
我还没有解决.如果是这种情况,将很难工作.请帮助某人.

Updated on October 3, 2019
I haven't solved it yet. If this is the case, it will be difficult to work. Please help someone.

推荐答案

尝试在 WebServiceConfig 类中创建额外的 Wsdl11Definition 方法,并用@Bean(name = "UserB") 注释该方法.

Try to create an additional Wsdl11Definition method in the WebServiceConfig class and annotate the method with @Bean(name = "UserB").

您只显示了 WebServiceConfig 类中的一个片段,我假设该类中没有.

You have only shown a snippet from your WebServiceConfig class, I am assuming that this is absent from the class.

您的类应该类似于:

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Autowired
    CustomConfig customConfig;

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*");
    }
}

@Bean(name = "userA")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema [randomMethodSchema]) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("userAPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://soap.example.com/");
        wsdl11Definition.setSchema([randomMethodSchema]);
        return wsdl11Definition;
    }

@Bean(name = "userB")
    public DefaultWsdl11Definition defaultWsdl11Definition2(XsdSchema [randomMethodSchema]) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("userBPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://soap.example.com/");
        wsdl11Definition.setSchema([randomMethodSchema]);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema [randomMethodSchema]() {
        return new SimpleXsdSchema(new ClassPathResource([schema name].xsd));
    }
}

HTH

这篇关于具有一个命名空间的多个 SOAP 端点本地部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆