开发者

Testing CXF and Jersey together causes Spring conflicts?

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.

The test initialisation for Jersey looks like:

public MailProviderTest()
    throws Exception
{
    super(new WebAppDescriptor.Builder("net.haltcondition.service.rest")
            .contextPath("")
            .contextParam("contextConfigLocation", "classpath:applicationContext.xml")
            .servletClass(SpringServlet.class)
            .conte开发者_开发问答xtListenerClass(ContextLoaderListener.class)
            .build());
}

The CXF tests (which talk to our upstream provider's test servers) looks like:

@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<String,Object> outProps= new HashMap<String,Object>();
    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));
}

When Maven runs the tests the Jersey class is run first; this results in the following error when running the CXF tests:

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)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜