Creating component modules
WorldServer supports multiple types of pluggable components and you can use them to expand the capabilities of WorldServer. In other words, WorldServer defines exit points through which you can call custom code to perform specific operations.
In the pluggable component model, you can create new component classes by extending the abstract class that corresponds to the type of component you want to develop. For example, the WSProjectAutomaticAction class supports creating new project-level automatic actions.
WSRunnable interface, abstract classes provide you a handle to the WSContext (or derived context) object, which is required to gain access to the various supported service managers. Consider the following code snippet that illustrates a simple WSHttpServlet example:
/**
* SDK Sample implementation of a Custom Servlet.
<p>
* Simple Custom servlet that prints out a list of
* WorldServer users.
*/
public class UserList extends WSHttpServlet
{
public boolean handle(WSContext context,
HttpServletRequest request,
HttpServletResponse response)
{
try {
// Get users
WSUser[] users = context.getUserManager().getUsers();
// List them
PrintWriter out = response.getWriter();
out.print("<table cellpadding=5 border=1>");
out.print("<tr><td colspan=2>WorldServer User List</td></tr>");
for(int i=0; i<users.length; i++) {
out.print("<tr>");
out.print("<td align=center>");
if(users[i].getId() == 1) {
out.print("<img src=ws_ext?resource=images/admin.jpg>");
} else {
out.print("<img src=ws_ext?resource=images/user.jpg>");
}
out.print("</td>");
out.print("<td>");
out.print(users[i].getFullName());
out.print("</td></tr>");
}
out.print("</table>");
} catch (Exception ex) {
throw new WSRuntimeException(ex);
}
return true;
}
When you create an SDK servlet, you must extend the WSHttpServlet class, which requires you to implement the handle method. The SDK execution framework provides you with a handle to an initialized WorldServer context object through the handle method. Each supported pluggable component has its own SDK abstract class which exposes a method that you can implement to gain access to the WorldServer context.