Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.coweb.admin.rs;
  
  import java.io.Reader;
  import java.util.List;
  import java.util.Map;
  
 
 
 
 
 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)
              = new AdminImpl();
         else {
             try {
                 Class clazz = Class.forName(adminClass);
                  = (Admin)clazz.newInstance();
             }
             catch(Exception e) {
                  = new AdminImpl();
             }
         }
         
     }
     
 
 	public void doGet(HttpServletRequest reqHttpServletResponse resp
 		
 		String path = req.getPathInfo();
 		if(path.endsWith("/session"))
 			this.getSessions(reqresp);
 		else if(path.startsWith("/session"))
 			this.getSession(reqresp);
 		else if(path.startsWith("/application"))
 			this.getApplication(reqresp);
 		else
 	}
 	
 	public void doPost(HttpServletRequest reqHttpServletResponse resp
 		
 		String path = req.getPathInfo();
 		if(path.startsWith("/session"))
 			this.createSession(reqresp);
 		else if(path.startsWith("/application"))
 			this.registerApplication(reqresp);
 		else
 	}
 	
 	public void doPut(HttpServletRequest reqHttpServletResponse resp
 		
 		String path = req.getPathInfo();
 		if(path.startsWith("/session"))
 			this.updateSession(reqresp);
 		else if(path.startsWith("/application"))
 			this.updateApplication(reqresp);
 		else
 	}
 	
 	public void doDelete(HttpServletRequest reqHttpServletResponse resp
 		
 		String path = req.getPathInfo();
 		if(path.startsWith("/session"))
 			this.deleteSession(reqresp);
		else if(path.startsWith("/application"))
			this.unregisterApplication(reqresp);
		else
	}
		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
			..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<Map<StringObject>> sessions = 
                        acls,
						query,
						sortBy,
						direction,
						-1,
						-1);
			..println(sessions);
			JSONArray arr = null;
			if(sessions != null)
				arr = new JSONArray(sessions);
			else
				arr = new JSONArray();
			arr.write(resp.getWriter());
		}
		catch(Exception e) {
			//throw new ServletException(e.getMessage());
		}
	}
		try {
			String path = req.getPathInfo();
			String[] parts = path.split("/");
			String sessionId = parts[parts.length-1];
                    req.getRemoteUser(), namesessionId);
			JSONObject json = new JSONObject(session);
			json.write(resp.getWriter());
		}
		catch(Exception e) {
			throw new ServletException(e.getMessage());
		}
	}
		try {
			Reader r = req.getReader();
			JSONObject args = null;
			r.mark(1024);
			if(r.read() != -1) {
				r.reset();
				args = new JSONObject(r);
                            name,
						(String)args.get("title"),
						(String)args.get("description"),
						(Map<StringInteger>)args.get("aclsDict"))) {
					throw new ServletException("Error Creating Session");
				}
			}
			else
				throw new ServletException("No Session Info");
		}
		catch(Exception e) {
			//throw new ServletException(e.getMessage());
		}
	}
		try {
			Map<StringObjectapplication = 
                .getApplication(req.getRemoteUser(), name);
			JSONObject json = new JSONObject(name);
			json.write(resp.getWriter());
		}
		catch(Exception e) {
			throw new ServletException(e.getMessage());
		}
	}
		String title = ctx.getServletContextName();
		String description = ctx.getInitParameter("description");
		String appUrl = ctx.getInitParameter("appurl");
		String thumbnailUrl = ctx.getInitParameter("thumbnailurl");
                title
				description
				appUrl
				thumbnailUrl);
		if(ret == -1) {
			throw new ServletException("Error Registering App " + title);
		}
	}
		String title = ctx.getServletContextName();
		boolean ret = .unregisterApplication(req.getRemoteUser(), title);
		if(!ret) {
			throw new ServletException("Error Registering App " + title);
		}
	}
		String title = ctx.getServletContextName();
	}
	}
	}
New to GrepCode? Check out our FAQ X