Я создал мыльный веб-сервис с Spring WS.Когда я запускаю свое приложение и отправляю запросы SOAP конечной точке, я получаю правильный ответ.Таким образом, сам сервис работает.
Теперь я хочу написать интеграционные тесты, используя 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, который затем используется клиентом-макетом для вызова сервиса, т.е. mockClient = MockWebServiceClient.createClient (applicationContext);
Проблема также может быть связана с тем, как генерируется запрос / ответ винтеграционный тест.Я использую класс RequestCreators и передаю ему тот же 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)\Java\jre1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;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 Systems\NICE Player Codec Pack\\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.8.0_102\bin;C:\Program Files (x86)\Java\jre1.8.0_161\bin;C:\Program Files (x86)\RSA SecurID Token Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Citrix\System32\;C:\Program Files\Citrix\ICAService\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Avaya\IC73\Java\bin;C:\Program Files (x86)\Avaya\IC73\bin\;C:\Users\n0230962\Desktop\apache-maven-3.5.0\bin\;C:\Program Files (x86)\GitExtensions\;C:\Program Files (x86)\Cntlm;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\NICE Systems\NICE Player Release 6\\;C:\Program Files\nodejs;C:\Program Files\Citrix\Virtual Desktop Agent\;C:\Program Files\nodejs\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Git\cmd;C:\Users\n0230962\AppData\Local\Microsoft\WindowsApps;;C:\Users\n0230962\AppData\Local\Programs\Fiddler;C:\Users\n0230962\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\n0230962\AppData\Roaming\npm;C:\Users\n0230962\AppData\Local\Microsoft\WindowsApps;C:\Users\n0230962\AppData\Local\Yarn\bin;C:\Users\n0230962\Desktop\sts-bundle\sts-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)