Reputation: 1443
I am trying to create a Web service with Spring WS. I followed their guide and i set up everything fine. When i run my application and send SOAP requests to the endpoint i get the right response. (I created a SOAP client with Spring WS too). So i got that going.
Now i want to write tests. I got a unit test testing the method for the endpoint. All good and green. Right return value and such. Now i also want an integration test. This is where it goes wrong. I get the error: WARN org.springframework.ws.server.EndpointNotFound - No endpoint mapping found for [SaajSoapMessage {http://my.app/soap/version}GetServiceVersionRequest]
(Had to censor some variables and naming for reasons. Could be they don't match. I will fix it if it occurs. In the real situation it works.)
I have the following configuration:
@EnableWs
@Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
@Bean(name = "serviceVersion")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema serviceVersionSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("ServiceVersionPort");
wsdl11Definition.setLocationUri("/ws/version");
wsdl11Definition.setTargetNamespace("http://my.app/soap/version");
wsdl11Definition.setSchema(serviceVersionSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema serviceVersionSchema() {
return new SimpleXsdSchema(new ClassPathResource("xsd/ServiceVersionRequest.xsd"));
}
}
I have the following endpoint:
@Endpoint
public class GetServiceVersionEndpoint {
@PayloadRoot(namespace = "http://my.app/soap/version", localPart = "GetServiceVersionRequest")
@ResponsePayload
public JAXBElement<GetServiceVersionResponse> getServiceVersion(@RequestPayload GetServiceVersionRequest request) {
GetServiceVersionResponse response = new GetServiceVersionResponse();
ServiceVersion serviceVersion = new ServiceVersion();
serviceVersion.setMajor(1);
serviceVersion.setMinor(0);
serviceVersion.setRevision(0);
serviceVersion.setBuild(1);
response.setVersion(serviceVersion);
return new ObjectFactory().createGetServiceVersionResponse(response);
}
}
This is my test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebServiceConfig.class)
public class GetServiceVersionEndpointIntegrationTest {
@Inject
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@Before
public void init(){
mockClient = MockWebServiceClient.createClient(applicationContext);
}
@Test
public void testValidServiceVersionRequest() throws Exception {
JAXBElement<GetServiceVersionRequest> request = new ObjectFactory().createGetServiceVersionRequest(new GetServiceVersionRequest());
ServiceVersion serviceVersion = new ServiceVersion();
serviceVersion.setMajor(1);
serviceVersion.setMinor(0);
serviceVersion.setRevision(0);
serviceVersion.setBuild(1);
GetServiceVersionResponse getServiceVersionResponse = new GetServiceVersionResponse();
getServiceVersionResponse.setVersion(serviceVersion);
JAXBElement<GetServiceVersionResponse> response = new ObjectFactory().createGetServiceVersionResponse(getServiceVersionResponse);
mockClient
.sendRequest(withPayload(new JAXBSource(JAXBContext.newInstance(GetServiceVersionRequest.class), request)))
.andExpect(payload(new JAXBSource(JAXBContext.newInstance(GetServiceVersionResponse.class), response)));
}
}
The stacktrace is:
java.lang.AssertionError: No endpoint can be found for request [SaajSoapMessage {http://my.app/soap/version}GetServiceVersionRequest]
at org.springframework.ws.test.support.AssertionErrors.fail(AssertionErrors.java:39)
at org.springframework.ws.test.server.MockWebServiceClient.sendRequest(MockWebServiceClient.java:184)
at nl.app.endpoint.GetServiceVersionEndpointIntegrationTest.testValidServiceVersionRequest(GetServiceVersionEndpointIntegrationTest.java:78)
I also tried sending a Source
object with a raw XML SOAP request as content. Same error. I don't know what i am doing wrong as it works when running the application. Any idea's?
Upvotes: 3
Views: 3720
Reputation: 10549
I do not know which Spring tutorial did you follow. I followed this one - https://spring.io/guides/gs/producing-web-service/. Spring Boot is used and for *Test I had to change your
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebServiceConfig.class)
to
@RunWith(SpringJUnit4ClassRunner.class) // same
@SpringBootTest
Upvotes: 1