Hi Sergey,


One thing I have found is this:

    public Response build() {
        ResponseImpl r = new ResponseImpl(status, entity);
        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.putAll(metadata);
        r.addMetadata(m);
        reset();
        return r;
    }

How would you feel about removing that call to reset()? At the moment
I set all my response fields and then that overwrites them. Would it
break anything if I changed it?

Cheers,
Brad.

On Fri, Jun 13, 2008 at 1:42 PM, Sergey Beryozkin
<[EMAIL PROTECTED]> wrote:
> Hi Brad
>
>> Hi Sergey,
>>
>> I'm trying the Response approach you suggested. Its for a file
>> download service so I need to be able to set the Content-Type and
>> Content-Length headers and also provide the file contents as the HTTP
>> response body.
>>
>> Code snippet:
>>
>>   @ProduceMime({"application/xml", "application/json"})
>>   class MailService
>>
>>           @ProduceMime("*/*")
>>           public Response getFile(){
>>
>>           .....
>>
>>           MimetypesFileTypeMap map = new MimetypesFileTypeMap();
>>           String contentType = map.getContentType("file." +
>> fileExtension);
>>           int index = contentType.indexOf("/");
>>           String type = contentType.substring(0, index);
>>           String subType = contentType.substring(index + 1);
>>           MediaType media = new MediaType(type, subType);
>
> You can also do MediaType.parse(contentType) and remove the custom parsing
> code...
>
>>
>>           ResponseBuilder builder =
>> Response.status(HttpURLConnection.HTTP_OK);
>>           builder.entity(f);
>>           builder.type(media);
>>           builder.header("Content-Length", f.length());
>>           resp = Response.ok().build();
>>
>> I assumed that builder.type(media) would set the Content-Type but it
>> doesn't so I'm also adding it manually:
>>
>>           builder.header("Content-Type", contentType);
>>
>
> builder.type(media) and builder.header("Content-Type", contentType), as
> builder.type(contentType) should have the same effect...
>
>> Its still not setting the content type though. I'm wondering if its
>> down to the class-wide @ProduceMime() which is more restrictive?
>
> I briefly looked at the code, it all should work just fine, have a look
> please at the out interceptor code and at a ResponseImpl and
> ResponseBuilderImpl, as well as at
> AbstractHttpDestination.copyResponseHeaders()...If you could debug and see
> what's happening then
> it would help to fix the problem if any
>
>>
>> Also, is builder.entity() the right way to set the response body? I'm
>> not seeing my file contents in the response at the client.
>
> It is the only way when using a Response. What type is the file object ? If
> it's File or InputStream then it should work...If it's
> Reader then it will work after the 'big update' only...
>
> Cheers, Sergey
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

Reply via email to