[Building Sakai] Create new Sakai service

Le Nguyen Thach nevilarus at gmail.com
Tue Jul 27 00:31:42 PDT 2010


Thanks Steve

I already did it , but not in direct way. As you can see in my example code,
I call my service indirectly via the application's logic. So I injected the
service as a property of myapp logic.
-----
package org.sakaiproject.myapp.logic;
class MyappLogicImpl extends MyappLogic{
     private MyService myService;
     public void setMyService(MyService myService){
          this.myService = myService;
     }
     public String testService(){
          return myService.testme();
     }
     public MyClass getServiceClass(){
           MyClass myclass = myService.getMyClass();
           System.out.println(myclass.getTitle());   //line 1 :"TITLE"
           return myclass;
     }
}
-----------------
package org.sakaiproject.myapp.tool.pages;
...
System.out.println(logic.testService()); //line 2 :"OK"
MyClass class = logic.getServiceClass();//line 3 :ClassCastException
System.out.println(class.getTitle());
....
----------------
I got expected results in line 1 and line 2 but not line 3 (
ClassCastException, of course). So myapp's tool cannot understand MyClass
until I inject the service bean directly into it. Am I right? Is there any
other way to solve it ?


Thanks David
You're right. I can only see my impl jars and third party jars. So what
should I do know?

Best Regards.
Le Nguyen Thach

On Mon, Jul 26, 2010 at 5:48 PM, David Horwitz <david.horwitz at uct.ac.za>wrote:

> Something to check as well is that your API's are not getting bundled in
> the sakai component. If you look in tomcat/components/[my
> component]/WEB-INF/lib/
>
> You should only see your impl jars and third party jars. This is
> something that can lead to classcast exception
>
> On 07/26/2010 12:23 PM, Steve Swinsburg wrote:
> > Hi,
> >
> > You are on the right path. You need to inject your service into your tool
> so that it can access it since they are in different classloaders. You do
> this via Spring. You first setup the service as a bean, then add the Spring
> listener in your web.xml and an applicationContext.xml to setup your tool as
> a beans and inject the service beans into it.
> >
> > Using the app buikder check out the components.xml in the pack module and
> the web.xml and applicationContext in tool. If you generate a Wicket tool
> with the app builder you'll get it all.
> >
> > cheers,
> > Steve
> >
> >
> >
> >
> > On 26/07/2010, at 8:03 PM, Le Nguyen Thach wrote:
> >
> >
> >> Hi
> >>
> >> I need to write a new Sakai service to do some basic business logic in
> my project. It supposes to work like some other Sakai services
> (UserDirectoryService, SiteService ..etc). I could not find any tutorial on
> the internet so I created my service as a Sakai Application ( but with no
> tool implementation) using Sakai App Builder. Luckily , It worked. I can
> successfully call a test method like this from my Sakai application.
> >> -----
> >> public String testme(){
> >>    return "OK";
> >> }
> >> -----
> >> But I hit a wall when I started putting real task in it.
> >>
> >> ----Method getMyClass() declared in myservice-api
> >>
> >> public MyClass getMyClass();
> >> ----
> >>
> >> I want to pass the return value to the tool layer in my application . So
> I implemented a method like this in myapp-api and my myapp-impl.
> >>
> >> ----api
> >> public MyClass getServiceClass(int parameter);
> >> -----impl
> >> public MyClass getServiceClass(int parameter){
> >>     return myservice.getMyClass();
> >> }
> >> -------
> >>
> >> Then I called it
> >> ----tool
> >> MyClass class = logic.getServiceClass(parameter);  //line 1
> >> String x = class.getTitle();
> >> ...
> >> ----
> >>
> >> But it throwed ClassCastException right at line 1. I have searched on
> internet and some people said It got something to do with "classloader". I
> guess MyClass in myapp and MyClass in myservice had been loaded into
> different libraries ( eventhough they have same code). I can't think any
> solution here. Could somebody give me some suggestions?
> >>
> >> Many thanks !
> >>
> >> Le Nguyen Thach
> >> _______________________________________________
> >> sakai-dev mailing list
> >> sakai-dev at collab.sakaiproject.org
> >> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> >>
> >> TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
> >>
> > _______________________________________________
> > sakai-dev mailing list
> > sakai-dev at collab.sakaiproject.org
> > http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> >
> > TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
> >
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20100727/4642eddb/attachment.html 


More information about the sakai-dev mailing list