6 Replies Latest reply on Sep 6, 2006 5:32 PM by Tyler Zerr

    Building a service for the Portal

    Tim Seckendorf Newbie

      I am new to the Jboss Portal and this is my first post to the forum. However I have a significant amount of experience on Exo Platform and JSR168 spec. platforms. What I am looking for help with is a refrece to building/writing or a refrence on how to write and deploy your own Service for the JBoss Portal. If such an animial exists or a road map of how the current services are build an deployed, that would also be very helpful.

      Specifically, I am interested in building a JDBC service or DAO service that is not hybernate based. I just want to be able to ask the portal or context for a data sercice that returns a JDBC connection. If there is a shout cut to doing this I would be extremely greatfull if some one could give me a heads up or point me in the right direction.

      Thanks for any help in advance.

      tseckend

        • 1. Re: Building a service for the Portal
          Tyler Zerr Newbie

          If you are using ejb3.0 you can check out the ejb3 TrailBlazer section on JMS Service objects. It is extremely simple to make an MBean service on jboss using ejb3.
          It is here:

          http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/jmx/index.html

          Of course, using ejb3 usually means you don't need to get jdbc connections manually. So if your not using ejb3, then the information on writing MBean services manually is in the JBoss AS Guide doc, sectiion 2.4 (specifically 2.4.3). This is much harder than using ejb3. You can download it here:

          http://labs.jboss.com/portal/jbossas/docs/index.html

          The JMS spec itself is also good to read for the fully detailed information on writing services if you need more information.

          • 2. Re: Building a service for the Portal
            Tim Seckendorf Newbie

            Zert1, I am talking about a Portal Service as describe

            <portlet-app>

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

            </portlet-app>

            UserModule userModule = (UserModule) getPortletContext().getAttribute("UserModule");
            String userId = request.getParameters().getParameter("userid");
            User user = userModule.findUserById(userID);

            Were should I be implementing this code, and what else needs to be done to get this to work correctly.

            tseckend

            "zerrt1" wrote:
            If you are using ejb3.0 you can check out the ejb3 TrailBlazer section on JMS Service objects. It is extremely simple to make an MBean service on jboss using ejb3.
            It is here:

            http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/jmx/index.html

            Of course, using ejb3 usually means you don't need to get jdbc connections manually. So if your not using ejb3, then the information on writing MBean services manually is in the JBoss AS Guide doc, sectiion 2.4 (specifically 2.4.3). This is much harder than using ejb3. You can download it here:

            http://labs.jboss.com/portal/jbossas/docs/index.html

            The JMS spec itself is also good to read for the fully detailed information on writing services if you need more information.



            • 3. Re: Building a service for the Portal
              Tyler Zerr Newbie

              OK, so you would create your MBean service class as described in the documentation links in my first post.

              - create an interface for your MBean that extends extends org.jboss.system.ServiceMBean

              -create your MBean class that extends extends org.jboss.system.ServiceMBeanSupport and implements your interface from step one

              -put all the logic/methods that want to use in this class

              -load your MBean service using a *-service.xml file, which specifies the NAME of the service you have created. This file can either be right under the deploy directory or in the META-INF dir inside your .sar application. The service should then show up in your jmx console under this name. Now you can inject the service using the code that you quoted.


              For example, here is the code in the jboss-portal.sar/META-INF/jboss-service.xml file that loads the UserModule portlet as a service in your example

              <mbean>
               code="org.jboss.portal.identity.db.UserModuleImpl"
               name="portal:service=Module,type=User"
              ...
              </mbean>
              


              The code= is the name of the class, so you would use your classe's fully qualified name.
              The name= is the name you want to call your service. I'm not sure if you have to start the name with portal: for it to work with a portlet, but you can try with a different name if you want.

              The basic structure of the name should be:
              {app-name]:service={somename},type={somename}

              So your descriptor would look something like:
               <mbean>
               code="org.mypackage.DAOClass"
               name="portal:service:Module,type=DAOAccess"
               </mbean>
              


              Then you can inject the service in your portlet with this code in your jboss-portlet.xml file

              <portlet-app>
              <service-name>DAOAccessModule</service-name>
              <service-class>org.mypackage.DAOClass</service-class>
              <service-ref>:service-Module,type=DAOAccess</service-ref>
              </portlet-app>
              


              (if you use a name other than portal for start of your service name, you should include it in the servive-ref, not sure about if that works or not)

              So, the ref and class are the same as set in the service.xml, the name you will use in your portlet to get the service from the context

              DAOClass dao = (DAOClass) getPortletContext().getAttribute("DAOAccessModule");
              dao.getConection() ....
              


              I should mention that I have never done this yet, I have only created a service, I haven't injected it in a portlet before. But this is how the docs say to do it.

              If you use the ejb3 method to create your MBean you simply create a class and add the @Service annotation with the name of your service (portal:Service=Module,type=DAOAccess) and the @Management annotation with the interface describing the methods, etc that you want to expose in the service in the jmx-console. That is explained in the link in my first post. Then you inject the service the same way as in your example code.

              I hope this helps.

              • 4. Re: Building a service for the Portal
                Tim Seckendorf Newbie

                zerrt:

                Wow, I will give it a try. I will let you know how it works for me. Thanks for the detail this is what I have been missing.

                Thanks again !!

                • 5. Re: Building a service for the Portal
                  Antoine Herzog Master

                  for the portal part of the question : yes, it works fine, the service work the same way in the portlet.
                  you can see an example in the CMSPortlet, with the CMSService (interface is CMS).
                  look at the jboss-service.xml for examples of descriptor of existing services in the portal. it is in some meta-inf folder in the portal folders.

                  • 6. Re: Building a service for the Portal
                    Tyler Zerr Newbie

                    But the CMS service name begins with "portal:", is there any service injected into the portlet context that don't start with portal:? I couldn't find any.

                    It probably allows any service to be injected I would think. Just not sure if you need to then add the full name instead of leaving out the first part.