commit
245da57a6e
28 changed files with 659 additions and 0 deletions
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<classpath> |
||||
<classpathentry kind="src" output="target/classes" path="src"> |
||||
<attributes> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/WildFly 22.0 Runtime"> |
||||
<attributes> |
||||
<attribute name="owner.project.facets" value="jst.web"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
||||
<attributes> |
||||
<attribute name="module" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="output" path="target/classes"/> |
||||
</classpath> |
||||
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<projectDescription> |
||||
<name>Download Manager</name> |
||||
<comment></comment> |
||||
<projects> |
||||
</projects> |
||||
<buildSpec> |
||||
<buildCommand> |
||||
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
<arguments> |
||||
</arguments> |
||||
</buildCommand> |
||||
<buildCommand> |
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name> |
||||
<arguments> |
||||
</arguments> |
||||
</buildCommand> |
||||
<buildCommand> |
||||
<name>org.eclipse.wst.validation.validationbuilder</name> |
||||
<arguments> |
||||
</arguments> |
||||
</buildCommand> |
||||
<buildCommand> |
||||
<name>org.eclipse.m2e.core.maven2Builder</name> |
||||
<arguments> |
||||
</arguments> |
||||
</buildCommand> |
||||
</buildSpec> |
||||
<natures> |
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature> |
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> |
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> |
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
||||
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> |
||||
</natures> |
||||
</projectDescription> |
||||
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<classpath> |
||||
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/> |
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/> |
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject"> |
||||
<attributes> |
||||
<attribute name="hide" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/> |
||||
<classpathentry kind="output" path=""/> |
||||
</classpath> |
||||
@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1 |
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
||||
org.eclipse.jdt.core.compiler.compliance=1.8 |
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning |
||||
org.eclipse.jdt.core.compiler.release=enabled |
||||
org.eclipse.jdt.core.compiler.source=1.8 |
||||
@ -0,0 +1,4 @@
|
||||
activeProfiles= |
||||
eclipse.preferences.version=1 |
||||
resolveWorkspaceProjects=true |
||||
version=1 |
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> |
||||
<wb-module deploy-name="download-manager-web-0.0.1-SNAPSHOT"> |
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> |
||||
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/> |
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/> |
||||
<property name="java-output-path" value="/Download Manager/build/classes"/> |
||||
<property name="context-root" value="download-manager-web"/> |
||||
</wb-module> |
||||
</project-modules> |
||||
@ -0,0 +1,12 @@
|
||||
<root> |
||||
<facet id="jst.jaxrs"> |
||||
<node name="libprov"> |
||||
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/> |
||||
</node> |
||||
</facet> |
||||
<facet id="jst.jsf"> |
||||
<node name="libprov"> |
||||
<attribute name="provider-id" value="jsf-no-op-library-provider"/> |
||||
</node> |
||||
</facet> |
||||
</root> |
||||
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<faceted-project> |
||||
<runtime name="WildFly 22.0 Runtime"/> |
||||
<fixed facet="jst.web"/> |
||||
<fixed facet="java"/> |
||||
<fixed facet="wst.jsdt.web"/> |
||||
<installed facet="jst.web" version="4.0"/> |
||||
<installed facet="wst.jsdt.web" version="1.0"/> |
||||
<installed facet="jst.jaxrs" version="2.1"/> |
||||
<installed facet="java" version="11"/> |
||||
<installed facet="jst.jsf" version="2.2"/> |
||||
</faceted-project> |
||||
@ -0,0 +1 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary |
||||
@ -0,0 +1,2 @@
|
||||
disabled=06target |
||||
eclipse.preferences.version=1 |
||||
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0 |
||||
Class-Path: |
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
||||
<jboss-deployment-structure> |
||||
<deployment> |
||||
<dependencies> |
||||
<module name="org.slf4j" /> |
||||
</dependencies> |
||||
</deployment> |
||||
</jboss-deployment-structure> |
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation=" |
||||
http://www.jboss.com/xml/ns/javaee |
||||
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd"> |
||||
<context-root>/dm</context-root> |
||||
</jboss-web> |
||||
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html><%@ |
||||
page import="java.util.Collection,org.leolo.web.dm.dao.*,org.leolo.web.dm.model.*" |
||||
%><html> |
||||
<head> |
||||
<title>Download Manager</title> |
||||
</head> |
||||
<body> |
||||
<h1>Download Manager</h1> |
||||
<% Collection<Project> projs = new ProjectDao().getAllProjects(); %> |
||||
<h2>Project List</h2> |
||||
<ul><% for(Project proj:projs){ %> |
||||
<li><a href="project/<%=proj.getProjectPath()%>"><%= proj.getProjectName() %></a></li> |
||||
<%} %></ul> |
||||
</body> |
||||
</html> |
||||
@ -0,0 +1,41 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>org.leolo.web.download-manager</groupId> |
||||
<artifactId>download-manager-web</artifactId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
<packaging>war</packaging> |
||||
<build> |
||||
<sourceDirectory>src</sourceDirectory> |
||||
<plugins> |
||||
<plugin> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.8.0</version> |
||||
<configuration> |
||||
<release>11</release> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<artifactId>maven-war-plugin</artifactId> |
||||
<version>3.2.1</version> |
||||
<configuration> |
||||
<warSourceDirectory>WebContent</warSourceDirectory> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
<dependencies> |
||||
|
||||
<dependency> |
||||
<groupId>org.json</groupId> |
||||
<artifactId>json</artifactId> |
||||
<version>20210307</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>at.favre.lib</groupId> |
||||
<artifactId>bcrypt</artifactId> |
||||
<version>0.9.0</version> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,6 @@
|
||||
package org.leolo.web.dm; |
||||
|
||||
public class Constant { |
||||
public static final String SESSION_USER_ID = "uid"; |
||||
public static final String SESSION_USER_NAME = "uname"; |
||||
} |
||||
@ -0,0 +1,33 @@
|
||||
package org.leolo.web.dm; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.SQLException; |
||||
|
||||
import javax.naming.InitialContext; |
||||
import javax.naming.NamingException; |
||||
import javax.sql.DataSource; |
||||
|
||||
public class DatabaseManager { |
||||
|
||||
private static DataSource ds; |
||||
|
||||
static { |
||||
InitialContext context; |
||||
try { |
||||
context = new InitialContext(); |
||||
ds = (DataSource) context.lookup("java:/dm"); |
||||
} catch (NamingException e) { |
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private DatabaseManager() { |
||||
|
||||
} |
||||
|
||||
public static Connection getConnection() throws SQLException { |
||||
return ds.getConnection(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package org.leolo.web.dm.dao; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.SQLException; |
||||
|
||||
import org.leolo.web.dm.DatabaseManager; |
||||
|
||||
public abstract class BaseDao { |
||||
|
||||
protected Connection getConnection() throws SQLException { |
||||
return DatabaseManager.getConnection(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,117 @@
|
||||
package org.leolo.web.dm.dao; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.PreparedStatement; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.Collection; |
||||
import java.util.Vector; |
||||
|
||||
import org.leolo.web.dm.model.Project; |
||||
import org.leolo.web.dm.model.ProjectMode; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.slf4j.Marker; |
||||
import org.slf4j.MarkerFactory; |
||||
|
||||
public class ProjectDao extends BaseDao{ |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ProjectDao.class); |
||||
private static Marker mark = MarkerFactory.getMarker("org.leolo.web.dm"); |
||||
|
||||
public Collection<Project> getAllProjects(){ |
||||
Vector<Project> v = new Vector<>(); |
||||
try( |
||||
Connection conn = getConnection(); |
||||
Statement stmt = conn.createStatement(); |
||||
ResultSet rs = stmt.executeQuery("SELECT project_id, project_path, project_name, mode FROM project") |
||||
){ |
||||
while(rs.next()) { |
||||
Project proj = new Project(); |
||||
proj.setProjectId(rs.getInt(1)); |
||||
proj.setProjectPath(rs.getString(2)); |
||||
proj.setProjectName(rs.getString(3)); |
||||
if("master".equalsIgnoreCase(rs.getString(4))) { |
||||
proj.setMode(ProjectMode.MASTER); |
||||
}else { |
||||
proj.setMode(ProjectMode.SLAVE); |
||||
} |
||||
v.add(proj); |
||||
} |
||||
}catch(SQLException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return v; |
||||
} |
||||
|
||||
public Project getProjectByPath(String path) { |
||||
try( |
||||
Connection conn = getConnection(); |
||||
PreparedStatement stmt = conn.prepareStatement("SELECT project_id, project_path, project_name, mode FROM project WHERE project_path = ?"); |
||||
){ |
||||
stmt.setString(1, path); |
||||
try(ResultSet rs = stmt.executeQuery()){ |
||||
while(rs.next()) { |
||||
Project proj = new Project(); |
||||
proj.setProjectId(rs.getInt(1)); |
||||
proj.setProjectPath(rs.getString(2)); |
||||
proj.setProjectName(rs.getString(3)); |
||||
if("master".equalsIgnoreCase(rs.getString(4))) { |
||||
proj.setMode(ProjectMode.MASTER); |
||||
}else { |
||||
proj.setMode(ProjectMode.SLAVE); |
||||
} |
||||
return proj; |
||||
} |
||||
} |
||||
}catch(SQLException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Collection<String> getProjectPathsIgnoreCase(String path) { |
||||
Vector<String> names = new Vector<>(); |
||||
try( |
||||
Connection conn = getConnection(); |
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT project_path FROM project WHERE UPPER(project_path) = ?") |
||||
){ |
||||
pstmt.setString(1, path.toUpperCase()); |
||||
try(ResultSet rs = pstmt.executeQuery()){ |
||||
while(rs.next()) { |
||||
names.add(rs.getString(1)); |
||||
} |
||||
} |
||||
}catch(SQLException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return names; |
||||
} |
||||
|
||||
public Project getProjectById(int projectId) { |
||||
try( |
||||
Connection conn = getConnection(); |
||||
PreparedStatement stmt = conn.prepareStatement("SELECT project_id, project_path, project_name, mode FROM project WHERE project_id = ?"); |
||||
){ |
||||
stmt.setInt(1, projectId); |
||||
try(ResultSet rs = stmt.executeQuery()){ |
||||
while(rs.next()) { |
||||
Project proj = new Project(); |
||||
proj.setProjectId(rs.getInt(1)); |
||||
proj.setProjectPath(rs.getString(2)); |
||||
proj.setProjectName(rs.getString(3)); |
||||
if("master".equalsIgnoreCase(rs.getString(4))) { |
||||
proj.setMode(ProjectMode.MASTER); |
||||
}else { |
||||
proj.setMode(ProjectMode.SLAVE); |
||||
} |
||||
return proj; |
||||
} |
||||
} |
||||
}catch(SQLException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
|
||||
package org.leolo.web.dm.dao; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class SystemParameterDao extends BaseDao { |
||||
private static Logger log = LoggerFactory.getLogger(SystemParameterDao.class); |
||||
|
||||
private static final Object SYNC_TOKEN = new Object(); |
||||
private static Map<String, String> cache = new HashMap<>(); |
||||
static { |
||||
new SystemParameterDao().reloadCache(); |
||||
} |
||||
public void reloadCache() { |
||||
synchronized(SYNC_TOKEN) { |
||||
try( |
||||
Connection conn = getConnection(); |
||||
Statement stmt = conn.createStatement(); |
||||
ResultSet rs = stmt.executeQuery("SELECT parameter_id, parameter_value FROM system_parameter") |
||||
){ |
||||
Map<String, String> cache = new HashMap<>(); |
||||
while(rs.next()) { |
||||
cache.put(rs.getString(1), rs.getString(2)); |
||||
} |
||||
SystemParameterDao.cache = cache; |
||||
}catch(SQLException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
SYNC_TOKEN.notifyAll(); |
||||
} |
||||
} |
||||
|
||||
public String getParameterValue(String parameterName) { |
||||
return cache.get(parameterName); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package org.leolo.web.dm.model; |
||||
|
||||
public class Project { |
||||
private int projectId; |
||||
private String projectPath; |
||||
private String projectName; |
||||
private ProjectMode mode; |
||||
public int getProjectId() { |
||||
return projectId; |
||||
} |
||||
public void setProjectId(int projectId) { |
||||
this.projectId = projectId; |
||||
} |
||||
public String getProjectPath() { |
||||
return projectPath; |
||||
} |
||||
public void setProjectPath(String projectPath) { |
||||
this.projectPath = projectPath; |
||||
} |
||||
public String getProjectName() { |
||||
return projectName; |
||||
} |
||||
public void setProjectName(String projectName) { |
||||
this.projectName = projectName; |
||||
} |
||||
public ProjectMode getMode() { |
||||
return mode; |
||||
} |
||||
public void setMode(ProjectMode mode) { |
||||
this.mode = mode; |
||||
} |
||||
} |
||||
@ -0,0 +1,6 @@
|
||||
package org.leolo.web.dm.model; |
||||
|
||||
public enum ProjectMode { |
||||
MASTER, |
||||
SLAVE; |
||||
} |
||||
@ -0,0 +1,42 @@
|
||||
package org.leolo.web.dm.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.annotation.WebServlet; |
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* Servlet implementation class BaseServlet |
||||
*/ |
||||
public class BaseServlet extends HttpServlet { |
||||
private static final long serialVersionUID = 1L; |
||||
private static Logger log = LoggerFactory.getLogger(BaseServlet.class); |
||||
|
||||
/** |
||||
* @see HttpServlet#HttpServlet() |
||||
*/ |
||||
public BaseServlet() { |
||||
super(); |
||||
// TODO Auto-generated constructor stub
|
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
log.debug("Request - [GET] {}", request.getRequestURI()); |
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,58 @@
|
||||
package org.leolo.web.dm.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.annotation.WebServlet; |
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.json.JSONObject; |
||||
import org.leolo.web.dm.Constant; |
||||
import org.leolo.web.dm.dao.ProjectDao; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.slf4j.Marker; |
||||
import org.slf4j.MarkerFactory; |
||||
|
||||
/** |
||||
* Servlet implementation class LogoutServlet |
||||
*/ |
||||
@WebServlet("/Logout") |
||||
public class LogoutServlet extends HttpServlet { |
||||
private static Logger log = LoggerFactory.getLogger(LogoutServlet.class); |
||||
private static Marker mark = MarkerFactory.getMarker("user"); |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* @see HttpServlet#HttpServlet() |
||||
*/ |
||||
public LogoutServlet() { |
||||
super(); |
||||
// TODO Auto-generated constructor stub
|
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
Object uname = request.getSession().getAttribute(Constant.SESSION_USER_NAME); |
||||
log.info(mark, "User {} logged out.", uname); |
||||
if(uname!=null) { |
||||
request.getSession().invalidate(); |
||||
} |
||||
response.setContentType("application/json"); |
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("status", "success"); |
||||
obj.write(response.getWriter()); |
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
// TODO Auto-generated method stub
|
||||
doGet(request, response); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@
|
||||
package org.leolo.web.dm.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.annotation.WebServlet; |
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
/** |
||||
* Servlet implementation class MainServlet |
||||
*/ |
||||
//@WebServlet("/")
|
||||
public class MainServlet extends HttpServlet { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* @see HttpServlet#HttpServlet() |
||||
*/ |
||||
public MainServlet() { |
||||
super(); |
||||
// TODO Auto-generated constructor stub
|
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
// TODO Auto-generated method stub
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath()); |
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
// TODO Auto-generated method stub
|
||||
doGet(request, response); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,63 @@
|
||||
package org.leolo.web.dm.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.PrintWriter; |
||||
import java.util.Collection; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.annotation.WebServlet; |
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.json.JSONObject; |
||||
import org.leolo.web.dm.dao.ProjectDao; |
||||
import org.leolo.web.dm.model.Project; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* Servlet implementation class MainServlet |
||||
*/ |
||||
@WebServlet({"/metadata/*"}) |
||||
public class ProjectMetadataServlet extends BaseServlet { |
||||
private static Logger log = LoggerFactory.getLogger(ProjectMetadataServlet.class); |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* @see HttpServlet#HttpServlet() |
||||
*/ |
||||
public ProjectMetadataServlet() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
||||
*/ |
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
super.doGet(request, response); |
||||
response.setContentType("application/json"); |
||||
log.info("URL: {}", request.getRequestURI()); |
||||
String projectPath = request.getRequestURI().substring(request.getContextPath().length()+10); |
||||
log.info("Project Requested: {}", projectPath); |
||||
ProjectDao projDao = new ProjectDao(); |
||||
Project proj = projDao.getProjectByPath(projectPath); |
||||
JSONObject retObj = new JSONObject(); |
||||
if(proj==null) { |
||||
retObj.put("status", "error"); |
||||
retObj.put("message", "Specified project cannot be found"); |
||||
retObj.put("requested", projectPath); |
||||
Collection<String> names = projDao.getProjectPathsIgnoreCase(projectPath); |
||||
for(String name:names) { |
||||
retObj.append("suggestedPaths", name); |
||||
} |
||||
}else { |
||||
retObj.put("status", "success"); |
||||
retObj.put("name", proj.getProjectName()); |
||||
retObj.put("id", proj.getProjectId()); |
||||
//TODO: Handle other case
|
||||
} |
||||
retObj.write(response.getWriter()); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue