2005-09-21 susi

* Bugfix in susidns for deleting entries
2005-09-21  jrandom
    * Add support for HTTP POST to EepGet
    * Use HTTP POST for syndie bulk fetches, since there's a lot of data to
      put in that URL.
This commit is contained in:
jrandom
2005-09-21 06:43:04 +00:00
committed by zzz
parent 7700d12178
commit 3286ca49c8
8 changed files with 142 additions and 30 deletions

View File

@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Revision: 1.22 $
* $Revision: 1.1 $
*/
%>
<%@ page contentType="text/html"%>
@ -136,7 +136,7 @@
</table>
</div>
<c:if test="${book.master}||${book.router}">
<c:if test="${book.master || book.router}">
<div id="buttons">
<p class="buttons"><input type="image" name="action" value="delete" src="images/delete.png" alt="Delete checked" />
</p>

View File

@ -17,14 +17,14 @@ import net.i2p.syndie.data.*;
*/
public class ArchiveServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String path = req.getPathInfo();
if ( (path == null) || (path.trim().length() <= 1) ) {
renderRootIndex(resp);
return;
} else if (path.endsWith(Archive.INDEX_FILE)) {
renderSummary(resp);
} else if (path.endsWith("export.zip")) {
} else if (path.indexOf("export.zip") != -1) {
ExportServlet.export(req, resp);
} else {
String blog = getBlog(path);

View File

@ -24,17 +24,98 @@ import net.i2p.syndie.data.*;
*/
public class ExportServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
export(req, resp);
}
public static void export(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String meta[] = req.getParameterValues("meta");
String entries[] = req.getParameterValues("entry");
try {
doExport(req, resp);
} catch (ServletException se) {
se.printStackTrace();
throw se;
} catch (IOException ioe) {
ioe.printStackTrace();
throw ioe;
}
}
private static void doExport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String meta[] = null;
String entries[] = null;
String type = req.getHeader("Content-Type");
if ( (type == null) || (type.indexOf("boundary") == -1) ) {
// it has to be POSTed with the request, name=value pairs. the export servlet doesn't allow any
// free form fields, so no worry about newlines, so lets parse 'er up
List metaList = new ArrayList();
List entryList = new ArrayList();
StringBuffer key = new StringBuffer();
StringBuffer val = null;
String lenStr = req.getHeader("Content-length");
int len = -1;
if (lenStr != null)
try { len = Integer.valueOf(lenStr).intValue(); } catch (NumberFormatException nfe) {}
int read = 0;
int c = 0;
InputStream in = req.getInputStream();
while ( (len == -1) || (read < len) ){
c = in.read();
if ( (c == '=') && (val == null) ) {
val = new StringBuffer(128);
} else if ( (c == -1) || (c == '&') ) {
String k = (key == null ? "" : key.toString());
String v = (val == null ? "" : val.toString());
if ("meta".equals(k))
metaList.add(v.trim());
else if ("entry".equals(k))
entryList.add(v.trim());
key.setLength(0);
val = null;
// no newlines in the export servlet
if (c == -1)
break;
} else {
if (val == null)
key.append((char)c);
else
val.append((char)c);
}
read++;
}
if (metaList != null) {
meta = new String[metaList.size()];
for (int i = 0; i < metaList.size(); i++)
meta[i] = (String)metaList.get(i);
}
if (entryList != null) {
entries = new String[entryList.size()];
for (int i = 0; i < entryList.size(); i++)
entries[i] = (String)entryList.get(i);
}
} else {
meta = req.getParameterValues("meta");
entries = req.getParameterValues("entry");
}
resp.setContentType("application/x-syndie-zip");
resp.setStatus(200);
OutputStream out = resp.getOutputStream();
ZipOutputStream zo = new ZipOutputStream(out);
if (false) {
StringBuffer bbuf = new StringBuffer(1024);
bbuf.append("meta: ");
if (meta != null)
for (int i = 0; i < meta.length; i++)
bbuf.append(meta[i]).append(", ");
bbuf.append("entries: ");
if (entries != null)
for (int i = 0; i < entries.length; i++)
bbuf.append(entries[i]).append(", ");
System.out.println(bbuf.toString());
}
ZipOutputStream zo = null;
if ( (meta != null) && (entries != null) && (meta.length + entries.length > 0) )
zo = new ZipOutputStream(out);
List metaFiles = getMetaFiles(meta);
@ -62,8 +143,10 @@ public class ExportServlet extends HttpServlet {
zo.closeEntry();
}
zo.finish();
zo.close();
if (zo != null) {
zo.finish();
zo.close();
}
}
private static List getMetaFiles(String blogHashes[]) {

View File

@ -160,27 +160,28 @@ public class RemoteArchiveBean {
if (_exportCapable) {
StringBuffer url = new StringBuffer(512);
url.append(buildExportURL());
StringBuffer postData = new StringBuffer(512);
Set meta = new HashSet();
for (int i = 0; i < entries.length; i++) {
BlogURI uri = new BlogURI(entries[i]);
if (uri.getEntryId() >= 0) {
url.append("entry=").append(uri.toString()).append('&');
postData.append("entry=").append(uri.toString()).append('&');
meta.add(uri.getKeyHash());
_statusMessages.add("Scheduling bulk blog post fetch of " + HTMLRenderer.sanitizeString(entries[i]));
}
}
for (Iterator iter = meta.iterator(); iter.hasNext(); ) {
Hash blog = (Hash)iter.next();
url.append("meta=").append(blog.toBase64()).append('&');
postData.append("meta=").append(blog.toBase64()).append('&');
_statusMessages.add("Scheduling bulk blog metadata fetch of " + blog.toBase64());
}
List urls = new ArrayList(1);
urls.add(url.toString());
List tmpFiles = new ArrayList(1);
try {
File tmp = File.createTempFile("fetchBulk", ".zip", BlogManager.instance().getTempDir());
tmpFiles.add(tmp);
fetch(urls, tmpFiles, user, new BulkFetchListener(tmp));
boolean shouldProxy = (_proxyHost != null) && (_proxyPort > 0);
EepGet get = new EepGet(_context, shouldProxy, _proxyHost, _proxyPort, 0, tmp.getAbsolutePath(), url.toString(), postData.toString());
get.addStatusListener(new BulkFetchListener(tmp));
get.fetch();
} catch (IOException ioe) {
_statusMessages.add("Internal error creating temporary file to fetch " + HTMLRenderer.sanitizeString(url.toString()) + ": " + ioe.getMessage());
}

View File

@ -1,5 +1,6 @@
<% request.setCharacterEncoding("UTF-8"); %>
<%
<%@page autoFlush="false" %><%
request.setCharacterEncoding("UTF-8");
java.util.Map params = request.getParameterMap();
response.setContentType(net.i2p.syndie.web.ArchiveViewerBean.getAttachmentContentType(params));
int len = net.i2p.syndie.web.ArchiveViewerBean.getAttachmentContentLength(params);

View File

@ -35,6 +35,7 @@ public class EepGet {
private int _numRetries;
private String _outputFile;
private String _url;
private String _postData;
private boolean _allowCaching;
private List _listeners;
@ -65,7 +66,13 @@ public class EepGet {
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url) {
this(ctx, shouldProxy, proxyHost, proxyPort, numRetries, outputFile, url, true, null);
}
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, String postData) {
this(ctx, shouldProxy, proxyHost, proxyPort, numRetries, outputFile, url, true, null, postData);
}
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, boolean allowCaching, String etag) {
this(ctx, shouldProxy, proxyHost, proxyPort, numRetries, outputFile, url, allowCaching, etag, null);
}
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, boolean allowCaching, String etag, String postData) {
_context = ctx;
_log = ctx.logManager().getLog(EepGet.class);
_shouldProxy = shouldProxy;
@ -74,6 +81,7 @@ public class EepGet {
_numRetries = numRetries;
_outputFile = outputFile;
_url = url;
_postData = postData;
_alreadyTransferred = 0;
_bytesTransferred = 0;
_bytesRemaining = -1;
@ -562,29 +570,40 @@ public class EepGet {
private String getRequest() {
StringBuffer buf = new StringBuffer(512);
buf.append("GET ").append(_url).append(" HTTP/1.1\n");
boolean post = false;
if ( (_postData != null) && (_postData.length() > 0) )
post = true;
if (post) {
buf.append("POST ").append(_url).append(" HTTP/1.1\r\n");
} else {
buf.append("GET ").append(_url).append(" HTTP/1.1\r\n");
}
try {
URL url = new URL(_url);
buf.append("Host: ").append(url.getHost()).append("\n");
buf.append("Host: ").append(url.getHost()).append("\r\n");
} catch (MalformedURLException mue) {
mue.printStackTrace();
}
if (_alreadyTransferred > 0) {
buf.append("Range: bytes=");
buf.append(_alreadyTransferred);
buf.append("-\n");
buf.append("-\r\n");
}
buf.append("Accept-Encoding: identity;q=1, *;q=0\n");
buf.append("Accept-Encoding: identity;q=1, *;q=0\r\n");
if (!_allowCaching) {
buf.append("Cache-control: no-cache\n");
buf.append("Pragma: no-cache\n");
buf.append("Cache-control: no-cache\r\n");
buf.append("Pragma: no-cache\r\n");
}
if (_etag != null) {
buf.append("If-None-Match: ");
buf.append(_etag);
buf.append("\n");
buf.append("\r\n");
}
buf.append("Connection: close\n\n");
if (post)
buf.append("Content-length: ").append(_postData.length()).append("\r\n");
buf.append("Connection: close\r\n\r\n");
if (post)
buf.append(_postData);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Request: [" + buf.toString() + "]");
return buf.toString();

View File

@ -1,4 +1,12 @@
$Id: history.txt,v 1.260 2005/09/18 18:08:18 jrandom Exp $
$Id: history.txt,v 1.261 2005/09/18 19:56:47 ragnarok Exp $
2005-09-21 susi
* Bugfix in susidns for deleting entries
2005-09-21 jrandom
* Add support for HTTP POST to EepGet
* Use HTTP POST for syndie bulk fetches, since there's a lot of data to
put in that URL.
2005-09-18 jrandom
* Added support for pure 64bit linux with jbigi and the java service

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.241 $ $Date: 2005/09/17 20:29:59 $";
public final static String ID = "$Revision: 1.242 $ $Date: 2005/09/18 18:08:18 $";
public final static String VERSION = "0.6.0.6";
public final static long BUILD = 1;
public final static long BUILD = 2;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);