I posted about this last Thursday, but I still need some help with this.

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.  Just so it's clear, the application itself is working fine, 
it's just this integration test that I can't get working.

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 and some 
hopefully irrelevant stuff:
-------------------------------------
[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 [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
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)
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 : */*.
------------------------------------------

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