MediaType issue

9 views
Skip to first unread message

jon

unread,
Jun 14, 2018, 10:46:45 AM6/14/18
to Restlet Framework (Discuss)
I have some hard time supporting more than one variant in my resource (pdf and excel)

 @Get("pdf|excel")
 
public Representation getReport(Variant variant) {
   if(MediaType.APPLICATION_EXCEL.isCompatible(variant.getMediaType()) {
     
...
   
}
...}

I guess the point is that restlet sends the correct variant as a parameter (above) based on what the accept header defines in the request. But when testing in the restlet client, setting Accept:application/excel (or json) the variant is always application/pdf. 

If i clear the variants like this, and add them manually: 
 getVariants().clear();
 getVariants
().add(new Variant(MediaType.APPLICATION_PDF));
 getVariants
().add(new Variant(MediaType.APPLICATION_EXCEL));

I get: The method specified in the request is not allowed for the resource identified by the request URI

Using ?media=excel i the URI does not work either.

Any ideas? 

Tim Peierls

unread,
Jun 14, 2018, 11:40:48 AM6/14/18
to j...@finanger.no, Restlet Framework (Discuss)

I wasn’t aware of the Variant argument behavior in ServerResource. Where is that documented?

Does it work if you factor into two methods?

@Get("pdf")
public PdfRepresentation getReportPdf() {
  ...
}

@Get("excel")
public ExcelRepresentation getReportExcel() {
  ...
}

—tim


--
You received this message because you are subscribed to the Google Groups "Restlet Framework (Discuss)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-disc...@restlet.org.

Jerome Louvel

unread,
Jun 15, 2018, 1:35:19 AM6/15/18
to Tim Peierls, j...@finanger.no, Restlet Framework (Discuss)

Hi there,


You should make sure that the metadata service of your parent application has the "pdf" and "excel" extensions properly registered.


By default, I think you should use "xls" instead of "excel".


Best regards,

Jerome



De : framewor...@restlet.org <framewor...@restlet.org> de la part de Tim Peierls <t...@peierls.net>
Envoyé : jeudi 14 juin 2018 17:40
À : j...@finanger.no
Cc : Restlet Framework (Discuss)
Objet : Re: MediaType issue
 

As a recipient of an email from Talend, your contact personal data will be on our systems. Please see our contacts privacy notice at Talend, Inc.



jon

unread,
Jun 15, 2018, 4:27:18 AM6/15/18
to Restlet Framework (Discuss), t...@peierls.net, j...@finanger.no
Thanks, 
it helped a lot using the correct extention name :-) I checked the metadata, and all extentionnames are registered by default as far as i can see.
For some reason i had to remove the:
 getVariants().add(new Variant(MediaType.APPLICATION_PDF));
 getVariants
().add(new Variant(MediaType.APPLICATION_EXCEL));

in doInit(..) to make it work (was just test code anyhow).

The request media type is application/vnd.ms-excel using uri: ......?media=xls, but will be identified by the system using .isCompatible(...)


-Jon
Reply all
Reply to author
Forward
0 new messages