7 Replies Latest reply on Jun 12, 2007 5:40 PM by ghyoju

    Injecting PortalObjectContainer into servlet

    jkoek

      Version JBOSS 2.4 (latest)

      I want to use the PortalObjectContainer in a servlet.
      I have tried to retrieve it from a context but no luck.

      I want to use it to
      - create portals/pages based on username
      - update portal pages (add/remove/update windows)
      - store user specific settings per portlet.

      I'm already able to use the PortalObjectContainer from out of a portlet, but that means that the complete is updated everytime the user changes
      something.
      Because I'm using AJAX/JSON I want to minimize the updates as possible.



      Can anyone help me?

        • 1. Re: Injecting PortalObjectContainer into servlet

          you need to inject it in the servlet context using the declarative injection in the file jboss-portlet.xml.

          • 2. Re: Injecting PortalObjectContainer into servlet
            jkoek

            Julien,

            I tried it.
            I'm getting now a PortalObjectContainer object but I'm not able to retrieve the context. This context makes it possible for me to createPages and Windows.

            Underneath the code that I have used and the jboss-portlet.xml that is part of my servlet deployment.


            Can you give me a new hint?

            Thanks,

            jeroen.

            try
            {
            MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
            container = (PortalObjectContainer)
            MBeanProxy.get(PortalObjectContainer.class,
            new ObjectName("portal:container=PortalObject"),
            mbeanServer);
            }
            catch (Exception e)
            {
            log.error("Cannot get interceptor stack", e);
            throw new IllegalStateException("Cannot get interceptor stack");
            }
            if (container == null) {
            System.out.println("No portal object container");
            }
            else
            {
            System.out.println( "We got the portal object container" );
            Context ctx = null;
            try {
            ctx = container.getContext();
            }
            catch ( Exception ex ) {
            System.out.println( "Failed to get context" );
            }
            if ( ctx == null ) {
            System.out.println( "PortalObjectContainer context is empty!" );
            }
            }

            <portlet-app>
            <!-- Service injected in the portlet context. -->

            <service-name>PortalObjectContainer</service-name>
            <service-class>org.jboss.portal.core.model.portal.PortalObjectContainer</service-class>
            <service-ref>portal:container=PortalObject</service-ref>


            </portlet-app>

            • 3. Re: Injecting PortalObjectContainer into servlet

              you need to wrap the portal object container usage is a JTA transaction.

              • 4. Re: Injecting PortalObjectContainer into servlet
                jkoek

                Yes, Thanks.
                It works.
                Now I'm off to the next step and that is making the pages user specific.

                To share the knowledge hereby the code.
                In case someone has improvements please suggest.

                TransactionManager tm = null;
                try {
                InitialContext ic = new InitialContext();
                tm = (TransactionManager) ic.lookup("java:/TransactionManager");
                } catch (NamingException ex) {
                System.out.println("Failed to find transactionmnager" );
                }

                try
                {
                tm.begin();
                try {
                MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
                container = (PortalObjectContainer)MBeanProxy.get(PortalObjectContainer.class, new ObjectName("portal:container=PortalObject"), mbeanServer);
                Context ctx = container.getContext();

                PortalObject po = ctx.getDefaultPortal();
                out.print("PortalNode " + po.getName());
                System.out.println( "Portal retrieved!" + po.getName() );

                ++loop;
                Portal portal = (Portal) po;
                portal.createPage( "JBOSS rocks!" + loop );
                portal.createPage( "JBOSS rocks again!" + loop );
                portal.createPage( "JBOSS rocks and again!" + loop );
                }
                finally {
                tm.commit();
                }
                }
                catch ( Exception ex ) {
                ex.printStackTrace();
                }

                • 5. Re: Injecting PortalObjectContainer into servlet
                  agaudreau

                  Thanks to the injection hint I was able to make my custom NavigationPortlet work which was missing the service injections in the jboss-portlet.xml for the PortalObjectContainer... and:

                  <service-name>PortalAuthorizationManagerFactory</service-name>
                  <service-class>org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory</service-class>
                  <service-ref>:service=PortalAuthorizationManagerFactory</service-ref>


                  Posted so anyone trying to do the same will get a hit for this post in a search.

                  • 6. Re: Injecting PortalObjectContainer into servlet
                    fredf

                     

                    "agaudreau" wrote:
                    Thanks to the injection hint I was able to make my custom NavigationPortlet work which was missing the service injections in the jboss-portlet.xml for the PortalObjectContainer... and:
                    <service>
                    <service-name>PortalAuthorizationManagerFactory</service-name>
                    <service-class>org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory</service-class>
                    <service-ref>:service=PortalAuthorizationManagerFactory</service-ref>
                    </service>

                    Posted so anyone trying to do the same will get a hit for this post in a search.


                    I am trying to do the same but I fail recieving the container context. see my post for more info
                    http://jboss.org/index.html?module=bb&op=viewtopic&t=105402

                    • 7. Re: Injecting PortalObjectContainer into servlet
                      ghyoju

                      Hi,

                      In JBOSS portal 2.4 it works. We are trying to use JBOSS portal 2.6 and the Context Class is not in portal-core-lib.jar. Where did it move to? How do I find out.

                      Thanks you very much.

                      Gyan