[
https://issues.apache.org/jira/browse/OLINGO-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14556232#comment-14556232
]
Christian Amend commented on OLINGO-662:
----------------------------------------
Hi,
1.) for media entities it should not be necessary to override the
getCustomContentTypes() method since the media value can have any content type
we do not validate this as long as the entity type is marked with
hasStream()=true.
2.) The OData protocol is somewhat special here. When you create a new Media
Entity you first send the data for the media value in one request by using the
HTTP Post method on the entity set. Then your service should persist the media
value and generate an empty entity object will be given back to the client. The
client can now use the entity he receives to make an update on the entity where
it is sending the payload based on the xml or json format with all its
properties. So in order to persist media entities you have those two steps with
different requests.
We tried to map this bahviour to the V2 Odata lib by dispatching the create
request to the createEntity(...) method as you found out correctly. There you
have to check if the entity you received is a media entity. To parse the
payload the Olingo library does not offer a special deserializer. You can use
the readBinary() method from our EntityProvider if this is enough for you use
case.
You could have a look at our generic lists processor:
https://git-wip-us.apache.org/repos/asf?p=olingo-odata2.git;a=blob;f=odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java;h=86ae0cb8480a43a29fe7809ed01bf42a95144bfd;hb=HEAD
Look at the createEntity method there to see how we handle media entities.
In V4 we tried to make this design better by offering a createMediaEntity()
method but I don`t think we can change the V2 API this much for the next micro
version update.
So you approach is definitely valid.
Best Regards,
Christian
> Attachments support in olingo
> -----------------------------
>
> Key: OLINGO-662
> URL: https://issues.apache.org/jira/browse/OLINGO-662
> Project: Olingo
> Issue Type: Bug
> Components: MISC, odata2-annotation, odata2-core, odata4-server
> Affects Versions: V2 2.0.3
> Reporter: Prashanth
> Assignee: Christian Amend
> Priority: Blocker
> Labels: attachments
>
> This question is about the support for attachments uploading and downloading
> via Olingo Service ( Olingo V2 2.0.3 ). I have gone the olingo docs but
> didn't find any clue on how to provide support for uploading and downloading
> of attachments using olingo .
> Does olingo supports this functionality ? If olingo supports , how to
> implements this ?
> Following are some basics which i came to know by debugging the core library :
> -> Media type support : We can provide support for custom content types by
> overriding the method getCustomContentTypes() in processor class.
> -> Implementation : we can implement createEntity as following in processor
> class :
> @Override
> public ODataResponse createEntity(PostUriInfo uriInfo, InputStream
> content,
> String requestContentType, String contentType) throws ODataException {
> ... }
>
> But here content is giving the requestBody , not actual file/attachment.
> Note : Here the support for attachments means - ex : in case of Rest , CXF
> provides some api which can be seen in following snippet :
> @POST
> @Consumes( {MediaType.MULTIPART_FORM_DATA })
> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> public Response create(@Context HttpHeaders httpHeaders, @Context
> UriInfo uriInfo,
> MultipartBody multipartBody)
> Here @Consumes media type provides consumption of multipart formdata and
> MultipartBody parameter can give us the attachments.
> Similar to above , Does Olingo V2 2.0.3 provides any API ?How can we
> implement the support for attachments in Olingo V2 2.0.3 ? Please share us an
> example !
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)