users@jersey.java.net

Re: [Jersey] A message body writer for Java type [...] and MIME media type [...] was not found

From: Javier Alvarez <javier.alvarez_at_bsc.es>
Date: Thu, 13 May 2010 12:57:16 +0200

Hello Pavel,

Thank you very much, that solved the problem.

Best regards,

-- 
Javi
On 13/05/10 12:41, Pavel Bucek wrote:
>
> Hello again,
>
> I found two problems in your code:
>
> 1) you didn't declare xml namespace in xml used for request (I fixed 
> that by modifying xml input to:
>
> <VDC name="prod"
>       href="http://nuba.morfeo-project.org/tcloud/cesga/vdc/prod"  
> xmlns="http://schemas.tcloud.telefonica.com/tcloud/0.1">
> <Description>Business Support Systems</Description>
> <Link rel="up" href="http://nuba.morfeo-project.org/tcloud/cesga" />
> <Link rel="add"
>              
> type="application/vnd.telefonica.tcloud.instantiateOvfParams+xml"
>              
> href="http://nuba.morfeo-project.org/tcloud/cesga/vdc/prod/action/instantiateOvf" 
> />
>
> <AvailableNetworks>
> <Network 
> href="http://nuba.morfeo-project.org/tcloud/cesga/vdc/prod/net/public" 
> name="public" />
> </AvailableNetworks>
> </VDC>
>
> )
>
>
> 2) you need to wrap object you are returning with JAXBElement class 
> (because your class doesn't have @XmlRootElement annotation); so your 
> resource method can look like:
>
>     @POST
>     @Consumes ("application/vnd.telefonica.tcloud.vdc+xml")
>     @Path ("/vdc/action/add")
>     public Response addVDC (VDCType vdc)
>     {
>         System.out.println(vdc.getDescription());
>         System.out.println(vdc.getLink());
>         System.out.println(vdc.getStorageCapacity());
>         System.out.println(vdc.getComputeCapacity());
>
>         return Response.ok(new JAXBElement<VDCType>(new QName("VDC"), 
> VDCType.class, vdc), "application/vnd.telefonica.tcloud.vdc+xml").build();
>     }
>
>
> Feel free to ask if you have additional questions/problems.
>
> Regards,
> Pavel
>
>
>
> On 5/12/10 5:08 PM, Javier Alvarez wrote:
>> Hello Pavel,
>>
>> Find a little eclipse project attached. You can deploy the generated 
>> war on tomcat and then run the src/test/java/ServiceTester class (it 
>> will asume http://localhost:8080 as tomcat's URL).
>>
>> Thank you.
>>
>> On 12/05/10 16:03, Pavel Bucek wrote:
>>> Hello Javier,
>>>
>>> can you provide minimal failing test-case (preferably maven 
>>> project)? I will look into it, but this would save my time..
>>>
>>> thanks,
>>> Pavel
>>>
>>> On 5/12/10 9:07 AM, Javier Alvarez wrote:
>>>> Hi Moises,
>>>>
>>>> I forgot to say that I get the error when invoking the following 
>>>> POST method:
>>>>
>>>> @POST
>>>> @Consumes ("application/vdc+xml")
>>>> @Path ("/vdc/action/add")
>>>> public Response addVDC (VDCType vdc)
>>>> {
>>>>     System.out.println(vdc.getName());
>>>>
>>>>     return Response.ok(vdc, "application/vdc+xml").build();
>>>> }
>>>>
>>>> And then:
>>>>
>>>> - If I add @XmlRootElement to the VDCType class I get an HTTP 400 
>>>> Response saying that the sent resource is sintactically incorrect 
>>>> and the method above prints nothing.
>>>>
>>>> - Without the @XmlRootElement I can invoke the method and it prints 
>>>> the correct name, but it crashes when returning.
>>>>
>>>> By the way, if I change the type to "application/xml" I have the 
>>>> same problem.
>>>>
>>>> Thank you.
>>>>
>>>> On 12/05/10 08:34, Moises Lejter wrote:
>>>>> Maybe you should designate your class as @XmlRootElement, too ?
>>>>> I would have expected that the default XML encoding would be 
>>>>> acceptable, even though you say "application/cvd+xml", and not 
>>>>> just "application/xml" ...
>>>>>
>>>>> Moises
>>>>>
>>>>> On May 12, 2010, at 1:27 AM, Javier Alvarez wrote:
>>>>>
>>>>>> I am developing a RESTful Web Service using Jersey and I 
>>>>>> encountered a problem. The error is the following:
>>>>>>
>>>>>> /A message body writer for Java type, class VDCType, and MIME 
>>>>>> media type, application/vdc+xml, was not found./
>>>>>
>>>> -- 
>>>> Javi
>>>
>>
>>
>> -- 
>> Javi
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail:users-help_at_jersey.dev.java.net
>>    
>