12 Replies Latest reply on Oct 12, 2008 9:45 AM by antoine seilles

    how to develop a JBossPortlet?

    antoine seilles Newbie

      Hi ,
      i'm trying to develop a portlet that extends JBossPortlet.
      I want this portlet to print number of users of my portal in konsole.
      No problem to compilation and deploy but then, when i try to see my portlet i have the following error :

      Cause: java.lang.ClassCastException: org.jboss.portlet.JBossRenderRequest cannot be cast to org.jboss.portlet.JBossRenderRequest
      Message: org.jboss.portlet.JBossRenderRequest cannot be cast to org.jboss.portlet.JBossRenderRequest
      StackTrace:

      java.lang.ClassCastException: org.jboss.portlet.JBossRenderRequest cannot be cast to org.jboss.portlet.JBossRenderRequest
      at org.jboss.portlet.JBossPortlet.render(JBossPortlet.java:390)
      at org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl.invokeRender(PortletContainerImpl.java:483)
      at org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl.dispatch(PortletContainerImpl.java:405)



      public class TestPortlet extends JBossPortlet
      {
       private UserModule userModule;
      
       protected void doView(JBossRenderRequest rRequest, JBossRenderResponse rResponse) throws IOException, PortletException,
       PortletSecurityException
       {
       userModule = (UserModule)getPortletContext().getAttribute("UserModule");
       Set users;
       System.out.println(userModule.getUserCount());
       PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(rResponse.encodeURL("/WEB-INF/jsp/default.jsp"));
       prd.include(rRequest, rResponse);
       }
      }
      


      Here is my list of imports :

      import javax.portlet.PortletException;
      import javax.portlet.PortletRequestDispatcher;
      import javax.portlet.PortletSecurityException;
      
      
      import org.jboss.portal.identity.IdentityException;
      import org.jboss.portal.identity.UserModule;
      import org.jboss.portal.identity.User;
      import org.jboss.portlet.JBossPortlet;
      import org.jboss.portlet.JBossRenderRequest;
      import org.jboss.portlet.JBossRenderResponse;
      import org.jboss.portlet.JBossActionResponse;
      import org.jboss.portlet.JBossActionRequest;


      And i use the following libs :
      jboss-portlet-api-lib.jar
      portal-identity-lib.jar
      portlet-api-1.0.jar

        • 1. Re: how to develop a JBossPortlet?
          Burkhard Vogt Newbie

          try removing the jar files (as mentioned below) from your deployment file.

          • 2. Re: how to develop a JBossPortlet?
            antoine seilles Newbie

            Yep it's done.
            Now i have a NullPointerException cause my userModule is null.

            I have tested my context and i don't have an attribute "userModule" define.

            thanks for your time

            • 3. Re: how to develop a JBossPortlet?
              Prabhat Jha Master

              You can get userModule by modifying your jboss-web.xml to add

              <service-name>UserModule</service-name>
               <service-class>org.jboss.portal.identity.UserModule</service-class>
               <service-ref>:service=Module,type=User</service-ref>


              Then you can get it in your portlet by calling userModule = (UserModule)getPortletContext().getAttribute("UserModule");

              • 4. Re: how to develop a JBossPortlet?
                antoine seilles Newbie

                well my web.xml file was really simple :

                <?xml version="1.0" encoding="UTF-8"?>
                <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
                 <display-name>Portlet for testing usermodule</display-name>
                </web-app>
                


                I have tried the followinf jboss-web.xml file but there is a problem cause i don't have an equivalent resource-ref in web.xml.
                I'm gonna look on web for a tuto about this point.

                <?xml version="1.0" encoding="UTF-8"?>
                <jboss-web>
                 <resource-ref>
                 <res-ref-name>GroupManagement</res-ref-name>
                 <service-name>UserModule</service-name>
                 <service-class>org.jboss.portal.identity.UserModule</service-class>
                 <service-ref>:service=Module,type=User</service-ref>
                 </resource-ref>
                </jboss-web>


                • 5. Re: how to develop a JBossPortlet?
                  antoine seilles Newbie

                  Well i don't find any tutoriels...

                  I have the following error when trying to deploy :

                  Failed to parse WEB-INF/jboss-web.xml; - nested throwable: (org.jboss.deployment.DeploymentException: expected one service-ref-name tag)


                  • 6. Re: how to develop a JBossPortlet?
                    antoine seilles Newbie

                    Ok
                    now i deploy without problems but i still have my nullpointerexception...

                    My jboss-web.xml :

                    <?xml version="1.0" encoding="UTF-8"?>
                    <jboss-web>
                     <service>
                     <service-name>UserModule</service-name>
                     <service-class>org.jboss.portal.identity.UserModule</service-class>
                     <service-ref>:service=Module,type=User</service-ref>
                     </service>
                    </jboss-web>


                    • 7. Re: how to develop a JBossPortlet?
                      Burkhard Vogt Newbie

                      web.xml is not meant, but jboss-web.xml instead - just create one. It resides in WEB-INF too.

                      Try this one:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <portlet-app>
                       <portlet>
                       <portlet-name>UserAdminPortlet</portlet-name>
                       <transaction>
                       <trans-attribute>Required</trans-attribute>
                       </transaction>
                       </portlet>
                       <service>
                       <service-name>UserModule</service-name>
                       <service-class>org.jboss.portal.identity.UserModule</service-class>
                       <service-ref>:service=Module,type=User</service-ref>
                       </service>
                      </portlet-app>

                      This might help:
                      http://docs.jboss.com/jbportal/v2.6.6/referenceGuide/html/xmldescriptors.html#descriptors_portlet

                      • 8. Re: how to develop a JBossPortlet?
                        Burkhard Vogt Newbie

                        sorry, name it: jboss-portlet.xml

                        • 9. Re: how to develop a JBossPortlet?
                          antoine seilles Newbie

                          Well no problem for deployment but when i do userModule.getUserCount();
                          I have an error in konsole. Last message of this error :

                          INFO [WebappClassLoader] Illegal access: this web application instance has been stopped already. Could not load org/apache/axis/configuration/EngineConfigurationFactoryDefault.class. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.


                          But i have UserModule in my portletContext now.
                          ;)

                          • 10. Re: how to develop a JBossPortlet?
                            antoine seilles Newbie

                            hum.
                            I have stopped my JBoss et launchd it again.
                            Error is not the same:

                            ERROR [HibernateUserModuleImpl] Cannot count users
                            org.hibernate.HibernateException: Unable to locate current JTA transaction
                            at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
                            at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
                            at org.jboss.portal.identity.db.HibernateUserModuleImpl.getCurrentSession(HibernateUserModuleImpl.java:298)
                            at org.jboss.portal.identity.db.HibernateUserModuleImpl.getUserCount(HibernateUserModuleImpl.java:275)
                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                            at java.lang.reflect.Method.invoke(Method.java:616)
                            at org.jboss.mx.interceptor.AttributeDispatcher.invoke(AttributeDispatcher.java:99)
                            at org.jboss.portal.jems.as.system.JBossServiceModelMBean$4.invoke(JBossServiceModelMBean.java:346)
                            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                            at org.jboss.mx.interceptor.ModelMBeanAttributeInterceptor.invoke(ModelMBeanAttributeInterceptor.java:197)
                            at org.jboss.mx.interceptor.PersistenceInterceptor.invoke(PersistenceInterceptor.java:76)


                            • 11. Re: how to develop a JBossPortlet?
                              Burkhard Vogt Newbie

                              you need to have a portlet/transaction definition in the jboss-portlet.xml (as mentioned abaove) in which the 'portlet-name' corresponds to the name defined in the portet.xml

                              • 12. Re: how to develop a JBossPortlet?
                                antoine seilles Newbie

                                Thanks for your time.

                                It works fine.