Where are the web services?
Prev | Chapter 2. 20 Minute Quick Start | Next

## Where are the web services?

The Apache Axis project was integrated into Sakai for the 2.0 release. Axis provides an engine for deploying web services using the SOAP specification. Axis also provides a simple means for deploying methods written in Java as Web Services. You can begin using this feature immediately with little to no knowledge of the actual SOAP specification, or any web service specification for that matter. This involves putting java code into files that end with a *.jws extenstion. We will refer to these as JWS files.

The above figure shows where the JWS files live on the deployed server. They are inside webapps/sakai-axis. The URL for connecting to them from a client is the usual URL for a webapp plus the "?wsdl" parameter. This parameter lets Axis know that you are trying to connect to the file as a web service. Let's take a quick look at what a JWS file looks like.

    import org.sakaiproject.api.kernel.session.cover.SessionManager;
    import org.sakaiproject.service.legacy.user.User;
    import org.sakaiproject.service.legacy.user.cover.UserDirectoryService;

    public class UserWebService {
    	public String addNewUser( String sessionid, String userid, String firstname, String lastname, String email, String type, String password)
    	{
    		Session s = SessionManager.getSession(id);
    		s.setActive();
    		SessionManager.setCurrentSession(s);

    		try {
    			User addeduser = null;
    			addeduser = UserDirectoryService.addUser(userid, firstname, lastname, email, password, type, null);
    		}
    		catch (Exception e) {
    	 		return e.getClass().getName() + " : " + e.getMessage();
    		}
    		return "success";
    	}
    }

If you put the above code snippet into a file named UserWebService.jws and placed it into the sakai-axis directory, you could then connect to it using the URL, "http://pedagogy:8080/sakai-axis/UserWebService.jws?wsdl". Viola, we've just created a web service to add new users to Sakai!

We can see that a JWS file contains a public Java class, and whatever import statements it needs. Any method declared as public will be available via the web service. You can use private functions to do other work in your class and they won't be available to the web service. One caveat is that you cannot yet declare your web service class to be in a package. That support is coming in the future however.

That's all you need to create a simple web service in Sakai 2.1. Wow, that was easy! At some point in your web service career you may want to create more complex SOAP services. These would require more than one *.jws file, however, you'd be surprised how far this coarse grained strategy can get you.

Now might be a good time to search the Sakai Source for the SakaiLogin.jws and SakaiScript.jws and take a peek at them. We will use them in the next section.

Prev | Up | Next
Chapter 2. 20 Minute Quick Start | Home | Creating Users and Sites