>>
>> I don't recall seeing such NPEs in Jettison - I'll save this stack
>> trace till I get a chance to fix that at jettison level.
>> If you get JSON content with prefixes coming in then you need to
>> explicitly register JSONProvider during WebClient.create(...), and set
>> a namespaceMap property on it (key - prefix, value - namespace).
>> Other approach in 2.4.1 is to configure the *server* provider to drop
>> namespaces completely (ignoreNamespaces property) and use
>> StaxTransformFeature wildcards on the client side to add expected
>> namespaces
>
> I managed to figure this out before I saw this response. :)
>
> I created the JSONProvider in the server factory and added it to both the
> server and the client, and it now works.
Great...
>
> Actually, Sergey, the namespaceMap is defined in the non-obvious way, with
> the namespace as the key, and the prefix as the value.
>
Jettison expects it, I guess it's easier this way for Jettison to
react to JAXB reporting writeElement with non-empty namespace...I
guess it could've allocated prefixes dynamically, which I believe
JSONProvider itself can do (Benson did the work)
Cheers, Sergey
>> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStar
>> tElement(StAXStreamConnector.java:232)
>> > 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)
>> > at
>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unm
>> arshallerImpl.java:332)
>> > at
>> org.apache.cxf.jaxrs.provider.JSONProvider.readFrom(JSONProvider.java:1
>> 97)
>> > ... 33 more
>> >
>> >>
>> >> 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
>> >
>