Commit 8c067d2f authored by Ivar Refsdal's avatar Ivar Refsdal

Dump md5 of input fields

parent cb88cf6f
......@@ -12,28 +12,29 @@
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.13.v20161014</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
......
package no.nsd.programvareutvikling;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
......@@ -12,7 +12,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.UUID;
public class DataSetConverter {
public static class SimpleHandler extends AbstractHandler {
......@@ -21,36 +20,20 @@ public class DataSetConverter {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
try {
try (Writer writer = response.getWriter()) {
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
long starttime = System.currentTimeMillis();
FileItemStream item = iter.next();
InputStream stream = item.openStream();
String filename = UUID.randomUUID().toString() + ".bin";
String tmpFileName = "/tmp/" + filename;
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFileName))) {
IOUtils.copy(stream, os);
try (InputStream stream = item.openStream()) {
String md5 = DigestUtils.md5Hex(stream);
System.out.println("md5 of input " + item.getFieldName() + " is " + md5);
writer.write(item.getFieldName() + ": " + md5 + "\n");
}
long diff = System.currentTimeMillis() - starttime;
System.out.println("Saved filename " + filename + " in " + diff);
}
File responseFile = new File("response.bin");
if (responseFile.exists()) {
long starttime = System.currentTimeMillis();
try (InputStream is = new BufferedInputStream(new FileInputStream(responseFile))) {
try (OutputStream os = new BufferedOutputStream(response.getOutputStream())) {
IOUtils.copy(is, os);
}
}
long diff = System.currentTimeMillis() - starttime;
System.out.println("Wrote response.bin in " + diff);
} else {
System.out.println("no response.bin found... Absolute path: " + responseFile.getAbsolutePath());
}
response.setStatus(200);
} catch (Exception e) {
e.printStackTrace();
response.setStatus(500);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment