dev@glassfish.java.net

Re: Payload and PayloadImpl Changes

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Thu, 09 Feb 2012 11:43:59 -0600

Sounds good. Give me some time to digest this and I'll ping you on IM.

On 2/9/12 11:37 AM, Tim Quinn wrote:
> Jason,
>
> Help me understand how the existing API does not let you do what you
> need. I do not think we want to expose methods which force the
> payload implementation to maintain or create a collection of Parts.
>
> The server code that is populating the payload for return to the
> client can already add one or more files (binary or otherwise) to the
> payload using Payload.Outbound.addPart or attachFile.
>
> The client code receiving the returned payload can iterate through all
> the parts of the payload using the existing Payload.Inbound.parts()
> method which returns an Iterator<Part>.
>
> This API is designed to allow the implementation - either inbound or
> outbound - to avoid creating an internal collection of the Parts. The
> transferred data could be very large and we do not want to have to
> hold the contents of all the parts in memory.
>
> I'm not sure what you need to do with the Parts on the receiving end,
> but take a look at PayloadFilesManager. If you want to write each
> incoming Part to a file then this class will save you a lot of work.
>
> Let's take this offline so I can understand more clearly what the REST
> implementation needs to do and if the existing implementations can
> help as-is.
>
> - Tim
>
>
>
> On Feb 9, 2012, at 10:35 AM, Jason Lee wrote:
>
>> Tim, I need to be able to return binary files via REST calls. To do
>> this, given the use of ActionReport, etc., I need to make a small
>> change to the public API of Payload. The diff for the change is
>> below. Do you see any issues with this change?
>>
>> Thanks!
>>
>> Index:
>> nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java
>> ===================================================================
>> ---
>> nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java
>> (revision 52514)
>> +++
>> nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java
>> (working copy)
>> @@ -52,8 +52,10 @@
>> import java.net.URI;
>> import java.net.URLConnection;
>> import java.util.ArrayList;
>> +import java.util.Collection;
>> import java.util.Collections;
>> import java.util.Iterator;
>> +import java.util.List;
>> import java.util.Properties;
>> import java.util.logging.Logger;
>> import org.glassfish.api.admin.Payload;
>> @@ -335,7 +337,8 @@
>> return (isComplex()) ? getComplexContentType() :
>> getSinglePartContentType();
>> }
>>
>> - ArrayList<Payload.Part> getParts() {
>> + @Override
>> + public Collection<Payload.Part> getParts() {
>> return parts;
>> }
>>
>> Index:
>> nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/Payload.java
>> ===================================================================
>> ---
>> nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/Payload.java
>> (revision 52514)
>> +++
>> nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/Payload.java
>> (working copy)
>> @@ -46,6 +46,7 @@
>> import java.io.InputStream;
>> import java.io.OutputStream;
>> import java.net.URI;
>> +import java.util.Collection;
>> import java.util.Iterator;
>> import java.util.Properties;
>>
>> @@ -147,6 +148,8 @@
>> final Properties props,
>> final String content) throws IOException;
>>
>> + public Collection<Payload.Part> getParts();
>> +
>> /**
>> * Adds a part of the specified content type, name, and
>> content to
>> * the payload.
>>
>> --
>> Jason Lee
>> Senior Member of Technical Staff
>> GlassFish Team
>>
>> Oracle Corporation
>> Phone +1 405-216-3193
>> Bloghttp://blogs.steeplesoft.com
>


-- 
Jason Lee
Senior Member of Technical Staff
GlassFish Team
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com