[ 
https://issues.apache.org/jira/browse/OLINGO-858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15137228#comment-15137228
 ] 

Dirk Mahler commented on OLINGO-858:
------------------------------------

Hi Christian,

there's no chance of handling errors while streaming is in progress as the 
headers are already written to the ServletOutputStream. But I don't know if 
this is really a problem:

{code}
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final 
String contentType) throws ODataException {
  ...
  List<Map<String, Object>> entries = ... // user code for creating entries in 
the feed
  ...
  return EntityProvider.writeFeed(contentType, entitySet, entries, 
EntityProviderWriteProperties.serviceRoot(
                    getContext().getPathInfo().getServiceRoot()).build());
{code}

Entries can be a List which only provides an Iterable/Iterator that is 
transformed into the InputStream which is used to write to the 
ServletOutputStream. So the user code can create a valid ODataResponse object 
if it is sure that the iterator can fetch data (e.g. after successful execution 
of a query and providing the iterator based on the result set) or create an 
error if anything went wrong at this stage. Of course there's still a chance 
that fetching data from the iterator fails for some reason (e.g. connection to 
DB is cut-off) but that's a bit like that the WiFi is turned off on the client 
that receives the data - he gets some non-parseable XML or JSON and needs to 
deal with that properly.

Actually there's another problem: If the iterator like in the given example is 
backed up by a JDBC result set (i.e. a resource) then it must be closed after 
processing it. If everything goes well the iterator implementation may do this 
on it's own if the last row has been reached - but there's currently no chance 
of detecting a broken connection to the HTTP client. In our project I solved it 
by putting the JDBC connection in the request scope of a CDI container - but 
this is very dependent on the technical context.

> org.apache.olingo.odata2.api.processor.ODataResponse enity is not streamed
> --------------------------------------------------------------------------
>
>                 Key: OLINGO-858
>                 URL: https://issues.apache.org/jira/browse/OLINGO-858
>             Project: Olingo
>          Issue Type: Improvement
>          Components: odata2-core
>    Affects Versions: V2 2.0.5
>            Reporter: Mitko Kolev
>            Assignee: Michael Bolz
>
> The entity of the {{org.apache.olingo.odata2.api.processor.ODataResponse}} is 
> not streamed.
> {code}
> ODataResponse.newBuilder().entity(someInputStream).header("Content-Type", 
> "application/octet-stream")
>                 .status(HttpStatusCodes.OK).build()
> {code} 
> It would make sense to stream this directly in the HTTP response.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to