Reputation: 387
I use a spring boot ws application together with apache cxf to provide a SOAP web service. All configured URLs use relative paths, so that the application can be used with flexible deployments.
In production environment, the application is running behind a load balancer and forces clients to use https. But the generated wsdl keeps its http protocol although the wsdl itself is exposed using https.
This is the spring endpoint configuration:
@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;
}
How can I adjust the generated wsdl, so that it switches to https? Or better: is it possible to force the protocol to use the same like the exposed wsdl itself?
Best, Lars
Upvotes: 1
Views: 2483
Reputation: 2450
In your spring-boot application, if you are using cxf framework then you can add your custom interceptor to pass on the custom 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);
}
}
You need to configure this interceptor like this in your config file.
EndpointImpl endpoint = new EndpointImpl(bus, communicationPortTypeImpl);
List<Interceptor<? extends Message>> interceptors = new ArrayList<>();
interceptors.add(new MyInInterceptor(endpointUrl));
endpoint.setInInterceptors(interceptors);
endpoint.publish("/myEndPoint");
Upvotes: 2
Reputation: 2450
I also faced a similar issue in my project, and I solved it by using spring boot parameters. We have a ngnix server which takes the requests and forwards to back-end machines having spring boot applications.
Added following parameters in ngnix configuration.
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Scheme https;
Later, added following parameters in spring boot application
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
After this server started appending https to the URL.
Upvotes: 2