我创建了带有Spring WS的SOAP Web服务。当我运行应用程序并将肥皂请求发送到端点时,我会得到正确的响应。因此服务本身正在工作。
现在,我想使用Spring的MockWebserviceClient编写集成测试,但我会遇到错误:
org.springframework.ws.NoEndpointFoundException: No endpoint can be found for request [SaajSoapMessage {http://tempuri.org/}StartSessionGetOffers]
因为当我旋转应用程序时,该服务工作起作用,但是在运行测试时不行,所以我在启动时在日志中寻找差异。当应用程序旋转时,我会看到与肥皂服务映射有关的日志,这些日志在测试上下文中不存在:
INFO ServletRegistrationBean - Servlet messageDispatcherServlet mapped to [/soapWebService/*]
我了解测试类上@contextConfiguration注释是负责在ApplicationContext上注册SOAP服务的,然后由模拟客户端使用该服务来调用该服务,即operclient = oightebClient = mockwebserviceclient.createclient.createclient.createclient(applicationContext(;
问题也可能与集成测试中的请求/响应的生成方式有关。我正在使用RequestCreators类,并将其传递给我已经测试和知道工作的SOAP请求XML。该请求看起来正确生成。
但它不起作用,我没有想法。
我的测试课:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { WebServiceConfig.class })
public class InteractProxyEndpointTest {
@Autowired
ApplicationContext applicationContext;
@Autowired
ResourceLoader resourceLoader;
MockWebServiceClient mockClient;
@Before
public void createClient() {
Assert.assertNotNull(applicationContext);
mockClient = MockWebServiceClient.createClient(applicationContext);
}
@Test
public void interactEndpointTest() throws IOException {
final RequestCreator requestCreator; // Creator for the request
final ResponseMatcher responseMatcher; // Matcher for the response
mockClient = MockWebServiceClient.createClient(applicationContext);
Resource requestPayLoad = resourceLoader.getResource("classpath:com/lmig/dragon/controller/test/requestPayload.xml");
Resource responsePayload = resourceLoader.getResource("classpath:com/lmig/dragon/controller/test/responsePayload.xml");
requestCreator = RequestCreators
.withSoapEnvelope(requestPayLoad);
responseMatcher = ResponseMatchers.soapEnvelope(responsePayload);
// Calls the endpoint
mockClient.sendRequest(requestCreator).andExpect(responseMatcher);
}
}
我的WebServiceConfig
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<Servlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet,"/soapWebService/*");
}
@Bean(name = "interactOffers")
public DefaultWsdl11Definition interactWsdl11Definition(XsdSchema interactOffersSchema) {
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
definition.setPortTypeName("InteractOffersPort");
definition.setTargetNamespace("http://tempuri.org/StartSessionGetOffers");
definition.setLocationUri("/soapWebService");
definition.setSchema(interactOffersSchema);
return definition;
}
@Bean
public XsdSchema interactOffersSchema() {
return new SimpleXsdSchema(new ClassPathResource("interact-offers.xsd"));
}
}
requestPayload.xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:nba="http://schemas.datacontract.org/2004/07/NBAInteract.DataContracts">
<soapenv:Header/>
<soapenv:Body>
<tem:StartSessionGetOffers>
<!--Optional:-->
<tem:request>
<!--Optional:-->
<nba:EmployeeId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<!--Optional:-->
<nba:LMCustId></nba:LMCustId>
<nba:LMHouseholdId>/nba:LMHouseholdId>
<nba:SessionId></nba:SessionId>
<!--Optional:-->
<nba:CdiHouseholdId></nba:CdiHouseholdId>
<!--Optional:-->
<nba:EventName></nba:EventName>
<!--Optional:-->
<nba:LMInteractionChannel></nba:LMInteractionChannel>
<!--Optional:-->
<nba:OfferCount></nba:OfferCount>
<!--Optional:-->
<nba:UserAuxCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</tem:request>
</tem:StartSessionGetOffers>
</soapenv:Body>
</soapenv:Envelope>
测试日志:
INFO DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener]
INFO DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@445629, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1b9a632, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@1d250c6, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1f50bcc, org.springframework.test.context.support.DirtiesContextTestExecutionListener@126e945, org.springframework.test.context.transaction.TransactionalTestExecutionListener@1a65a25, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@c562f7, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@18ba8c8, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@1bb137d, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@9d0b9d, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@1301423, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1112965]
INFO GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@1c758ac: startup date [Sat May 04 21:25:01 PDT 2019]; root of context hierarchy
INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'webServiceConfig' of type [com.lmig.dragon.WebServiceConfig$$EnhancerBySpringCGLIB$$9e2d774] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$8ca20d2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO AnnotationActionEndpointMapping - Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
INFO SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
INFO SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
WARN EndpointNotFound - No endpoint mapping found for [SaajSoapMessage {http://tempuri.org/}StartSessionGetOffers]
ERROR MockWebServiceClient - Could not send request
org.springframework.ws.NoEndpointFoundException: No endpoint can be found for request [SaajSoapMessage {http://tempuri.org/}StartSessionGetOffers]
at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:217) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:176) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.test.server.MockWebServiceClient.sendRequest(MockWebServiceClient.java:178) ~[spring-ws-test-3.0.7.RELEASE.jar:na]
at com.lmig.dragon.controller.test.InteractProxyEndpointTest.interactEndpointTest(InteractProxyEndpointTest.java:60) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) [.cp/:na]
INFO GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@1c758ac: startup date [Sat May 04 21:25:01 PDT 2019]; root of context hierarchy
完整的应用程序启动日志(当服务按预期工作时(:
INFO PropertySourceBootstrapConfiguration - Located property source: CompositePropertySource {name='vault', propertySources=[LeaseAwareVaultPropertySource {name='secret/np/us-consumer-markets/uscm-contact-center-technology/trove/test/test/trove-credentials'}, LeaseAwareVaultPropertySource {name='secret/np/us-consumer-markets/uscm-contact-center-technology/trove/test/test/application'}]}
INFO Application - No active profile set, falling back to default profiles: default
INFO AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@10d6318: startup date [Fri May 03 13:44:03 PDT 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@959ece
INFO GenericScope - BeanFactory id=3c934013-f2bf-3e58-ac35-c5b28f255634
INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'webServiceConfig' of type [com.lmig.dragon.WebServiceConfig$$EnhancerBySpringCGLIB$$2cbed7af] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$2ba6210d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO AnnotationActionEndpointMapping - Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$a3285f0b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO TomcatWebServer - Tomcat initialized with port(s): 443 (http)
INFO Http11NioProtocol - Initializing ProtocolHandler ["http-nio-443"]
INFO StandardService - Starting service [Tomcat]
INFO StandardEngine - Starting Servlet Engine: Apache Tomcat/8.5.28
INFO AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:Program Files (x86)Javajre1.8.0_161bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:/Program Files (x86)/Java/jre1.8.0_161/bin/client;C:/Program Files (x86)/Java/jre1.8.0_161/bin;C:/Program Files (x86)/Java/jre1.8.0_161/lib/i386;C:Program Files (x86)Nice SystemsNICE Player Codec Pack\;C:ProgramDataOracleJavajavapath;C:Program Files (x86)Common FilesOracleJavajavapath;C:Program Files (x86)Javajdk1.8.0_102bin;C:Program Files (x86)Javajre1.8.0_161bin;C:Program Files (x86)RSA SecurID Token Common;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesCitrixSystem32;C:Program FilesCitrixICAService;c:Program Files (x86)Microsoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100DTSBinn;C:Program FilesMicrosoftWeb Platform Installer;C:Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Files (x86)AvayaIC73Javabin;C:Program Files (x86)AvayaIC73bin;C:Usersn0230962Desktopapache-maven-3.5.0bin;C:Program Files (x86)GitExtensions;C:Program Files (x86)Cntlm;C:Program Files (x86)Microsoft SQL Server110ToolsBinn;C:Program FilesMicrosoft SQL Server110DTSBinn;C:Program Files (x86)Microsoft SQL Server110ToolsBinnManagementStudio;C:Program Files (x86)Microsoft SQL Server110DTSBinn;C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssemblies;C:Program Files (x86)Microsoft SQL Server140ToolsBinn;C:Program Files (x86)Microsoft SQL Server140DTSBinn;C:Program Files (x86)Microsoft SQL ServerClient SDKODBC130ToolsBinn;C:Program Files (x86)Microsoft SQL Server140ToolsBinnManagementStudio;C:Program Files (x86)NICE SystemsNICE Player Release 6\;C:Program Filesnodejs;C:Program FilesCitrixVirtual Desktop Agent;C:Program Filesnodejs;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesTortoiseGitbin;C:Program Files (x86)Yarnbin;C:Program FilesGitcmd;C:Usersn0230962AppDataLocalMicrosoftWindowsApps;;C:Usersn0230962AppDataLocalProgramsFiddler;C:Usersn0230962AppDataLocalProgramsMicrosoft VS Codebin;C:Usersn0230962AppDataRoamingnpm;C:Usersn0230962AppDataLocalMicrosoftWindowsApps;C:Usersn0230962AppDataLocalYarnbin;C:Usersn0230962Desktopsts-bundlests-3.9.1.RELEASE;;.]
INFO [/] - Initializing Spring embedded WebApplicationContext
INFO ContextLoader - Root WebApplicationContext: initialization completed in 1250 ms
INFO ServletRegistrationBean - Servlet messageDispatcherServlet mapped to [/soapWebService/*]
INFO ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]
INFO FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
INFO FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
INFO FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
INFO FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
INFO RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@10d6318: startup date [Fri May 03 13:44:03 PDT 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@959ece
[org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
INFO AnnotationMBeanExporter - Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
INFO AnnotationMBeanExporter - Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=10d6318,type=ConfigurationPropertiesRebinder]
INFO Http11NioProtocol - Starting ProtocolHandler ["http-nio-443"]
INFO NioSelectorPool - Using a shared selector for servlet write/read
INFO TomcatWebServer - Tomcat started on port(s): 443 (http) with context path ''
INFO Application - Started Application in 4.705 seconds (JVM running for 5.539)
添加@componentscan到您的WebServiceConfig,可以喜欢以下内容:
@EnableWs
@Configuration
@ComponentScan
public class WebServiceConfig extends WsConfigurerAdapter
{
....
}