【问题标题】:Apache CXF + SpringBoot: Can I publish multiple endpoints for one SOAP web-service?Apache CXF + SpringBoot:我可以为一个 SOAP Web 服务发布多个端点吗?
【发布时间】:2018-02-14 00:51:10
【问题描述】:

我已经使用 Apache CXF + SpringBoot 实现了一个 SOAP Web 服务。

在我的端点配置类中,我有

@Bean
public Endpoint endpoint()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl());
    endpoint.publish("/myservice");
    return endpoint;
}

这会创建一个 Web 服务端点为 https://host:port/myService

对于这个服务,我需要公开多个端点——比如—— https://host:port/tenant1/myService
https://host:port/tenant2/myService
https://host:port/tenant3/myService

这是一种 REST 端点——即,我试图在服务端点中传递tenantId 变量。

这在 Apache CXF + Springboot 中可行吗?

我试过了-

@Bean
public Endpoint endpoint()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    String[] pathArray = {"tenant1", "tenant2", "tenant3"};
    for (int i = 0; i < pathArray.length; i++)
    {
        endpoint.publish("/" + pathArray[i] + "/myservice");
    }
    return endpoint;
}

但它不起作用。

如果有任何意见/建议,我将不胜感激。谢谢!

【问题讨论】:

  • 您实施了哪种解决方案?因为我必须从 url 列表中动态创建多个端点。

标签: web-services spring-boot soap cxf


【解决方案1】:

不,您不能将相同的端点映射到多个 url,为一个 wsdl 文件创建一个端点,该文件将生成为单个类。从 url 我假设你想基于租户在多个 url 上托管相同的服务。在这种情况下,您必须为每个租户创建端点。

@Bean
public Endpoint endpoint1()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    endpoint.publish("/tenant1/" + pathArray[i] + "/myservice");
    return endpoint;
}

@Bean
public Endpoint endpoint2()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    endpoint.publish("/tenant1/" + pathArray[i] + "/myservice");
    return endpoint;
}

@Configuration
public class CxfConfiguration implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {

        Arrays.stream(new String[] { "tenant1", "tenant2" }).forEach(str -> {
            Bus bus = factory.getBean(Bus.class);
            JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
            bean.setAddress("/" + str + "/myService");
            bean.setBus(bus);
            bean.setServiceClass(HelloWorld.class);
            factory.registerSingleton(str, bean.create());
        });

    }


}

顺便说一句:使用 REST 可能更好吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 2021-08-13
    • 2022-08-21
    • 2012-04-02
    相关资源
    最近更新 更多