List Info

Thread: content-type of resources




content-type of resources
user name
2008-05-14 09:38:35
I'm confused.

The resources that are served up by my custom weblet are not
getting any
Content-Type header.

And I've grepped through the entire codebase of weblets and
not found
anywhere that is actually setting the content-type for
resources.

But somehow the content-type is being set for resources on
the weblets
demo site:
   http://confe
rence.irian.at/weblets-demo/
For example the "a simple weblet include via a jsp
bean" page when
tested with Firefox + LiveHttpHeaders shows the correct
Content-Types
for the various files served.

Can someone explain how the demo app is getting the right
mime-types for
its .js, .css, .png etc resources?

Thanks,
Simon


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
For additional commands, e-mail: users-helpweblets.dev.java.net


Re: content-type of resources
user name
2008-05-14 10:21:59
Hello Simon

The mimetype is set
from the container itself via the mime type apis.

Usually the content type is added at the outer rim of the
system
(aka servlet, phase listener) when the response object is
generated
        String contentName = webRequest.getPathInfo();
        String contentTypeDefault =
getServletContext().getMimeType(contentName);
        WebletResponse webResponse =
          new WebletResponseImpl(contentTypeDefault,
httpResponse);
        _webletContainer.service(webRequest, webResponse);

You can enforce different mime types by altering the content
type
attribute in the weblet response
from your own weblet.
The probably more generic and more neutral way is to set
your file
extensions in your
paths according to the mime type the container expects for
your dynamic file.

Weblet currently does not have its own mimetype mappings
(although there is some pre 0.4 code in there which prepares
such a
subsystem, it
might make sense to readd it again later because some
containers do not deliver
mimetype lists on default)



Werner





On Wed, May 14, 2008 at 4:38 PM, simon.kitchingchello.at
<simon.kitchingchello.at> wrote:
> I'm confused.
>
> The resources that are served up by my custom weblet
are not getting any
> Content-Type header.
>
> And I've grepped through the entire codebase of weblets
and not found
> anywhere that is actually setting the content-type for
resources.
>
> But somehow the content-type is being set for resources
on the weblets
> demo site:
>   http://confe
rence.irian.at/weblets-demo/
> For example the "a simple weblet include via a jsp
bean" page when
> tested with Firefox + LiveHttpHeaders shows the correct
Content-Types
> for the various files served.
>
> Can someone explain how the demo app is getting the
right mime-types for
> its .js, .css, .png etc resources?
>
> Thanks,
> Simon
>
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
> For additional commands, e-mail: users-helpweblets.dev.java.net
>
>

------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
For additional commands, e-mail: users-helpweblets.dev.java.net


Re: content-type of resources
user name
2008-05-15 01:58:44
Ok, I see now.

If a custom weblet calls
  response.setContentType("foo")
it gets "foo".

If a custom weblet calls
  response.setContentType(null)
then it gets the container default.

But if it never calls
  response.setContentType
then it gets no "Content-Type" header at all.


It seems rather odd to have to add a call of
  response.setContentType(null)
to my code in order to *get* a content-type output...

But thanks very much for clearing that up.

Regards,
Simon

Werner Punz schrieb:
> Hello Simon
>
> The mimetype is set
> from the container itself via the mime type apis.
>
> Usually the content type is added at the outer rim of
the system
> (aka servlet, phase listener) when the response object
is generated
>         String contentName = webRequest.getPathInfo();
>         String contentTypeDefault =
> getServletContext().getMimeType(contentName);
>         WebletResponse webResponse =
>           new WebletResponseImpl(contentTypeDefault,
httpResponse);
>         _webletContainer.service(webRequest,
webResponse);
>
> You can enforce different mime types by altering the
content type
> attribute in the weblet response
> from your own weblet.
> The probably more generic and more neutral way is to
set your file
> extensions in your
> paths according to the mime type the container expects
for your dynamic file.
>
> Weblet currently does not have its own mimetype
mappings
> (although there is some pre 0.4 code in there which
prepares such a
> subsystem, it
> might make sense to readd it again later because some
containers do not deliver
> mimetype lists on default)
>
>
>
> Werner
>
>
>
>
>
> On Wed, May 14, 2008 at 4:38 PM, simon.kitchingchello.at
> <simon.kitchingchello.at> wrote:
>   
>> I'm confused.
>>
>> The resources that are served up by my custom
weblet are not getting any
>> Content-Type header.
>>
>> And I've grepped through the entire codebase of
weblets and not found
>> anywhere that is actually setting the content-type
for resources.
>>
>> But somehow the content-type is being set for
resources on the weblets
>> demo site:
>>   http://confe
rence.irian.at/weblets-demo/
>> For example the "a simple weblet include via a
jsp bean" page when
>> tested with Firefox + LiveHttpHeaders shows the
correct Content-Types
>> for the various files served.
>>
>> Can someone explain how the demo app is getting the
right mime-types for
>> its .js, .css, .png etc resources?
>>
>> Thanks,
>> Simon
>>
>>
>>
------------------------------------------------------------
---------
>> To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
>> For additional commands, e-mail: users-helpweblets.dev.java.net
>>
>>
>>     
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
> For additional commands, e-mail: users-helpweblets.dev.java.net
>
>
>   


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
For additional commands, e-mail: users-helpweblets.dev.java.net


Re: content-type of resources
user name
2008-05-15 02:30:54
On Thu, May 15, 2008 at 8:58 AM, simon.kitchingchello.at
<simon.kitchingchello.at> wrote:
> Ok, I see now.
>
> If a custom weblet calls
>  response.setContentType("foo")
> it gets "foo".
>
> If a custom weblet calls
>  response.setContentType(null)
> then it gets the container default.
>
> But if it never calls
>  response.setContentType
> then it gets no "Content-Type" header at
all.
>
>
> It seems rather odd to have to add a call of
>  response.setContentType(null)
> to my code in order to *get* a content-type output...

Ok I have to recheck that myself, setting it explicetly to
null should not be
needed, since the response content type already is
determined before
the weblet is called.

Usually if you have your resources path as ...foo.xml then
the content
type automatically is
set if the container has a mime xml mapping.
The setcontenttype should only allow to override the default
value.

I will check that and will keep you informed asap (which is
tomorrow)
We might have a small bug here as well.

(maybe setting it to null enforces a reevaluation of the
content type)


Werner

------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeweblets.dev.java.net
For additional commands, e-mail: users-helpweblets.dev.java.net


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )