I've built unit tests with JAXRSServerFactoryBean, but I've typically used the 
VerboseMockitoJUnitRunner.  I'm now trying to build an integration test using 
SpringJUnit4ClassRunner, where the service I want to test is injected from the 
Spring context.

In the past, I would have a static "init()" method to initialize the server.  
In this case, I discovered that I can't do that in a static method, as I can't 
autowire static fields.  So, I'm currently working with an instance method to 
initialize the server.

When the WebClient attempts to connect, it doesn't appear as if it gets to my 
Jetty server, and it immediately fails with an xml parsing exception.  I don't 
see how I can diagnose what's going on here.  I'd appreciate any hints you have.

To start, here's my console log.  I've elided package and class names:
-------------------------------------
[main] INFO org.springframework.test.context.TestContextManager - 
@TestExecutionListeners is not present for class [class 
mypackage.content.StuffResultsControllerIntTest]: using defaults.
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - 
Loading XML bean definitions from class path resource [applicationContext.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - 
Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
[main] INFO 
org.springframework.beans.factory.support.DefaultListableBeanFactory - 
Overriding bean definition for bean 'stuffResultsService': replacing [Generic 
bean: class [mypackage.service.StuffResultsService]; scope=singleton; 
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; 
autowireCandidate=true; primary=false; factoryBeanName=null; 
factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in 
file [C:\Documents and 
Settings\dk068x\workspace4\StuffDataService\target\classes\mypackage.service\StuffResultsService.class]]
 with [Generic bean: class [mypackage.service.StuffResultsService]; scope=; 
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; 
autowireCandidate=true; primary=false; factoryBeanName=null; 
factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in 
class path resource [applicationContext.xml]]
[main] INFO org.springframework.context.support.GenericApplicationContext - 
Refreshing 
org.springframework.context.support.GenericApplicationContext@116ab4e: startup 
date [Thu Sep 08 15:32:58 PDT 2011]; root of context hierarchy
[main] INFO 
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - 
Loading properties file from class path resource 
[stuffDataService-test.properties]
[main] INFO 
org.springframework.beans.factory.support.DefaultListableBeanFactory - 
Pre-instantiating singletons in 
org.springframework.beans.factory.support.DefaultListableBeanFactory@19da4fc: 
defining beans 
[cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,stuffResultsService,StuffDataServer,messageLoggingInInterceptor,messageLoggingOutInterceptor,mobilityBuyFlowResultsController,stuffResultsController,logManager,exporter,attributeSource,assembler,onlineServiceNameList,onlineFailureExpressions,bosFailureExpressions,onlineBothellDAO,onlineAllenDAO,mypackage.dao.impl.BOSDAO#0,mobilityBuyFlowResultsService,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,onlineBothellDataSource,onlineAllenDataSource,bosDataSource,post15MinuteQueryProcessor,post15MinuteQueryTimerTask,timerFactory,mypackage.service.WorkflowIdentifier#0,mypackage.service.WorkflowIdentifier#1,mypackage.service.WorkflowIdentifier#2,mypackage.service.WorkflowIdentifier#3,mypackage.service.WorkflowIdentifier#4,mypackage.service.WorkflowIdentifier#5,mypackage.service.WorkflowIdentifier#6,mypackage.service.WorkflowIdentifier#7,mypackage.service.WorkflowIdentifier#8,mypackage.service.WorkflowIdentifier#9,mypackage.service.WorkflowIdentifier#10,mypackage.service.WorkflowIdentifier#11,mypackage.service.WorkflowIdentifier#12,mypackage.service.WorkflowIdentifier#13,mypackage.service.WorkflowIdentifier#14,mypackage.service.ServiceIdentifier#0,mypackage.service.ServiceIdentifier#1,mypackage.service.ServiceIdentifier#2,mypackage.service.ServiceIdentifier#3,mypackage.service.ServiceIdentifier#4,mypackage.service.ServiceIdentifier#5,mypackage.service.ServiceIdentifier#6,mypackage.service.ServiceIdentifier#7,mypackage.service.ServiceIdentifier#8,mypackage.service.ServiceIdentifier#9,mypackage.service.ServiceIdentifier#10,mypackage.service.ServiceIdentifier#11,mypackage.service.ServiceIdentifier#12,mypackage.service.ServiceIdentifier#13,mypackage.service.ServiceIdentifier#14,mypackage.service.ServiceIdentifier#15,mypackage.service.ServiceIdentifier#16,mypackage.service.ServiceIdentifier#17,mypackage.service.ServiceIdentifier#18,mypackage.service.ServiceIdentifier#19];
 root of factory hierarchy
[main] INFO org.springframework.scheduling.timer.TimerFactoryBean - 
Initializing Timer
Sep 8, 2011 3:32:58 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be /rest
[main] INFO org.springframework.jmx.export.MBeanExporter - Registering beans 
for JMX exposure on startup
[main] INFO org.springframework.jmx.export.MBeanExporter - Located managed bean 
'StuffDataServer:name=logBean': registering with JMX server as MBean 
[StuffDataServer:name=logBean]
Sep 8, 2011 3:32:59 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be 
http://localhost:9000/StuffDataService/rest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
Sep 8, 2011 3:33:01 PM org.apache.cxf.jaxrs.provider.AbstractJAXBProvider 
handleJAXBException
WARNING: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"HTML"). 
Expected elements are 
<{http://www.stuff.com/automation/schema/serviceCallResults/v1.0}serviceCallResults>]
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:332)
        at 
org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputStream(JAXBElementProvider.java:214)
        at 
org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBElementProvider.java:180)
        at 
org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElementProvider.java:149)
        at 
org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:435)
        at 
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:747)
        at 
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:731)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:662)
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:324)
        at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:421)
        at 
mypackage.content.StuffResultsControllerIntTest.test(StuffResultsControllerIntTest.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at 
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        at 
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
        at 
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        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:236)
        at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", 
local:"HTML"). Expected elements are 
<{http://www.stuff.com/automation/schema/serviceCallResults/v1.0}serviceCallResults>
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1049)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
        ... 40 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", 
local:"HTML"). Expected elements are 
<{http://www.stuff.com/automation/schema/serviceCallResults/v1.0}serviceCallResults>
        ... 50 more

Sep 8, 2011 3:33:01 PM org.apache.cxf.jaxrs.client.AbstractClient 
reportMessageHandlerProblem
SEVERE: .Problem with reading the response message, class : class 
mypackage.domain.ServiceCallResults, ContentType : */*.
[Thread-2] INFO org.springframework.context.support.GenericApplicationContext - 
Closing org.springframework.context.support.GenericApplicationContext@116ab4e: 
startup date [Thu Sep 08 15:32:58 PDT 2011]; root of context hierarchy
[Thread-2] INFO 
org.springframework.beans.factory.support.DefaultListableBeanFactory - 
Destroying singletons in 
org.springframework.beans.factory.support.DefaultListableBeanFactory@19da4fc: 
defining beans 
[cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,stuffResultsService,StuffDataServer,messageLoggingInInterceptor,messageLoggingOutInterceptor,mobilityBuyFlowResultsController,stuffResultsController,logManager,exporter,attributeSource,assembler,onlineServiceNameList,onlineFailureExpressions,bosFailureExpressions,onlineBothellDAO,onlineAllenDAO,mypackage.dao.impl.BOSDAO#0,mobilityBuyFlowResultsService,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,onlineBothellDataSource,onlineAllenDataSource,bosDataSource,post15MinuteQueryProcessor,post15MinuteQueryTimerTask,timerFactory,mypackage.service.WorkflowIdentifier#0,mypackage.service.WorkflowIdentifier#1,mypackage.service.WorkflowIdentifier#2,mypackage.service.WorkflowIdentifier#3,mypackage.service.WorkflowIdentifier#4,mypackage.service.WorkflowIdentifier#5,mypackage.service.WorkflowIdentifier#6,mypackage.service.WorkflowIdentifier#7,mypackage.service.WorkflowIdentifier#8,mypackage.service.WorkflowIdentifier#9,mypackage.service.WorkflowIdentifier#10,mypackage.service.WorkflowIdentifier#11,mypackage.service.WorkflowIdentifier#12,mypackage.service.WorkflowIdentifier#13,mypackage.service.WorkflowIdentifier#14,mypackage.service.ServiceIdentifier#0,mypackage.service.ServiceIdentifier#1,mypackage.service.ServiceIdentifier#2,mypackage.service.ServiceIdentifier#3,mypackage.service.ServiceIdentifier#4,mypackage.service.ServiceIdentifier#5,mypackage.service.ServiceIdentifier#6,mypackage.service.ServiceIdentifier#7,mypackage.service.ServiceIdentifier#8,mypackage.service.ServiceIdentifier#9,mypackage.service.ServiceIdentifier#10,mypackage.service.ServiceIdentifier#11,mypackage.service.ServiceIdentifier#12,mypackage.service.ServiceIdentifier#13,mypackage.service.ServiceIdentifier#14,mypackage.service.ServiceIdentifier#15,mypackage.service.ServiceIdentifier#16,mypackage.service.ServiceIdentifier#17,mypackage.service.ServiceIdentifier#18,mypackage.service.ServiceIdentifier#19];
 root of factory hierarchy
[Thread-2] INFO org.springframework.jmx.export.MBeanExporter - Unregistering 
JMX-exposed beans on shutdown
[Thread-2] INFO org.springframework.scheduling.timer.TimerFactoryBean - 
Cancelling Timer
------------------------------------------

I have the following relevant maven artifacts:
* cxf-rt-transports-http
* cxf-rt-frontend-jaxrs
* cxf-rt-transports-http-jetty

The following is the method I use to create the server, given my injected 
service bean and the service URI:
-----------------------------
    public static void create(Object serviceBean, String uri) {
        JAXRSServerFactoryBean  sf  = new JAXRSServerFactoryBean();
        
        BindingFactoryManager   manager = 
sf.getBus().getExtension(BindingFactoryManager.class);
        JAXRSBindingFactory     factory = new JAXRSBindingFactory();
        factory.setBus(sf.getBus());
        manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, 
factory);

        Map<String, String> namespaceMap    = new HashMap<String, String>();
        XmlSchema   xmlSchemaAnnotation     = 
ServiceCallResults.class.getPackage().getAnnotation(XmlSchema.class);
        namespaceMap.put(xmlSchemaAnnotation.namespace(), "cns");
        JSONProvider    jsonProvider    = new JSONProvider();
        jsonProvider.setNamespaceMap(namespaceMap);
        jsonProvider.setIgnoreNamespaces(false);
        sf.setProvider(jsonProvider);
        
        setJSONProvider(jsonProvider);

        Map<Object, Object> extensionsMap   = new HashMap<Object, Object>();
        extensionsMap.put("json", "application/json");
        extensionsMap.put("xml", "application/xml");

        sf.setExtensionMappings(extensionsMap);

        sf.setServiceBean(serviceBean);
        sf.getInInterceptors().add(new LoggingInInterceptor());
        sf.getOutInterceptors().add(new LoggingOutInterceptor());
        
        sf.setAddress(uri);
        
        sf.create();
    }
-----------------

Reply via email to