简体   繁体   English

Spring WS集成测试没有发现端点映射

[英]Spring WS integration test no endpoint mapping found

I am trying to create a Web service with Spring WS. 我正在尝试使用Spring WS创建Web服务。 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. 当我运行我的应用程序并将SOAP请求发送到端点时,我得到了正确的响应。 (I created a SOAP client with Spring WS too). (我也用Spring WS创建了一个SOAP客户端)。 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.) 我收到错误: WARN org.springframework.ws.server.EndpointNotFound - No endpoint mapping found for [SaajSoapMessage {http://my.app/soap/version}GetServiceVersionRequest] (必须审查一些变量和命名原因。如果它们不匹配。如果它发生,我会修复它。在真实的情况下它起作用。)

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. 我还尝试使用原始XML SOAP请求作为内容发送Source对象。 Same error. 同样的错误。 I don't know what i am doing wrong as it works when running the application. 在运行应用程序时,我不知道我做错了什么。 Any idea's? 有任何想法吗?

I do not know which Spring tutorial did you follow. 我不知道您遵循哪个Spring教程。 I followed this one - https://spring.io/guides/gs/producing-web-service/ . 我按照这个 - https://spring.io/guides/gs/producing-web-service/ Spring Boot is used and for *Test I had to change your Spring Boot用于* Test我必须改变你的

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebServiceConfig.class)

to

@RunWith(SpringJUnit4ClassRunner.class) // same
@SpringBootTest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM