[英]Change schemaLocation and soap:address location in runtime generated WSDL with JAX-WS
[英]cxf generated wsdl: change soap address location protocol to https
我使用spring boot ws應用程序和apache cxf一起提供SOAP Web服務。 所有配置的URL都使用相對路徑,因此該應用程序可以與靈活的部署一起使用。
在生產環境中,該應用程序在負載平衡器后面運行,並強制客戶端使用https。 但是盡管wsdl本身是使用https公開的,但是生成的wsdl仍保留其http協議。
這是spring端點配置:
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), requestStatusApplicationService());
RequestStatusReceiverService requestStatusReceiverService = requestStatusReceiverService();
endpoint.setServiceName(requestStatusReceiverService.getServiceName());
endpoint.setWsdlLocation(requestStatusReceiverService.getWSDLDocumentLocation().toString()); // also a relative path
endpoint.publish("/relative-path-endpoint");
return endpoint;
}
如何調整生成的wsdl,以便切換到https? 或者更好:是否可以強制協議使用與暴露的wsdl本身相同的協議?
最好的,拉斯
我的項目中也遇到了類似的問題,我通過使用spring boot參數解決了這個問題。 我們有一個ngnix服務器,它接收請求並轉發到具有Spring Boot應用程序的后端計算機。
在ngnix配置中添加了以下參數。
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Scheme https;
后來,在Spring Boot應用程序中添加了以下參數
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
此服務器開始將https附加到URL之后。
在spring-boot應用程序中,如果使用cxf框架,則可以添加自定義攔截器以傳遞自定義URL。
public class MyInInterceptor extends AbstractInDatabindingInterceptor {
private String url;
public CustomInInterceptor(String url) {
super(Phase.USER_STREAM);
this.url = url;
}
@Override
public void handleMessage(Message message) throws Fault {
message.put("org.apache.cxf.request.url", url);
}
}
您需要在配置文件中像這樣配置此攔截器。
EndpointImpl endpoint = new EndpointImpl(bus, communicationPortTypeImpl);
List<Interceptor<? extends Message>> interceptors = new ArrayList<>();
interceptors.add(new MyInInterceptor(endpointUrl));
endpoint.setInInterceptors(interceptors);
endpoint.publish("/myEndPoint");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.