Search code examples
spring-bootspring-securityspring-ws

Spring-WS SOAP Endpoint 405 Method not allowed


Hi I'm trying to make an @endpoint SOAP service, but when I try to get the WSDL I get an 405 Method Not Allowed.

There is my service endpoint :

@Endpoint
public class SubscribeMemberService {

        public static final String NAMESPACE_URI = "urn:v1.webservice.subscription.test.org";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "subscribe")
    @ResponsePayload
    public SubscribeMemberResponse subscribe(@RequestPayload  SubscribeMemberRequest request) throws SubscribeMemberFault_Exception {
        LOG.info("request received: LastName:" + request.getName().getLastName());

            SubscribeMemberResponse response = new SubscribeMemberResponse();
            response.setInfoMessage("Subscription of  " + request.getName().getLastName());
            LOG.info("sending response:" + request.getName().getLastName());
            return response;

    }

}

And there is my WS config :

@EnableWs
@Configuration
@ComponentScan("org.test")
public class WebServiceConfig  extends WsConfigurerAdapter {

        @Bean
        public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
                MessageDispatcherServlet servlet = new MessageDispatcherServlet();
                servlet.setApplicationContext(applicationContext);
                servlet.setTransformWsdlLocations(true);
                return new ServletRegistrationBean(servlet, "/ws/*");
        }

        @Bean(name = "subscribeMember")
        public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema subscribeMember) {
                DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
                wsdl11Definition.setPortTypeName("subscribeMemberPort");
                wsdl11Definition.setLocationUri("/ws");
                wsdl11Definition.setTargetNamespace(SubscribeMemberService.NAMESPACE_URI);
                wsdl11Definition.setSchema(subscribeMember);
                return wsdl11Definition;
        }

        @Bean
        public XsdSchema subscribeMemberSchema() {
                return new SimpleXsdSchema(new ClassPathResource("META-INF/wsdl/subscribeMember.xsd"));
        }
}

Could it be link to the WebSecurityConfigurerAdapter? Because on the /ws/* I don't have an 404 not found, but I get 405 not allowed. Any ideas?

Note : the security filter in the WebSecurityConfigurerAdapter class is

protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic()
                .and()
                .authorizeRequests()
                .anyRequest().hasRole("mySuperRole").and()
                .csrf().disable();
}

Solution

  • I found the solution:

    1. I disabled the WebSecurityConfigurerAdapter to be sure that was not an issue coming from the security.
    2. I discover an issue in the logs : "SAAJ0511: Unable to create envelope from given source"
    3. To fix the issue I decided to use the maven plugin "jaxb2-maven-plugin" from the official tuto (https://spring.io/guides/gs/producing-web-service/#_generate_domain_classes_based_on_an_xml_schema) in place of "jaxws-maven-plugin". And I moved the wsdl files in /resources.
    4. I converted my SOAP exception with this tutorial : http://memorynotfound.com/spring-ws-add-detail-soapfault-exception-handling/
    5. I re-enabled the the WebSecurityConfigurerAdapter