> -----Original Message----- > From: Sergey Beryozkin [mailto:[email protected]] > Sent: Monday, September 12, 2011 1:36 PM > To: [email protected] > Subject: Re: Still having trouble with integration test using > JAXRSServerFactoryBean and SpringJUnit4ClassRunner > > Hi > > It's very difficult to figure out what is going on without seeing a > Maven project. > Would it be possible for you to create a simple project which can be > used to reproduce the issue ?
Ok. I've constructed it. I had to send it from a different address. > Cheers, Sergey > > On Mon, Sep 12, 2011 at 8:09 PM, KARR, DAVID <[email protected]> wrote: > > 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.se > rvice\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}servic > eCallResults>] > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamE > xception(UnmarshallerImpl.java:425) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Un > marshallerImpl.java:362) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unm > arshallerImpl.java:332) > > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputStr > eam(JAXBElementProvider.java:214) > > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBEleme > ntProvider.java:180) > > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElementP > rovider.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.jav > a: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(StuffResultsContro > llerIntTest.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}servic > eCallResults> > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEve > nt(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.reportUnexpectedChildEl > ement(Loader.java:116) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRo > otLoader.childElement(UnmarshallingContext.java:1049) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startEle > ment(UnmarshallingContext.java:478) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElem > ent(UnmarshallingContext.java:459) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStar > tElement(StAXStreamConnector.java:242) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StA > XStreamConnector.java:176) > > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Un > marshallerImpl.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}servic > eCallResults> > > ... 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(); > > } > > ----------------- > > > > > > -- > Sergey Beryozkin > > http://sberyozkin.blogspot.com > Talend - http://www.talend.com
