download zip
This commit is contained in:
parent
97324e4647
commit
4c9676773f
@ -20,7 +20,21 @@ public class AuthenticatedServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
session = new Session(req.getSession(true));
|
||||||
|
if (!session.isAuthenticated()) {
|
||||||
|
resp.sendRedirect("/mavor/authenticate");
|
||||||
|
} else {
|
||||||
|
doAuthenticatedPost(req, resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
// nooooothing
|
// nooooothing
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
// nooooothing
|
||||||
|
}
|
||||||
|
}
|
@ -22,8 +22,8 @@ import jakarta.servlet.annotation.WebServlet;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@WebServlet("/download")
|
@WebServlet("/download/jars")
|
||||||
public class Download extends AuthenticatedServlet {
|
public class DownloadJars extends AuthenticatedServlet {
|
||||||
|
|
||||||
private static final String PARAMETER_SITE = "site";
|
private static final String PARAMETER_SITE = "site";
|
||||||
private static final String PARAMETER_GROUP_ID = "groupId";
|
private static final String PARAMETER_GROUP_ID = "groupId";
|
||||||
@ -31,7 +31,6 @@ public class Download extends AuthenticatedServlet {
|
|||||||
private static final String PARAMETER_VERSION = "version";
|
private static final String PARAMETER_VERSION = "version";
|
||||||
private static final String PARAMETER_POM = "pom";
|
private static final String PARAMETER_POM = "pom";
|
||||||
private static final String PARAMETER_TYPE = "type";
|
private static final String PARAMETER_TYPE = "type";
|
||||||
private static final String PARAMETER_ZIP = "zip";
|
|
||||||
|
|
||||||
// TODO: set as property
|
// TODO: set as property
|
||||||
private static final String MAVEN_CMD = "/usr/bin/mvn";
|
private static final String MAVEN_CMD = "/usr/bin/mvn";
|
||||||
@ -39,6 +38,11 @@ public class Download extends AuthenticatedServlet {
|
|||||||
|
|
||||||
private File tempDir = new File(TEMP_DIR);
|
private File tempDir = new File(TEMP_DIR);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
doAuthenticatedGet(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
// TODO: implement a lot of checks:
|
// TODO: implement a lot of checks:
|
||||||
@ -53,13 +57,6 @@ public class Download extends AuthenticatedServlet {
|
|||||||
generatePomXmlByArtifact(site, groupId, artifactId, version);
|
generatePomXmlByArtifact(site, groupId, artifactId, version);
|
||||||
} else if (type.equals("pom")) {
|
} else if (type.equals("pom")) {
|
||||||
writePomXml(req.getParameter(PARAMETER_POM));
|
writePomXml(req.getParameter(PARAMETER_POM));
|
||||||
} else if (type.equals("zip")) {
|
|
||||||
String zipFilename = req.getParameter(PARAMETER_ZIP);
|
|
||||||
File zipFile = new File(tempDir, zipFilename);
|
|
||||||
resp.setContentType("application/zip");
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(zipFile);
|
|
||||||
fileInputStream.transferTo(resp.getOutputStream());
|
|
||||||
fileInputStream.close();
|
|
||||||
} else {
|
} else {
|
||||||
throw new ServletException("Unknown download type: " + type);
|
throw new ServletException("Unknown download type: " + type);
|
||||||
}
|
}
|
||||||
@ -121,7 +118,11 @@ public class Download extends AuthenticatedServlet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return dir.getAbsolutePath().equals(TEMP_DIR) && name.endsWith(".jar");
|
try {
|
||||||
|
return dir.getCanonicalPath().equals(tempDir.getCanonicalPath()) && name.endsWith(".jar");
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -136,7 +137,7 @@ public class Download extends AuthenticatedServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zipStream.close();
|
zipStream.close();
|
||||||
return zipFile.getAbsolutePath();
|
return zipFile.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
37
src/main/java/de/devloop/mavor/servlet/DownloadZip.java
Normal file
37
src/main/java/de/devloop/mavor/servlet/DownloadZip.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package de.devloop.mavor.servlet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import de.devloop.mavor.AuthenticatedServlet;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@WebServlet("/download/zip")
|
||||||
|
public class DownloadZip extends AuthenticatedServlet {
|
||||||
|
|
||||||
|
// TODO: set as property
|
||||||
|
private static final String TEMP_DIR = "/home/damage/Temp/mavor";
|
||||||
|
|
||||||
|
private static final String PARAMETER_FILENAME = "file";
|
||||||
|
private File tempDir = new File(TEMP_DIR);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String zipFilename = req.getParameter(PARAMETER_FILENAME);
|
||||||
|
File zipFile = new File(tempDir, zipFilename);
|
||||||
|
if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) {
|
||||||
|
resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename));
|
||||||
|
resp.setContentType("application/zip");
|
||||||
|
resp.setContentLengthLong(zipFile.length());
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(zipFile);
|
||||||
|
fileInputStream.transferTo(resp.getOutputStream());
|
||||||
|
fileInputStream.close();
|
||||||
|
} else {
|
||||||
|
throw new ServletException("-.-");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
<body style="background-color:black; color:white">
|
<body style="background-color:black; color:white">
|
||||||
Output:<br/>
|
Output:<br/>
|
||||||
<pre>${stdout}</pre><br/>
|
<pre>${stdout}</pre><br/>
|
||||||
File: <a href="/mavor/download?type=zip&file=${zipFilename}">${zipFilename}</a><br/>
|
File: <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/>
|
||||||
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<body style="background-color:black; color:white">
|
<body style="background-color:black; color:white">
|
||||||
<h2>Hello ${username}</h2>
|
<h2>Hello ${username}</h2>
|
||||||
<form method="get" action="/mavor/download">
|
<form method="get" action="/mavor/download/jars">
|
||||||
<input type="hidden" name="type" value="artifact"/>
|
<input type="hidden" name="type" value="artifact"/>
|
||||||
Site: <input type="text" name="site" value="https://source.devloop.de/api/packages/damage/maven/" /><br/>
|
Site: <input type="text" name="site" value="https://source.devloop.de/api/packages/damage/maven/" /><br/>
|
||||||
Group ID: <input type="text" name="groupId" value="org.apache.activemq"/><br/>
|
Group ID: <input type="text" name="groupId" value="org.apache.activemq"/><br/>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
Version: <input type="text" name="version" value="2.39.0"/><br/>
|
Version: <input type="text" name="version" value="2.39.0"/><br/>
|
||||||
<input type="submit"/>
|
<input type="submit"/>
|
||||||
</form>
|
</form>
|
||||||
<form method="get" action="/mavor/download">
|
<form method="post" action="/mavor/download/jars">
|
||||||
<input type="hidden" name="type" value="pom"/>
|
<input type="hidden" name="type" value="pom"/>
|
||||||
POM: <textarea name="pom"></textarea><br/>
|
POM: <textarea name="pom"></textarea><br/>
|
||||||
<input type="submit"/>
|
<input type="submit"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user