Multiple Spring WS Endpoints on different URL's - spring

I'm using Spring Boot and like in the example https://spring.io/guides/gs/producing-web-service/
WS Endpoints are exposed on /ws/* with MessageDispatcher:
#Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
I want to have 2 endpoints on different URL's. Is that possible?

Related

ServletRegistrationBean in Spring cloud

I have recently migrated the application to Spring Cloud Gateway from zuul filter for routing to multiple microservices. I have a filter which is written in
native code (HTTPServlet). In Spring application initialization, I am registering that Servlet as below
#Bean
public ServletRegistrationBean oAuthCodeReceiverServletBean() {
ServletRegistrationBean oauthCodeReceiverServletBean = new ServletRegistrationBean(
new OAuthCodeRecieverServlet(), "/login/oauth/codereceiver");
return oauthCodeReceiverServletBean;
}
#Bean
public FilterRegistrationBean<OAuthFilter> securityRegistrationBean() {
FilterRegistrationBean<OAuthFilter> registrationBean = new FilterRegistrationBean<>(oAuthFilter);
registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
registrationBean.addUrlPatterns("/*");
return registrationBean;
}
But the Filter is not at all called. The filters that implements GlobalFilter are called. Is there a solution handle ?
Please note I dont have option to update the native code OauthFilter.

Defining multiple endpoints for multiple soap web services in spring boot application

I have a servlet mapping issue in spring boot application with multiple soap web services. I have two (or more) WebServices with different mappings.
Service A -> Endpoint1
Service B -> Endpoint2
Once I deploy spring boot application with two MessageDispatcherServlets , Service A and B both can be accessed with Endpoint1 only. I don't know how I can map Endpoint1 url to ServiceA and Endpoint2 to ServiceB.
Please check sample of my code for Service-A. Code is similar for Service-B.
#Bean(name = "ServiceA")
public Wsdl11Definition wsdl11DefinitionImportAgent() {
SimpleWsdl11Definition simpleWsdl11Definition = new SimpleWsdl11Definition();
simpleWsdl11Definition.setWsdl(new ClassPathResource("/wsdl/ServiceA.wsdl"));
return simpleWsdl11Definition;
}
#Bean
public ServletRegistrationBean messageDispatcherServletServiceA(ApplicationContext
applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/ServiceA");
}

Spring boot MessageDispatcherServlet overriding DispatcherServlet. how to skip overriding and register both DispatcherServlet?

in a single application, I m trying to use soap as well as rest web service. and each servlet is given different URI, below is the code of config class.
The question is: only soap service URL is working fine but for the rest on getting 405 error.
#EnableWs
#Configuration
public class WebServiceConfig {
#Bean
public ServletRegistrationBean RsRegistrationBean(ApplicationContext applicationContext) {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setApplicationContext(applicationContext);
return new ServletRegistrationBean(servlet,"/rest/*");
}
#Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(
ApplicationContext context) {
MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
messageDispatcherServlet.setApplicationContext(context);
messageDispatcherServlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(messageDispatcherServlet,"/");
}
}
Remove your WebServiceConfig class, as both are auto-configured by Spring Boot already (as of Spring Boot 1.4). Add the following to your application.properties
spring.mvc.servlet.path=/rest
spring.webservices.path=/
Now you leverage the Spring Boot proivded infrastructure instead of fighting with it.

Java configuration for SAAJInInterceptor and WSS4JInInterceptor beans

I have a web application that provides a soap web service using apache cxf and spring boot. So I have no xml file in my classpath to configure my beans, they are all configured in java configuration.I would like to set up authentication with ws-security from cxf.
So I would like to know if there are java configurations for the SAAJInInterceptor and WSS4JInInterceptor beans for example like this:
#Bean
public ServletRegistrationBean cxfServlet() {
ServletRegistrationBean servlet = new ServletRegistrationBean(new CXFServlet(), "/services/*");
servlet.setLoadOnStartup(1);
return servlet;
}
You just have to add the interceptor when you create your endpoint :
Map<String,Object> interceptorConfig = new HashMap<String,Object>();
// set the properties of you WSS4J config
// ...
WSS4JInInterceptor myInterceptor = new WSS4JInInterceptor(interceptorConfig);
myEndpoint.getInInterceptors().add(myInterceptor);
Another solution is by using annotation with #InInterceptors

How to integrate Spring Boot and Resteay

Although there are a lot of code example on the internet of integrating Spring Boot/Spring and Resteasy, but most of them are out of data or even don't work.
I am look at the latest Resteasy document, try to create a instance of SpringBeanProcessorServletAware in my config bean.
#Bean
public ServletListenerRegistrationBean<ResteasyBootstrap> resteasyBootstrapRegistratio() {
ServletListenerRegistrationBean<ResteasyBootstrap> registration = new ServletListenerRegistrationBean<>();
registration.setListener(new ResteasyBootstrap());
return registration;
}
#Bean
public ServletRegistrationBean resteasyServletRegistratio() {
ServletRegistrationBean registration = new ServletRegistrationBean();
registration.setServlet(new HttpServletDispatcher());
registration.addUrlMappings("/*");
return registration;
}
#Bean
public SpringBeanProcessorServletAware springBeanProcessorServletAware() {
SpringBeanProcessorServletAware springBeanProcessor = new SpringBeanProcessorServletAware();
return springBeanProcessor;
}
But it will throw Nullpoint exception. It seems like the servletContext is required to make SpringBeanProcessorServletAware work.
Then I try to inject servletContext. But the bean SpringBeanProcessorServletAware is being created before ServletContextInitializer finished.
How to make some bean created after ServletContextInitializer is finished?
Am I wrong in do the integration between Spring Boot and Resteasy.

Resources