Hi David
On Tue, Jul 12, 2011 at 4:28 PM, KARR, DAVID (ATTSI) <[email protected]> wrote:
> I'm building a service using CXF 2.4.1 by reusing most of the setup of a
> project that was using CXF 2.3.2. The first project was using Jackson, but
> I'm going to try using Jettison for this.
>
> My first unit test method uses the default of xml, and that parses the
> response just fine. The second method uses the ".json" extension, and I see
> in the console output that it returned a Jettison-formatted JSON response (it
> had the namespace prefix on the element name), but it just said this (class
> name changed):
>
> Jul 12, 2011 8:12:15 AM org.apache.cxf.jaxrs.client.AbstractClient
> reportMessageHandlerProblem
> SEVERE: .Problem with reading the response message, class : class
> mypackage.Myclass, ContentType : application/json.
>
In this case you should get ClientWebApplicationException thrown
containing the cause, can you update the code and catch it ? The
exception is coming from the reader, I'm wondering if it's default
JSON provider or not. JAXB provider is ordered first in 2.4.1, so
without WebClient explicitly specifying accept type, it may be
interfering given that MyClass is presumably a JAXB bean
Cheers, Sergey
> I'm referencing "cxf-rt-transports-http" and "cxf-rt-frontend-jaxrs" in my
> POM.
>
> The following is in my unit test class (with some class names and paths
> changed):
> ------------------------
> @BeforeClass
> public static void startServer() {
> setController(new StuffController());
> getController().init();
>
> ServerFactory.create(getController(), TestHelper.BASE_SERVICE_URI);
> }
>
> @Test
> public void testBasic() throws Exception {
> getController().setService(service);
>
> WebClient client =
> WebClient.create(TestHelper.BASE_SERVICE_URI).path("/stuff");
>
> Stuffs mockStuffs = new Stuffs();
> when(service.getStuff()).thenReturn(mockStuffs);
>
> Stuffs stuffs = client.get(Stuffs.class);
> assertThat(stuffs).isNotNull();
> }
>
> @Test
> public void testBasicJson() throws Exception {
> getController().setService(service);
>
> WebClient client =
> WebClient.create(TestHelper.BASE_SERVICE_URI).path("/stuff.json");
>
> Stuffs mockStuffs = new Stuffs();
> when(service.getStuff()).thenReturn(mockStuffs);
>
> Stuffs stuffs = client.get(Stuffs.class);
> assertThat(stuffs).isNotNull();
> }
> ---------------
>
> This is my ServerFactory class:
> ----------------------
> public class ServerFactory {
> 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<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