isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <...@haywood-associates.co.uk>
Subject Re: REST viewer returning a file
Date Wed, 20 Mar 2019 22:57:53 GMT
Hi Brian,

sorry for the late reply on this.

A ContentMappingService isn't going to solve your problem here ... IIRC the
list of content mapping services supported by the Swagger Service is
hardcoded, I think.  It probably ought to be extensible/pluggable, I
suppose.  One for the backlog... <sigh>

However, if I understand your problem, what you want is some sort of hint
as to how to interpret the "result.value" node, ie the format "My file
name:application/pdf:[the binary content base64-encoded]" ?

If so, then I think all the information you need is already in the
representation, in that the
"result.links[rel='urn:org.restfulobjects:rels/return-type'].ref indicates
a domain type of "
http://localhost:8080/project/restful/domain-types/org.apache.isis.applib.value.Blob".
To be truly HATEOAS, your client ought to follow this link and then the
returned representation shows:
{
   ...
   canonicalName: "org.apache.isis.applib.value.Blob",
   ...
}

In other words, the original value has a return type whose canonical name
is "org.apache.isis.applib.value.Blob" .  The RO spec then defines how to
parse the three parts.

In practical terms you might decide there's no need to actually follow the
http://localhost:8080/project/restful/domain-types/org.apache.isis.applib.value.Blob
link; you could check for  the suffix "
domain-types/org.apache.isis.applib.value.Blob
<http://localhost:8080/project/restful/domain-types/org.apache.isis.applib.value.Blob>
 "
and decide that's good enough.

Hope that helps a little...

Dan





On Wed, 6 Mar 2019 at 19:18, Brian K <harvestmoon299@gmail.com> wrote:

> Hi,
>
> I want to return a file from a REST operation.  I have an action that
> returns a pdf as a Blob.  In the wicket viewer that causes the browser to
> download a file.  The REST operation returns an object with content like
> this:
>
> ```
> {
>   "links" : [ ],
>   "resulttype" : "scalarvalue",
>   "result" : {
>     "value" : "My file name:application/pdf:[the binary content
> base64-encoded]",
>     "links" : [ {
>       "rel" : "urn:org.restfulobjects:rels/return-type",
>       "href" : "
>
> http://localhost:8080/project/restful/domain-types/org.apache.isis.applib.value.Blob
> ",
>       "method" : "GET",
>       "type" :
>
> "application/json;profile=\"urn:org.restfulobjects:repr-types/domain-type\""
>     } ],
>     "extensions" : { }
>   }
> }
> ```
>
> The swagger spec that is generated lists this operation as returning a data
> type of "object".  Is there another data type that I can use here that
> would generate something a little more intuitive? Maybe a swagger 2.0
> "file" data type, or a type described with the following yaml:
> ```
> type: object
>             properties:
>               name :
>                  type : string
>               mimeType :
>                  type : string
>               data :
>                  type : string
>                  format : byte
> ```
>
> Would an implementation of a ContentMappingService in my project would
> allow me to dictate how to represent the Blob data type to the REST
> viewer?
>
> Thanks!
> Brian
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message