MediaType issue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MediaType issue

JFinanger
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? 

--
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 [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: MediaType issue

Tim Peierls

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


On Thu, Jun 14, 2018 at 10:46 AM jon <[hidden email]> wrote:
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? 

--
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 [hidden email].

--
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 [hidden email].
Reply | Threaded
Open this post in threaded view
|

RE: MediaType issue

Jerome Louvel-4

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 : [hidden email] <[hidden email]> de la part de Tim Peierls <[hidden email]>
Envoyé : jeudi 14 juin 2018 17:40
À : [hidden email]
Cc : Restlet Framework (Discuss)
Objet : Re: MediaType issue
 

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


On Thu, Jun 14, 2018 at 10:46 AM jon <[hidden email]> wrote:
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? 

--
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 [hidden email].

--
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 [hidden email].

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.



--
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 [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: MediaType issue

JFinanger
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


fredag 15. juni 2018 07.35.19 UTC+2 skrev jlouvel følgende:

Hi there,


You should make sure that the <a href="https://restlet.com/open-source/documentation/javadocs/snapshot/jee/api/org/restlet/service/MetadataService.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frestlet.com%2Fopen-source%2Fdocumentation%2Fjavadocs%2Fsnapshot%2Fjee%2Fapi%2Forg%2Frestlet%2Fservice%2FMetadataService.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHQbvU8YDh2AUIb_xweq7gsWWHaYg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frestlet.com%2Fopen-source%2Fdocumentation%2Fjavadocs%2Fsnapshot%2Fjee%2Fapi%2Forg%2Frestlet%2Fservice%2FMetadataService.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHQbvU8YDh2AUIb_xweq7gsWWHaYg&#39;;return true;"> 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 : <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">framewor...@... <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">framewor...@...> de la part de Tim Peierls <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">t...@...>
Envoyé : jeudi 14 juin 2018 17:40
À : <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">j...@...
Cc : Restlet Framework (Discuss)
Objet : Re: MediaType issue
 

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


On Thu, Jun 14, 2018 at 10:46 AM jon <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">j...@...> wrote:
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? 

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;"> framework-disc...@restlet.org.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ey_9DF_mBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;"> framework-disc...@restlet.org.

As a recipient of an email from Talend, your contact personal data will be on our systems. Please see our contacts privacy notice at <a href="https://www.talend.com/contacts-privacy-policy/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.talend.com%2Fcontacts-privacy-policy%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHFXJ25lReHTI2L3MdHIwztEmB7Cg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.talend.com%2Fcontacts-privacy-policy%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHFXJ25lReHTI2L3MdHIwztEmB7Cg&#39;;return true;">Talend, Inc.



--
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 [hidden email].