java - SpringWS Junit测试异常: No endpoint can be found for request [SaajSoapMessage

标签 java spring soap spring-ws spring-test

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:

找不到请求 [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"));
    }
}

测试配置

@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 文件

<?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>

异常

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]

最佳答案

最后我解决了这个问题:只需在 MockWebServiceClient.sendRequestwithPayload() & andExpect(payload( )) 方法。

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>

关于java - SpringWS Junit测试异常: No endpoint can be found for request [SaajSoapMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47758638/

相关文章:

java - 如何离线运行我的 Spring 应用程序?

spring - 在 java 中使用 elasticSearch 2.3.3 按索引名称和类型删除索引

multithreading - delphi中的线程初始化和清理

php - 如何跟踪/调试此错误 SOAP [消息 :protected] => looks like we got no XML document

Java EWS 抛出 NoClassDefFounderror

java - 有人可以检查这个正则表达式语句吗?

java - 如何在基于 Java 的配置中使用@Autowired?

java - 为什么 reflections.getSubTypesOf(Object.class) 找不到枚举?

Java:在文本文件中搜索特定单词

soap - 在 Apache JMeter 的 SOAP 请求中添加签名