
org.coweb.admin.rs.ApplicationServlet Maven / Gradle / Ivy
package org.coweb.admin.rs;
import java.io.IOException;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.coweb.admin.acls.SessionAcls;
import org.coweb.admin.Admin;
import org.coweb.admin.AdminImpl;
import org.apache.wink.json4j.JSONArray;
import org.apache.wink.json4j.JSONObject;
public class ApplicationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private Admin cowebAdmin;
@Override
public void init() throws ServletException {
super.init();
ServletConfig config = this.getServletConfig();
String adminClass = config.getInitParameter("cowebAdminClass");
//Create the security policy. Default to CowebSecurityPolicy.
if(adminClass == null)
cowebAdmin = new AdminImpl();
else {
try {
Class clazz = Class.forName(adminClass);
cowebAdmin = (Admin)clazz.newInstance();
}
catch(Exception e) {
cowebAdmin = new AdminImpl();
}
}
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String path = req.getPathInfo();
if(path.endsWith("/session"))
this.getSessions(req, resp);
else if(path.startsWith("/session"))
this.getSession(req, resp);
else if(path.startsWith("/application"))
this.getApplication(req, resp);
else
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String path = req.getPathInfo();
if(path.startsWith("/session"))
this.createSession(req, resp);
else if(path.startsWith("/application"))
this.registerApplication(req, resp);
else
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String path = req.getPathInfo();
if(path.startsWith("/session"))
this.updateSession(req, resp);
else if(path.startsWith("/application"))
this.updateApplication(req, resp);
else
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String path = req.getPathInfo();
if(path.startsWith("/session"))
this.deleteSession(req, resp);
else if(path.startsWith("/application"))
this.unregisterApplication(req, resp);
else
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
private void getSessions(HttpServletRequest req, HttpServletResponse resp)
throws ServletException {
try {
Reader r = req.getReader();
JSONObject args = null;
if(r.read() != -1) {
r.reset();
args = new JSONObject(req.getReader());
}
else
args = new JSONObject();
Integer acls = null;
if(args.containsKey("acls"))
acls = ((Integer)args.get("acls")).intValue();
else
acls = SessionAcls.SESS_SEE_BIT;
System.out.println("acls = " + acls);
String query = null;
if(args.containsKey("query")) {
query = (String)args.get("query");
}
String sortBy = null;
if(args.containsKey("sortby"))
sortBy = (String)args.get("sortby");
String direction = null;
if(args.containsKey("direction"))
direction = (String)args.get("direction");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy