Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting CXF and Jersey together causes Spring conflicts?
    primarykey
    data
    text
    <p>I have an app that uses CXF as a SOAP client and Jersey to present REST services, with the Jersey classes managed by Spring. This works fine running in Tomcat; however when attempting to test with JerseyTest I get Spring conflicts; it appears JerseyTest doesn't shut-down the Spring context correctly.</p> <p>The test initialisation for Jersey looks like:</p> <pre><code>public MailProviderTest() throws Exception { super(new WebAppDescriptor.Builder("net.haltcondition.service.rest") .contextPath("") .contextParam("contextConfigLocation", "classpath:applicationContext.xml") .servletClass(SpringServlet.class) .contextListenerClass(ContextLoaderListener.class) .build()); } </code></pre> <p>The CXF tests (which talk to our upstream provider's test servers) looks like:</p> <pre><code>@Before public void setup() { // We need to do this the hard way to set the test endpoint rather than the default JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(Soap.class); factory.setAddress("https://webservice.test.provider.com/Service.asmx"); soap = (Soap) factory.create(); Map&lt;String,Object&gt; outProps= new HashMap&lt;String,Object&gt;(); outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); outProps.put(WSHandlerConstants.USER, "TESTUSER"); outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new WSAuthHandler("XXXX")); Client cxfClient = ClientProxy.getClient(soap); Endpoint cxfEndpoint = cxfClient.getEndpoint(); cxfEndpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); } </code></pre> <p>When Maven runs the tests the Jersey class is run first; this results in the following error when running the CXF tests:</p> <pre><code>Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153) at org.springframework.context.support.AbstractApplicationContext.containsBean(AbstractApplicationContext.java:892) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:143) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:113) at org.apache.cxf.transport.http.AbstractHTTPTransportFactory.configure(AbstractHTTPTransportFactory.java:228) </code></pre> <p>Unfortunately there doesn't seem to be any way to force the shutdown of the Spring application-context at the end of the Jersey tests and forcing per-test forks hasn't helped. It looks like I need to reset the Spring application-context as part of setting-up the CXF test, but I can't see how I would do this. Any pointers would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload