10 Replies Latest reply on May 4, 2007 5:43 AM by Courtney Couch

    mediaOutput resource error

    Courtney Couch Newbie

      If someone saves a link to a resource and tries to access it at a later time they get an error like:

      org.ajax4jsf.framework.resource.ResourceNotFoundException: Resource not registered : org.ajax4jsf.framework.resource.UserResource/n/n/-1487394660

      Is it possible to have some kind of default paint call or something rather than this error? Even just some default resource would be fine if that is possible.

      Since the data object is passed along serialized, the request has all the information for the server to render the request, can these links permanently work somehow?

        • 1. Re: mediaOutput resource error
          Igor Shabalov Apprentice

          You cannot use mediaOutput in that case because of security concerns.
          It will be better in your case directly use our resource framework.

          1. On page you put something like

          <h:graphicImage value="resource://com.bla.bla.MyResourceGenerator" />


          2. You need to create class com.bla.bla.MyResourceGenerator to implement
          org.ajax4jsf.framework.resource.InternetResource


          The best way to do so is to extends

          org.ajax4jsf.framework.resource.Java2Dresource


          all you need is an implementation of 3 methods:

          getDimentions
          getDataToStore
          paint


          getDataToStore must return ether byte[] or Serialazable instance, I recommend go with byte[] to make URI shorter.

          getDimentions will return size of generated image and paint must use something like

          Data dataToStore = (Data)resourceContext.getResourceData();


          to obtain exactly same data as it was returned by getDataToStore.

          3. Framework will call getDataToStore and getDimentions to create resource URI and replace "resource://your.class.name" with real URI. Actual parameters data will be encoded into URI, in case if this is not byte[], simple Java serialization will be used (so you can yse your own wrapper object and, perhaps, implement Serialazable methods to make serialization more effective).

          You can look to org.richfaces.renderkit.html.BaseGradient as an example.

          It is located in richfaces-common sub-project.



          • 2. Re: mediaOutput resource error
            Courtney Couch Newbie

            will this work with arbitrary binary data? pdf's, videos, or other documents.

            I use the mediaOutput to manage downloadable purchases and I need to embed, link to, or whatever various content (as well as control how many times its downloaded).

            with mediaOutput I am able to access seam components to track how many times a resource has been accessed before painting the output. Using this resource framework would I still have that kind of access to the session at the moment the object is painted when accessing it via the URI?

            • 3. Re: mediaOutput resource error
              Courtney Couch Newbie

              I've been digging around in the org.ajax4jsf.framework.resource package and it looks like what I really need is a custom renderer.

              It looks like renderers are all hard coded in ResourceBuilderImpl. Is there a way to define a new renderer without extending/changing ResourceBuilderImpl?

              I obviously havent had enough time to completely figure out whats going on, but for what I need to do, without using mediaOutput, I need to control the renderer (I need control of the data stream itself and those are managed from the Renderer's rather than the Resource classes like Java2Dresource)

              mediaOutput gave me that control, and mediaOutput seems to work through this resource framework so I'm thinking there is a way to define a renderer for static files, and have that renderer session aware as well.

              • 4. Re: mediaOutput resource error
                Courtney Couch Newbie

                 

                "courtneycouch" wrote:

                ...

                I'm thinking there is a way to define a renderer for static files, and have that renderer session aware as well.


                er. not necessarily just static files.. arbitrary data.


                I may be misinterpreting whats going on here as well obviously :)

                • 5. Re: mediaOutput resource error
                  Courtney Couch Newbie

                  alright I think i got it. (sorry for so many posts..)

                  I'm creating a Resource extending InternetResourceBase, and overriding the getRenderer and setRenderer methods so it uses my renderer. Setting the resource to be session aware.

                  Then creating a renderer extending BaseResourceRenderer and overriding

                  public int send(InternetResource base, ResourceContext context)


                  I believe how your supposed to add new renderers and resources using ajax4jsf correct?

                  • 6. Re: mediaOutput resource error
                    Igor Shabalov Apprentice

                    Yes, if you are talking about arbitrary content, you need renderer. Sorry, my post we assuming that you working with images.

                    We have resource and resourceRenderer.
                    Resource is responsible for "generation" of resource itself and rendering of URI in resource-specific way. ResourceRenderer responsible for rendering of actual resource content into http response. We have bunch of pre-existing renderers and resources for many usecases. What is your particular case?

                    • 7. Re: mediaOutput resource error
                      Renzo Tomaselli Novice

                       

                      "ishabalov" wrote:
                      Yes, if you are talking about arbitrary content, you need renderer. Sorry, my post we assuming that you working with images.

                      We have resource and resourceRenderer.
                      Resource is responsible for "generation" of resource itself and rendering of URI in resource-specific way. ResourceRenderer responsible for rendering of actual resource content into http response. We have bunch of pre-existing renderers and resources for many usecases. What is your particular case?


                      Would this way work for rendering pdf too ? MediaOutput definitely doesn't work for this purpose, I've been told "it's a feature request", see http://jboss.com/index.html?module=bb&op=viewtopic&t=105999
                      Could you please point out some more details for implementing this solution - if suitable for pdf rendering ?
                      Thanks.


                      • 8. Re: mediaOutput resource error
                        Janne Costiander Newbie

                        How do I pass the Object data for the

                        getDataToStore
                        ?

                        I have:
                        <h:graphicImage value="resource://my.class.name"/>

                        and the class gets called, but the object is null.

                        I need some way to pass some parameters to get the proper data in the getDataToStore.

                        • 9. Re: mediaOutput resource error
                          Courtney Couch Newbie

                           

                          "ishabalov" wrote:
                          Yes, if you are talking about arbitrary content, you need renderer. Sorry, my post we assuming that you working with images.

                          We have resource and resourceRenderer.
                          Resource is responsible for "generation" of resource itself and rendering of URI in resource-specific way. ResourceRenderer responsible for rendering of actual resource content into http response. We have bunch of pre-existing renderers and resources for many usecases. What is your particular case?


                          my particular use case is that I have various content (static and dynamic) that I need to control access to, manage total numbers of downloads by user, session, and bandwidth used.

                          For purchased downloadable products.

                          Using mediaOutput I simply access the seam components in the session context and update the relevant information there. The problem with mediaOutput is gracefully failing or making some media permanently available until a set number of complete downloads are successful regardless of a session being live. (like clicking a link from an email for example).

                          Basically I simply need to have control over arbitrary binary data and be able to create and access the stream directly of that data, and access/create seam components based on that request regardless of the session already existing. mediaOutput works for everything except that last part.

                          • 10. Re: mediaOutput resource error
                            Courtney Couch Newbie

                            How is the resource:/// found? Can it exist anywhere?

                            There doesnt seem to be much documentation on this resource framework.

                            If I'm embedding video for example generated, or flash content thats pulled from a custom renderer, how would one get the URI for that resource?

                            Is it possible from a bean to call some method somewhere in the a4j api to get the URI so I can arbitrarily use that URI or provide it to the user? If so, what is that method?