Attached is a working version (as a NB project).
The problem is your message body writer was registered for the incorrect
type, it should be Rows type rather than the CellType.
Your @GET method of the resource returns a Response instance that
contains an instance of Rows.
Paul.
Arul Dhesiaseelan wrote:
> Hi Paul,
>
> Attaching the sources for your reference. It also includes a client
> which sets the header to "application/xml". But, it does not fix it either.
> The resource method is getting invoked. But, I always get the same
> response as XML.
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <rows>
> <row>
> <cell><div class="progressOuterRow"><div
> class="progressInnerRow" style="width:
> 25.0px;"></div><div
> class="progressText">25/100 MB</div></div></cell>
> </row>
> </rows>
>
> Thanks!
> Arul
>
> Paul Sandoz wrote:
>> Arul Dhesiaseelan wrote:
>>> I am using 0.7.
>>>
>>> Does this version have include this behavior?
>>>
>>
>> It does.
>>
>> Is the client sending a an Accept header with "application/xml" included?
>>
>> Does the resource method (@GET annotated method) have a
>> @ProduceMime("application/xml")? Is that method getting invoked?
>>
>> I think it would help me a lot if you could attach a zip file of your
>> complete application then i can debug it.
>>
>> Paul.
>>
>>> Thanks!
>>> Arul
>>>
>>> Paul Sandoz wrote:
>>>> Arul Dhesiaseelan wrote:
>>>>> No. writeTo() is not even not even invoked.
>>>>>
>>>>
>>>> Hmmm... what version of Jersey are you using?
>>>>
>>>> I cannot recall when i changed it but application-declared
>>>> readers/writers take precedence over Jersey defined ones.
>>>>
>>>> I just added some unit tests that test overriding using String and
>>>> JAXB beans and they pass with no errors.
>>>>
>>>> Paul.
>>>>
>>>>> Thanks!
>>>>> Arul
>>>>>
>>>>> Paul Sandoz wrote:
>>>>>> Is the CDATAProvider.writeTo getting invoked?
>>>>>>
>>>>>> Paul.
>>>>>>
>>>>>> Arul Dhesiaseelan wrote:
>>>>>>> Paul,
>>>>>>>
>>>>>>> Thanks for your help.
>>>>>>>
>>>>>>> I tried this approach, but I am not seeing the SOP made it to my
>>>>>>> console. I suspect whether my custom stream writer is used at the
>>>>>>> first place. Is there a way to tell Jersey/Java to use my custom
>>>>>>> writer instead of the default writer?
>>>>>>>
>>>>>>> I see this in the console, which tells that at least my message
>>>>>>> body writer was loaded properly.
>>>>>>>
>>>>>>> INFO: Provider classes found:
>>>>>>> class impl.rest.jaxb.CDATAProvider
>>>>>>>
>>>>>>> Here is my MBW writer which uses the custom stream writer.
>>>>>>>
>>>>>>> @ProduceMime("application/xml")
>>>>>>> @Provider
>>>>>>> public class CDATAProvider implements MessageBodyWriter<CellType> {
>>>>>>>
>>>>>>> public void writeTo(CellType cellType,
>>>>>>> Class<?> type, Type genericType, Annotation
>>>>>>> annotations[],
>>>>>>> MediaType mediaType, MultivaluedMap<String, Object>
>>>>>>> headers,
>>>>>>> OutputStream out) throws IOException {
>>>>>>> try {
>>>>>>> JAXBContext jc = JAXBContext.newInstance(CellType.class);
>>>>>>> Marshaller marshaller =
>>>>>>> jc.createMarshaller(); XMLStreamWriter swImpl =
>>>>>>> XMLOutputFactory.newInstance().createXMLStreamWriter(out);
>>>>>>> XMLStreamWriter sw = new MyStreamWriter(swImpl);
>>>>>>> marshaller.marshal(cellType, sw);
>>>>>>> } catch (XMLStreamException xse) {
>>>>>>> System.out.println(xse.getMessage());
>>>>>>> } catch (JAXBException je) {
>>>>>>> System.out.println(je.getMessage());
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> public boolean isWriteable(Class<?> type, Type genericType,
>>>>>>> Annotation annotations[]) {
>>>>>>> return CellType.class.isAssignableFrom(type);
>>>>>>> }
>>>>>>>
>>>>>>> public long getSize(CellType cellType) {
>>>>>>> return -1;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Arul
>>>>>>>
>>>>>>> Paul Sandoz wrote:
>>>>>>>> As i understand it your use-case is you want to embed some
>>>>>>>> generic HTML content in some XML.
>>>>>>>>
>>>>>>>> Can you try the following code instead:
>>>>>>>>
>>>>>>>> private Rows processRowsResponse() {
>>>>>>>> List<RowType> rows = new ArrayList<RowType>();
>>>>>>>> RowType row = new RowType();
>>>>>>>> CellType cell = new CellType();
>>>>>>>> final String cdata = new StringBuilder().append("<div
>>>>>>>> class=\"progressOuterRow\"><div class=\"progressInnerRow\"
>>>>>>>> style=\"width:
>>>>>>>> ").append(result.toString()).append("px;\"></div><div
>>>>>>>> class=\"progressText\">").append(used).append("/").append(total).append("
>>>>>>>> MB</div></div>").toString();
>>>>>>>> cell.setValue(cdata);
>>>>>>>> row.getCell().add(cell);
>>>>>>>> rows.add(row);
>>>>>>>> return rows;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public class MyStreamWriter implements XMLStreamWriter {
>>>>>>>> private XMLStreamWriter mImpl;
>>>>>>>>
>>>>>>>> public MyStreamWriter(XMLStreamWriter xmlStreamWriter) throws
>>>>>>>> XMLStreamException {
>>>>>>>> this.mImpl = xmlStreamWriter;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void writeCharacters(String s) throws XMLStreamException {
>>>>>>>> System.out.println("writeCharacters: " + s);
>>>>>>>> mImpl.writeCData(s);
>>>>>>>> }
>>>>>>>>
>>>>>>>> //removed other methods
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> and check the output to see if the "writeCharacters: " string is
>>>>>>>> being printed and check if the content is escaped or not before
>>>>>>>> the delegated call.
>>>>>>>>
>>>>>>>> Paul.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109