hmm that is a bug then of StringRequestTarget
It should set that header if the content type is specified.

I will fix that




On Thu, May 22, 2008 at 2:02 PM, Edvin Syse <[EMAIL PROTECTED]> wrote:

> Update: overriding respond and setting the contentType directly works great
> :)
>
> -- Edvin
>
> Edvin Syse skrev:
>
>  Sure I could, but since the StringRequestTarget constructor takes a
>> content-type argument, I find it strange that this isn't sent to the
>> browser. Sure enough, StringRequestTarget#respond, creates as
>> StringBufferResourcesStream with the contentType field set correctly, but
>> then it just copies the stream, and doesn't set any headers.
>>
>> Maybe this will work?
>>
>> RequestCycle.get().setRequestTarget(new StringRequestTarget("text/html",
>> body) {
>>    public void respond(RequestCycle requestCycle) {
>>        requestCycle.getResponse().setContentType("text/html");
>>        super.respond(requestCycle);
>>    }
>> });
>>
>> -- Edvin
>>
>> richardwilko skrev:
>>
>>> You could implement your own dynamic web resource.  eg for a kml page on
>>> our
>>> site:
>>>
>>>
>>> public class KMLResource extends DynamicWebResource
>>> {
>>>
>>>    Document kml;
>>>        public KMLResource(Document kml)
>>>    {
>>>        this.kml = kml;
>>>    }
>>>        @Override
>>>    protected ResourceState getResourceState()
>>>    {
>>>        final XMLOutputter out = new XMLOutputter();
>>>              KMLResourceState kmlResourceState = new KMLResourceState();
>>>        try
>>>        {
>>>            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
>>>            out.output(kml, byteout);
>>>            kmlResourceState.setData(byteout.toByteArray());
>>>            byteout.close();
>>>        }
>>>        catch (IOException e)
>>>        {
>>>            e.printStackTrace();
>>>        }
>>>        return kmlResourceState;
>>>    }
>>>
>>>        class KMLResourceState extends ResourceState
>>>    {
>>>        @Override
>>>        public String getContentType()
>>>        {
>>>            return "application/vnd.google-earth.kml+xml";
>>>        }
>>>
>>>        private byte[] data = new byte[0];
>>>        @Override
>>>        public byte[] getData()
>>>        {
>>>            return data;
>>>        }
>>>        public void setData(byte[] data)
>>>        {
>>>            this.data = data;
>>>        }
>>>              @Override
>>>        public int getLength()
>>>        {
>>>            return data.length;
>>>        }
>>>    }
>>> }
>>>
>>> then use it like this in your page
>>>
>>> final KMLResource kmlResource = new KMLResource(kml);
>>>              getRequestCycle().setRequestTarget(new IRequestTarget() {
>>>
>>>            public void detach(RequestCycle requestCycle) {
>>>                          }
>>>            public void respond(RequestCycle requestCycle) {
>>>                              ResourceStreamRequestTarget target = new
>>> ResourceStreamRequestTarget(kmlResource.getResourceStream());
>>>                target.setFileName("name");
>>>
>>>                getRequestCycle().setRequestTarget(target);             }
>>>        });
>>>
>>> just alter it for text rather than a Document
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to