我使用Apache CXF和Sping Boot 来公开SOAP端点。
@Slf4j
@Configuration
public class SoapWebServiceConfig {
@Bean(name = "cxf")
public SpringBus springBus() {
var loggingFeature = new LoggingFeature();
loggingFeature.addSensitiveProtocolHeaderNames(Set.of("Server", "Accept", "Date"));
loggingFeature.setPrettyLogging(true);
var springBus = new SpringBus();
springBus.getFeatures().add(loggingFeature);
return springBus;
}
@Bean
public ActivateGateway activateGateway() {
return new ActivateGatewayImpl();
}
@Bean
@SneakyThrows
public Endpoint activateGatewayEndpoint(Bus bus, ActivateGateway activateGateway) {
EndpointImpl endpoint = new EndpointImpl(bus, activateGateway);
endpoint.publish("/activateGateway");
return endpoint;
}
@Primary
@Bean(name = "cxfServletRegistration")
public ServletRegistrationBean<CXFServlet> cxfServletRegistration() {
ServletRegistrationBean<CXFServlet> servletRegistrationBean = new ServletRegistrationBean<>(
new CXFServlet(), "/daas/activate/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
}
您可以看到我公开了一个端点,它可以在https://localhost:8081/daas/activate/activateGateway?wsdl
中访问:
...
<wsdl:import location="https://localhost:8081/daas/activate/activateGateway?wsdl=activateGateway.wsdl" namespace="http://schemas.symantec.com/cda/1.0/activateGateway">
</wsdl:import>
<wsdl:binding name="ActivateGatewayServiceSoapBinding" type="ns1:activateGateway">
...
<wsdl:service name="ActivateGatewayService">
<wsdl:port binding="tns:ActivateGatewayServiceSoapBinding" name="activateGatewayPort">
<soap:address location="https://localhost:8081/daas/activate/activateGateway"/>
</wsdl:port>
</wsdl:service>
但是这个location="https://localhost:8081/daas/activate/activateGateway
是无效的,因为这个服务在api网关之后。有没有办法改变“基本url”?例如,改变为这个https://localhost:8081/soap/daas/activate/activateGateway
(注意额外的/soap
前缀)。
这些文件在开始时生成,这不是硬编码。
1条答案
按热度按时间neekobn81#
我还没有找到一个解决方案,但是找到了一个变通的方法。有一个配置指南https://cxf.apache.org/docs/jax-ws-configuration.html,其中提到了
publishedEndpointUrl
,但遗憾的是,由于某些原因,它对我不起作用。我使用的解决方案是server.servlet.context-path=/test
和Ambassador的重写功能的组合: