提交 d588094e authored 作者: Thomas Mueller's avatar Thomas Mueller

Remove undocumented H2 Console feature 'transfer'

上级 b5b92017
......@@ -151,7 +151,7 @@ public class WebApp {
"jsp".equals(suffix)) {
cache = false;
mimeType = "text/html";
if (session == null && !file.startsWith(WebServer.TRANSFER)) {
if (session == null) {
session = server.createNewSession(hostAddr);
if (!"notAllowed.jsp".equals(file)) {
file = "index.do";
......@@ -239,8 +239,6 @@ public class WebApp {
file = autoCompleteList();
} else if ("tools.do".equals(file)) {
file = tools();
} else if ("transfer.do".equals(file)) {
file = "transfer.jsp";
} else {
file = "error.jsp";
}
......
......@@ -6,7 +6,6 @@
package org.h2.server.web;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -32,7 +31,6 @@ import org.h2.message.DbException;
import org.h2.server.Service;
import org.h2.server.ShutdownHandler;
import org.h2.store.fs.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils;
import org.h2.util.NetUtils;
......@@ -48,8 +46,6 @@ import org.h2.util.Utils;
*/
public class WebServer implements Service {
static final String TRANSFER = "transfer";
static final String[][] LANGUAGES = {
{ "cs", "\u010ce\u0161tina" },
{ "de", "Deutsch" },
......@@ -170,17 +166,6 @@ public class WebServer implements Service {
*/
byte[] getFile(String file) throws IOException {
trace("getFile <" + file + ">");
if (file.startsWith(TRANSFER + "/") && new File(TRANSFER).exists()) {
file = file.substring(TRANSFER.length() + 1);
if (!isSimpleName(file)) {
return null;
}
File f = new File(TRANSFER, file);
if (!f.exists()) {
return null;
}
return IOUtils.readBytesAndClose(new FileInputStream(f), -1);
}
byte[] data = Utils.getResource("/org/h2/server/web/res/" + file);
if (data == null) {
trace(" null");
......
......@@ -7,12 +7,9 @@ package org.h2.server.web;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Iterator;
......@@ -37,7 +34,6 @@ class WebThread extends WebApp implements Runnable {
protected final Socket socket;
private final Thread thread;
private InputStream input;
private int headerBytes;
private String ifModifiedSince;
WebThread(Socket socket, WebServer server) {
......@@ -210,12 +206,10 @@ class WebThread extends WebApp implements Runnable {
private String readHeaderLine() throws IOException {
StringBuilder buff = new StringBuilder();
while (true) {
headerBytes++;
int c = input.read();
if (c == -1) {
throw new IOException("Unexpected EOF");
} else if (c == '\r') {
headerBytes++;
if (input.read() == '\n') {
return buff.length() > 0 ? buff.toString() : null;
}
......@@ -320,7 +314,7 @@ class WebThread extends WebApp implements Runnable {
}
}
if (multipart) {
uploadMultipart(input, len);
// not supported
} else if (session != null && len > 0) {
byte[] bytes = DataUtils.newBytes(len);
for (int pos = 0; pos < len;) {
......@@ -332,45 +326,6 @@ class WebThread extends WebApp implements Runnable {
return keepAlive;
}
private void uploadMultipart(InputStream in, int len) throws IOException {
if (!new File(WebServer.TRANSFER).exists()) {
return;
}
String fileName = "temp.bin";
headerBytes = 0;
String boundary = readHeaderLine();
while (true) {
String line = readHeaderLine();
if (line == null) {
break;
}
int index = line.indexOf("filename=\"");
if (index > 0) {
fileName = line.substring(index +
"filename=\"".length(), line.lastIndexOf('"'));
}
trace(" " + line);
}
if (!WebServer.isSimpleName(fileName)) {
return;
}
len -= headerBytes;
File file = new File(WebServer.TRANSFER, fileName);
OutputStream out = new FileOutputStream(file);
IOUtils.copy(in, out, len);
out.close();
// remove the boundary
RandomAccessFile f = new RandomAccessFile(file, "rw");
int testSize = (int) Math.min(f.length(), Constants.IO_BUFFER_SIZE);
f.seek(f.length() - testSize);
byte[] bytes = DataUtils.newBytes(Constants.IO_BUFFER_SIZE);
f.readFully(bytes, 0, testSize);
String s = new String(bytes, "ASCII");
int x = s.lastIndexOf(boundary);
f.setLength(f.length() - testSize + x - 2);
f.close();
}
private static String getHeaderLineValue(String line) {
return line.substring(line.indexOf(':') + 1).trim();
}
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
and the EPL 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Upload</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<form action="transfer.do" method="post" enctype="multipart/form-data">
<p>
File:<br />
<input name="file" type="file" size="50" /><br /><br />
<input type="submit" value="Upload" />
</p>
</form>
</body></html>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论