[Registry-dev] Improving the resource handling

Chathura C. Ekanayake chathura at wso2.com
Sun Jul 20 22:37:51 PDT 2008


There can be some issues with handling content in the current resource 
implementation. Contents of resources can be set or retrieved as an 
input stream. But this could cause problems as input streams can be read 
only once. For example, if a handler reads the content as a stream, 
before putting the resource, the database layer won't be able to read 
the content again.

We have another problem. If a handler engaged for the GET request wants 
to replace the content with a new input stream, there is no guarantee 
that the new input stream will be closed. This is because that the user 
may not want to access the content at all (non of above problems arise, 
if we deal with contents as byte[]. But it limits the size of the 
content that we can handle).

We can handle both above scenarios and many other content related 
issues, if we introduce a  resource.discard() method. All the cleaning 
up related to the resource instances are done in this method and the 
users are required to call it when they have finished using the 
resource. Then, whenever the resource.setContentStream(...) is called, a 
temporary file is created and resource.getContentStream() is served by 
creating an input stream from the temporary file. So it is possible to 
call resource.getContentStream() multiple times. And the temporary file 
is deleted when the resource.discard() method is called.

Thoughts...

Thanks,
Chathura





More information about the Registry-dev mailing list