6 Replies Latest reply on Sep 12, 2003 6:54 AM by julien1

    How to define content type


      I'm trying to figure out how to set the content-type of the http response from within a module method. What I'd like to do is to allow a user to download a file (octet-stream). Is this possible to do with the Page-object or should I do it in another way?

        • 1. Re: How to define content type

          you have to use the getResource method and override it.
          take a look at mp3player it is doing that actually.


          • 2. Re: How to define content type

            Thanks - that made a lot of things clearer! :)


            • 3. Re: How to define content type

              Hi again! Now I have another problem that you might be able to solve (hopefully). I need to access some objects stored as session attributes from the getResource method. How do I accomplish that?

              If it is not possible to access the session attributes, is there any other way to pass temporary objects to the getResource method?


              • 4. Re: How to define content type

                you are right, it is not possible now, we have to think about it. Maybe we could pass the HttpServletRequest to the getResource method.

                do you have an idea ? I am a bit in refactoring stuff these days :-)


                • 5. Re: How to define content type

                  I think that passing the HttpServletRequest object is just fine! :)


                  • 6. Re: How to define content type

                    I my movement to refactorise stuff, I slightly changed the way resource are handled.

                    On component support there are two methods :

                    public void getResource(ResourceRequest req, ResourceResponse resp) {
                    String id = req.getPath();
                    Resource res = manager.get(id);
                    if (res == null)
                    res = getResource(id);
                    manager.add(id, res);

                    public Resource getResource(String path) { // like before }

                    you can overrride the getResource a-la-servlet and get all the info you want from the request. To give the resource to nukes, use the setResource on the response.

                    I added a resource manager on the components so when a component is stopped it stops all the streaming resources at the same time. For instance a client listening for an mp3 being streamed will se the connection close when the mp3 player module is removed from nukes.