SpringWS Junit Test Exception: No endpoint can be found for request [SaajSoapMessage

青春壹個敷衍的年華 提交于 2019-12-10 19:06:29

问题


I am getting an exception when I try to run the Spring Web Service JUnit Test Using the Spring WebService ServerSide Integration Test using MockWebServiceClient. When I run the WebService Junit Test, I'm getting an exception:

No endpoint can be found for request [SaajSoapMessagehttp://schemas.xmlsoap.org/soap/envelope/}Envelope]


Spring_WS_ServletConfig

@Configuration
@EnableWs
@EnableTransactionManagement
// @ComponentScan({ "com.springws.endpoint", "com.mybatis.", "com.mapstruct" })
// @ImportResource({ "classpath:/SpringConfig/spring-database-config.xml" })
public class Spring_WS_ServletConfig extends WsConfigurerAdapter {

    @Bean("StudentServiceWsdl")
    public DefaultWsdl11Definition orders() throws SQLException {
        DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
        definition.setPortTypeName("StudentService_SpringWS_PortType");
        definition.setLocationUri("http://localhost:8080/MvnSpringMcc/StudentService_SpringWS/");
        definition.setTargetNamespace("com.springws.student/LearnSpringWs");
        definition.setServiceName("SpringWSService");
        // definition.setWsdl(new
        // ClassPathResource("/wsdl/StudentService.wsdl"));
        definition.setSchema(studentsSchema());

        return definition;
    }

    @Bean
    public XsdSchema studentsSchema() {
        Resource resource = new ClassPathResource("/wsdl/StudentTask.xsd");
        return new SimpleXsdSchema(new ClassPathResource("/Schema_Wsdl/StudentTask.xsd"));
    }

    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        PayloadValidatingInterceptor validator = new PayloadValidatingInterceptor();
        validator.setValidateRequest(true);
        validator.setValidateResponse(true);
        validator.setSchema(new ClassPathResource("/Schema_Wsdl/StudentTask.xsd"));
    }
}

TestConfig

@Configuration
@ComponentScan({ "com.springws.test", "com.mybatis.mapper.vo", "com.mybatis.service", "com.mapstruct.mapper",
        "com.springws.endpoint", "com.mybatis.mapper" })
//@Import(Spring_WS_ServletConfig.class)
@ImportResource({ "classpath:testResources/spring-ws-test-database-config.xml" })
public class TestConfig {
}

CourseServiceEndPointServerSideIntegrationTest

@EnableTransactionManagement
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestConfig.class, Spring_WS_ServletConfig.class })
public class CourseServiceEndPointServerSideIntegrationTest {
    @Autowired
    ResourceLoader resourceLoader;
    @Autowired
    private ApplicationContext applicationContext;

    private MockWebServiceClient mockClient;

    @Before
    public void createClient() {
        mockClient = MockWebServiceClient.createClient(applicationContext);
    }

    @Test
    public void courseEndpoint() throws Exception {
        Resource requestPayLoad = resourceLoader.getResource("classpath:xmlTestFiles/RequestPayLoad.xml");
        Resource responsePayLoad = resourceLoader.getResource("classpath:xmlTestFiles/ResponsePayLoad.xml");

        mockClient.sendRequest(withPayload(requestPayLoad)).andExpect(payload(responsePayLoad));
    }
}

RequestPayLoad.xml File

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:lear="com.springws.student/LearnSpringWs" xmlns:stud="com.springws.student/StudentSchema">
    <soapenv:Header />
    <soapenv:Body>
        <lear:GetCourseRequest>
            <lear:Course>
                <stud:courseID>100</stud:courseID>
            </lear:Course>
        </lear:GetCourseRequest>
    </soapenv:Body>
</soapenv:Envelope>

Exception

CourseServiceEndpoint(com.springws.endpoint.CourseServiceEndpoint)  Time elapsed: 0.219 sec  <<< FAILURE!
java.lang.AssertionError: No endpoint can be found for request [SaajSoapMessage {http://schemas.xmlsoap.org/soap/envelope/}Envelope]
    at org.springframework.ws.test.support.AssertionErrors.fail(AssertionErrors.java:39)
    at org.springframework.ws.test.server.MockWebServiceClient.sendRequest(MockWebServiceClient.java:184)
    at com.springws.serverside.test.CourseServiceEndPointServerSideIntegrationTest.courseEndpoint(CourseServiceEndPointServerSideIntegrationTest.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Failed tests:   CourseServiceEndpoint(com.springws.serverside.test.CourseServiceEndPointServerSideIntegrationTest): No endpoint can be found for request [SaajSoapMessage {http://schemas.xmlsoap.org/soap/envelope/}Envelope]

回答1:


Finally I was able to solve the problem: Just provide the Soap Payload Information in the MockWebServiceClient.sendRequest's withPayload() & andExpect(payload()) methods.

RequestPayLoad.xml

<lear:GetCourseRequest xmlns:lear="com.springws.student/LearnSpringWs"
    xmlns:stud="com.springws.student/StudentSchema">
    <lear:Course>
        <stud:courseID>100</stud:courseID>
    </lear:Course>
</lear:GetCourseRequest>

ResponsePayLoad.xml

<ns3:GetCourseResponse xmlns:ns2="com.springws.student/StudentSchema"
    xmlns:ns3="com.springws.student/LearnSpringWs">
    <ns3:Course>
        <ns2:courseID>100</ns2:courseID>
        <ns2:courseName>Physics</ns2:courseName>
        <ns2:courseCategory>Physics</ns2:courseCategory>
        <ns2:credit>3.0</ns2:credit>
    </ns3:Course>
</ns3:GetCourseResponse>


来源:https://stackoverflow.com/questions/47758638/springws-junit-test-exception-no-endpoint-can-be-found-for-request-saajsoapmes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!