我使用Apache + SpringBoot实现了一个SOAP。
在我的端点配置类中,我有
@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 + 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;
}但不起作用。
如有任何意见或建议,我将不胜感激。谢谢!
发布于 2018-02-14 06:04:40
不,不能有相同的端点映射到多个urls,一个端点是为一个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());
});
}
}顺便问一下:休息可能是更好的方式吗?
https://stackoverflow.com/questions/48778052
复制相似问题