1. Ge#ng started
with Sakai development
Steve Swinsburg
Senior So8ware Engineer / Sakai Fellow 2009
The Australian NaBonal University
September 2010
2. Development environment
What are Sakai tools?
The Kernel
Dependency injecBon
Overview
4th Australian Sakai Conference ‐ September 15‐17, 2010 2
3. Development environment
• Requirements:
• Java 1.6
• Maven 2.2.1
• Tomcat 5.5.30
• Sakai Programmer’s Cafe
• Includes manual and code samples
• h_p://bit.ly/sakai‐programmers‐cafe
• Sakai app builder
• Eclipse plugin
4th Australian Sakai Conference ‐ September 15‐17, 2010 3
4. What are Sakai tools?
• A collecBon of webapps
• Shared API’s
• Linked implementaBons
• Glued together (via Spring)
4th Australian Sakai Conference ‐ September 15‐17, 2010 4
5. Sakai tools (the webapp)
• Just a normal webapp with a bit of ‘glue in
web.xml
• The webapp servlet
• Standard Tomcat setup, registers the app
<servlet>
<servlet-name>sakai.myapp</servlet-name>
<servlet-class>
org.sakaiproject.myapp.tool.MyAppServlet
</servlet-class>
</servlet>
4th Australian Sakai Conference ‐ September 15‐17, 2010 5
6. Sakai tools (the webapp)
• The request filter
• Maintains the session
<filter>
<filter-name>sakai.request</filter-name>
<filter-class>
org.sakaiproject.util.RequestFilter
</filter-class>
<!-- can configure this with init-params -->
</filter>
<filter-mapping>
<filter-name>sakai.request</filter-name>
<servlet-name>sakai.myapp</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
4th Australian Sakai Conference ‐ September 15‐17, 2010 6
7. Sakai tools (the webapp)
• A tool listener:
<listener>
<listener-class>
org.sakaiproject.util.ToolListener
</listener-class>
</listener>
• OpBonal Sakai/Spring listener:
<listener>
<listener-class>
org.sakaiproject.util.ContextLoaderListener
</listener-class>
</listener>
4th Australian Sakai Conference ‐ September 15‐17, 2010 7
8. Sakai tools (the webapp)
• The tool registraBon:
• Special convenBon / locaBon
• Must have unique id’s that match
• WEBAPP/tools/sakai.myapp.xml
<?xml version="1.0"?>
<registration>
<tool id="sakai.myapp"
title="My Great Application"
description="This is my new great application">
<category name="myworkspace" />
<configuration name="functions.require" />
</tool>
</registration>
4th Australian Sakai Conference ‐ September 15‐17, 2010 8
9. Sakai tools (the webapp)
• Many different frameworks
• Wicket, RSF, JSP, Servlets, even HTML/JS
• Some have their own web.xml setup
• Portal wrapper and your markup to give a
consistent look and feel
• JSR‐168 portlet support
4th Australian Sakai Conference ‐ September 15‐17, 2010 9
12. The Component Manager
• Webapps normally run in isolaBon
• To allow communicaBon, service is separated from
the webapp.
• ComponentManager loads the
‘components’ (services) and makes them available
to the webapps, thus allowing communicaBon.
4th Australian Sakai Conference ‐ September 15‐17, 2010 12
13. The Kernel
• Previously were inside tools themselves
• Split out the core services into a ‘kernel’
• UserDirectoryService
• SiteService
• ToolService
• SecurityService
• EmailService
• EventTrackingService
• ContentHosBngService
4th Australian Sakai Conference ‐ September 15‐17, 2010 13
14. Dependency injecBon
• Via Spring (preferred):
• Service wiring in TOMCAT/components/
myapp-pack/WEB-INF/components.xml
• setters (getters) in the impl class
<bean id="org.sakaiproject.myapp.logic.SakaiProxy"
class="org.sakaiproject.myapp.logic.SakaiProxyImpl”
init-method="init">
<property name="securityService"
ref="org.sakaiproject.authz.api.SecurityService" />
<property name="userDirectoryService"
ref="org.sakaiproject.user.api.UserDirectoryService" />
</bean>
4th Australian Sakai Conference ‐ September 15‐17, 2010 14
15. Dependency injecBon
• Via the ComponentManager staBc cover
• No Spring wiring needed
• Useful upgrade for legacy code
• Directly in class, in init/constructor
private UserDirectoryService uds;
ComponentManager manager =
org.sakaiproject.component.cover.ComponentManager.getInstance();
uds =
(UserDirectoryService)manager.get(UserDirectoryService.class);
4th Australian Sakai Conference ‐ September 15‐17, 2010 15