On 13 May 2014, at 21:13, michaelw_at_articulatedesign.us.com wrote:
> I ran wadl2java 1.1.6 to generate JavaBeans from WADL and used the
> beans in my Jersey 2.7 client. There are no problems unmarshalling an
> XML response using the generated beans. However, if a request body
> content is XML, marshalling fails with an exception:
>
> org.glassfish.jersey.message.internal.WriterInterceptorExecutor$Termina
> lWriterInterceptor aroundWriteTo
> SEVERE: MessageBodyWriter not found for media type=application/xml,
> type=class com.ltree.airportweather.AirportInfo,
> genericType=class com.ltree.airportweather.AirportInfo.
>
> If I manually add @XmlRootElement to the generated bean, the request
> succeeds.
Can you show me the code snippet you use to invoke the service using the client
as you did below? And also the body of the client method it is calling.
>
> I get the same result when sending requests from the generated custom
> class (i.e., the generated JAX-RS client with methods for all the
> requests in the WADL).
>
> Here's my code:
>
> AirportInfo airportInfoBean = new AirportInfo(); // generated by
> wadl2java
> ...
> Client client = ClientBuilder.newClient();
> String responseFromPost =
> client.target(BASE_URL)
> .request(MediaType.TEXT_PLAIN)
> .post(Entity.xml(airportInfoBean), String.class);
This is an odd formulation, why are you using Entity.xml, I suspect that give your model you will need to use:
.post(new JAXBElment(new QName(….), AirportInfoBean.class, airportInfoBean),String.class);
The problem here is that the AirportInfo object in a @XmlType and you need to provide the specific name in order to map this to a xml element / or just just the XmlRootElement annotation on it as you did above if the names match.
Gerard
>
> Any idea what I'm doing wrong? Should I be using the generated
> ObjectFactory somewhere in my client code?
>
> Thanks,
> Mike