From 116f429e351b6e79f4d92979a8cdb63ef9faac2f Mon Sep 17 00:00:00 2001 From: apfelmaennchen Date: Wed, 26 Sep 2012 09:56:16 +0200 Subject: [PATCH 1/2] fix for java.lang.RuntimeException: TableColumnIndex not available... --- source/net/yacy/data/ymark/YMarkTables.java | 11 ++++++----- .../kelondro/blob/TableColumnIndexException.java | 13 +++++++++++++ source/net/yacy/kelondro/blob/Tables.java | 8 ++++---- 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 source/net/yacy/kelondro/blob/TableColumnIndexException.java diff --git a/source/net/yacy/data/ymark/YMarkTables.java b/source/net/yacy/data/ymark/YMarkTables.java index 41c9961c3..70e67706c 100644 --- a/source/net/yacy/data/ymark/YMarkTables.java +++ b/source/net/yacy/data/ymark/YMarkTables.java @@ -47,6 +47,7 @@ import net.yacy.cora.util.SpaceExceededException; import net.yacy.data.WorkTables; import net.yacy.document.Document; import net.yacy.document.Parser.Failure; +import net.yacy.kelondro.blob.TableColumnIndexException; import net.yacy.kelondro.blob.Tables; import net.yacy.kelondro.blob.Tables.Row; import net.yacy.kelondro.blob.TablesColumnIndex; @@ -149,8 +150,8 @@ public class YMarkTables { } } catch (IOException e) { Log.logException(e); - } catch (Exception e) { - Log.logException(e); + } catch (TableColumnIndexException e) { + // currently nothing to do... } } } @@ -164,10 +165,10 @@ public class YMarkTables { this.worktables.delete(bmk_table,urlHash); } if(this.worktables.hasIndex(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key())) { - try { + try { this.worktables.getIndex(bmk_table).delete(urlHash); - } catch (Exception e) { - // nothing to do + } catch (TableColumnIndexException e) { + // currently nothing to do... } } } diff --git a/source/net/yacy/kelondro/blob/TableColumnIndexException.java b/source/net/yacy/kelondro/blob/TableColumnIndexException.java new file mode 100644 index 000000000..7c1b96e29 --- /dev/null +++ b/source/net/yacy/kelondro/blob/TableColumnIndexException.java @@ -0,0 +1,13 @@ +package net.yacy.kelondro.blob; + +public class TableColumnIndexException extends Exception { + + private static final long serialVersionUID = 2397828995935783296L; + + public TableColumnIndexException() { + } + + public TableColumnIndexException(String msg) { + super(msg); + } +} \ No newline at end of file diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.java index 526bf24f8..a75dfffc5 100644 --- a/source/net/yacy/kelondro/blob/Tables.java +++ b/source/net/yacy/kelondro/blob/Tables.java @@ -96,7 +96,7 @@ public class Tables implements Iterable { this.cidx = new ConcurrentHashMap(); } - public TablesColumnIndex getIndex(final String tableName, TablesColumnIndex.INDEXTYPE indexType) throws Exception { + public TablesColumnIndex getIndex(final String tableName, TablesColumnIndex.INDEXTYPE indexType) throws TableColumnIndexException, IOException { final TablesColumnIndex index; switch(indexType) { case RAM: @@ -109,12 +109,12 @@ public class Tables implements Iterable { index = new TablesColumnBLOBIndex(bheap); break; default: - throw new Exception("Unsupported TableColumnIndex: "+indexType.name()); + throw new TableColumnIndexException("Unsupported TableColumnIndex: "+indexType.name()); } return index; } - public TablesColumnIndex getIndex(final String tableName) throws Exception { + public TablesColumnIndex getIndex(final String tableName) throws TableColumnIndexException { // return an existing index if(this.cidx.containsKey(tableName)) { return this.cidx.get(tableName); @@ -131,7 +131,7 @@ public class Tables implements Iterable { final TablesColumnIndex index; if(size < NOINDEX) { - throw new RuntimeException("TableColumnIndex not available for tables with less than "+NOINDEX+" rows: "+tableName); + throw new TableColumnIndexException("TableColumnIndex not available for tables with less than "+NOINDEX+" rows: "+tableName); } if(size < RAMINDEX) { index = new TablesColumnRAMIndex(); From 7efe9eb37b37021c00b7d1da4864b1ed22b2c667 Mon Sep 17 00:00:00 2001 From: apfelmaennchen Date: Wed, 26 Sep 2012 10:36:09 +0200 Subject: [PATCH 2/2] adding CORS access header for Network.xml to overcome cross domain restriction (e.g. necessary to build a JavaScript YaCy client). --- htroot/Network.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/htroot/Network.java b/htroot/Network.java index 3fa937ec8..92b174e79 100644 --- a/htroot/Network.java +++ b/htroot/Network.java @@ -42,6 +42,7 @@ import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.RequestHeader; +import net.yacy.cora.protocol.ResponseHeader; import net.yacy.kelondro.util.MapTools; import net.yacy.peers.NewsDB; import net.yacy.peers.NewsPool; @@ -53,6 +54,7 @@ import net.yacy.search.Switchboard; import net.yacy.search.SwitchboardConstants; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; +import net.yacy.server.servletProperties; public class Network { @@ -62,7 +64,9 @@ public class Network { final Switchboard sb = (Switchboard) switchboard; final long start = System.currentTimeMillis(); - final serverObjects prop = new serverObjects(); + // final serverObjects prop = new serverObjects(); + final servletProperties prop = new servletProperties(); + prop.put("menu", post == null ? 2 : (post.get("menu", "").equals("embed")) ? 0 : (post.get("menu","").equals("simple")) ? 1 : 2); if (sb.peers.mySeed() != null) prop.put("menu_newpeer_peerhash", sb.peers.mySeed().hash); @@ -86,7 +90,7 @@ public class Network { final int disconCount = sb.peers.sizeDisconnected(); int potCount = sb.peers.sizePotential(); -// final boolean complete = ((post == null) ? false : post.get("links", "false").equals("true")); + // final boolean complete = ((post == null) ? false : post.get("links", "false").equals("true")); final long otherppm = sb.peers.countActivePPM(); final double otherqpm = sb.peers.countActiveQPM(); long myppm = 0; @@ -477,6 +481,14 @@ public class Network { prop.putNum("table_rt", System.currentTimeMillis() - start); + // Adding CORS Access header for Network.xml + final String path = requestHeader.get(HeaderFramework.CONNECTION_PROP_PATH); + if(path != null && path.endsWith(".xml")) { + final ResponseHeader outgoingHeader = new ResponseHeader(200); + outgoingHeader.put(HeaderFramework.CORS_ALLOW_ORIGIN, "*"); + prop.setOutgoingHeader(outgoingHeader); + } + // return rewrite properties return prop; }