From 734340c1289938a9e9091565ad98db595811ae2a Mon Sep 17 00:00:00 2001 From: luccioman Date: Fri, 4 Nov 2016 14:31:22 +0100 Subject: [PATCH] Fixed errors for Search portal mode or when peer is not reachable. Same case as reported on issue #87. --- htroot/Bookmarks.java | 5 +++-- htroot/Bookmarks.rss | 2 +- htroot/Table_YMark_p.java | 3 --- htroot/api/bookmarks/get_bookmarks.java | 5 +++-- htroot/api/bookmarks/get_bookmarks.xml | 2 +- htroot/api/bookmarks/get_folders.java | 5 +++-- htroot/yacysearch_location.java | 15 +++++++-------- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java index 905787de4..4c9b78d80 100644 --- a/htroot/Bookmarks.java +++ b/htroot/Bookmarks.java @@ -54,6 +54,7 @@ import net.yacy.data.BookmarksDB.Bookmark; import net.yacy.data.BookmarksDB.Tag; import net.yacy.document.Document; import net.yacy.document.Parser; +import net.yacy.http.servlets.YaCyDefaultServlet; import net.yacy.kelondro.data.meta.URIMetadataNode; import net.yacy.kelondro.workflow.BusyThread; import net.yacy.peers.NewsPool; @@ -106,8 +107,8 @@ public class Bookmarks { prop.put("LOCATION", "/Bookmarks.html?user="+username); */ - // set peer address - prop.put("address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP())); + // set peer base URL : used by Bookmars.rss to render an absolute URL + prop.put("address", YaCyDefaultServlet.getContext(header, sb)); //defaultvalues if(isAdmin) { diff --git a/htroot/Bookmarks.rss b/htroot/Bookmarks.rss index 5a44ad6ce..717d8ccfa 100644 --- a/htroot/Bookmarks.rss +++ b/htroot/Bookmarks.rss @@ -2,7 +2,7 @@ <![CDATA[YaCy '#[clientname]#': Bookmarks]]> - http://#[address]#/Bookmarks.html + #[address]#/Bookmarks.html #{display_bookmarks}# <![CDATA[#[title]#]]> diff --git a/htroot/Table_YMark_p.java b/htroot/Table_YMark_p.java index a66294e02..43cb1d991 100644 --- a/htroot/Table_YMark_p.java +++ b/htroot/Table_YMark_p.java @@ -273,9 +273,6 @@ public class Table_YMark_p { } - // adding the peer address - prop.put("address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP())); - // return rewrite properties return prop; } diff --git a/htroot/api/bookmarks/get_bookmarks.java b/htroot/api/bookmarks/get_bookmarks.java index 99c357a8e..e3d6d20f4 100644 --- a/htroot/api/bookmarks/get_bookmarks.java +++ b/htroot/api/bookmarks/get_bookmarks.java @@ -10,6 +10,7 @@ import net.yacy.data.BookmarkHelper; import net.yacy.data.BookmarksDB; import net.yacy.data.UserDB; import net.yacy.document.parser.html.CharacterCoding; +import net.yacy.http.servlets.YaCyDefaultServlet; import net.yacy.search.Switchboard; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; @@ -66,8 +67,8 @@ public class get_bookmarks { else username = "unknown"; prop.putHTML("display_user", username); - // set peer address - prop.put("display_address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP())); + // set peer address base : used in get_bookmarks.xml to render the absolute API link URL + prop.put("display_address", YaCyDefaultServlet.getContext(header, sb)); prop.put("display_peer", sb.peers.mySeed().getName()); final int itemsPerPage; // items per page diff --git a/htroot/api/bookmarks/get_bookmarks.xml b/htroot/api/bookmarks/get_bookmarks.xml index eed31fa95..345c83e83 100644 --- a/htroot/api/bookmarks/get_bookmarks.xml +++ b/htroot/api/bookmarks/get_bookmarks.xml @@ -37,7 +37,7 @@ <![CDATA[YaCy '#[peer]#': Bookmarks]]> - http://#[address]#/api/bookmarks/get_bookmarks.xml + #[address]#/api/bookmarks/get_bookmarks.xml #{bookmarks}# diff --git a/htroot/api/bookmarks/get_folders.java b/htroot/api/bookmarks/get_folders.java index 38b06cab7..fd7baec06 100644 --- a/htroot/api/bookmarks/get_folders.java +++ b/htroot/api/bookmarks/get_folders.java @@ -6,6 +6,7 @@ import net.yacy.cora.util.CommonPattern; import net.yacy.data.BookmarkHelper; import net.yacy.data.BookmarksDB; import net.yacy.data.UserDB; +import net.yacy.http.servlets.YaCyDefaultServlet; import net.yacy.search.Switchboard; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; @@ -31,8 +32,8 @@ public class get_folders { else username = "unknown"; prop.putHTML("display_user", username); - // set peer address - prop.put("display_address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP())); + // set peer address base : used in get_bookmarks.xml to render the absolute API link URL + prop.put("display_address", YaCyDefaultServlet.getContext(header, sb)); prop.put("display_peer", sb.peers.mySeed().getName()); String root = "/"; diff --git a/htroot/yacysearch_location.java b/htroot/yacysearch_location.java index febe02816..865cca097 100644 --- a/htroot/yacysearch_location.java +++ b/htroot/yacysearch_location.java @@ -27,11 +27,11 @@ import net.yacy.cora.document.feed.RSSMessage; import net.yacy.cora.federate.opensearch.SRURSSConnector; import net.yacy.cora.geo.GeoLocation; 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.util.CommonPattern; import net.yacy.document.LibraryProvider; +import net.yacy.http.servlets.YaCyDefaultServlet; import net.yacy.search.Switchboard; import net.yacy.search.SwitchboardConstants; import net.yacy.server.serverObjects; @@ -44,6 +44,8 @@ public class yacysearch_location { final serverObjects prop = new serverObjects(); prop.put("kml", 0); + + final String peerContext = YaCyDefaultServlet.getContext(header, sb); if (header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("kml") || header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("xml") || @@ -66,14 +68,13 @@ public class yacysearch_location { final double lat = post.getDouble("lat", 0.0d); final double radius = post.getDouble("r", 0.0d); //i.e. http://localhost:8090/yacysearch_location.kml?query=berlin&maximumTime=2000&maximumRecords=100 - + int placemarkCounter = 0; if (query.length() > 0 && search_query) { final Set locations = LibraryProvider.geoLoc.find(query, true); for (final String qp: CommonPattern.SPACES.split(query)) { locations.addAll(LibraryProvider.geoLoc.find(qp, true)); } - String ip = sb.peers.mySeed().getIP(); for (final GeoLocation location: locations) { // write for all locations a point to this message double lo = location.lon(); @@ -86,7 +87,7 @@ public class yacysearch_location { prop.put("kml_placemark_" + placemarkCounter + "_subject", ""); prop.put("kml_placemark_" + placemarkCounter + "_description", ""); prop.put("kml_placemark_" + placemarkCounter + "_date", ""); - prop.putXML("kml_placemark_" + placemarkCounter + "_url", "http://" + sb.peers.mySeed().getPublicAddress(ip) + "/yacysearch.html?query=" + location.getName()); + prop.putXML("kml_placemark_" + placemarkCounter + "_url", peerContext + "/yacysearch.html?query=" + location.getName()); prop.put("kml_placemark_" + placemarkCounter + "_pointname", location.getName()); prop.put("kml_placemark_" + placemarkCounter + "_lon", lo); prop.put("kml_placemark_" + placemarkCounter + "_lat", la); @@ -128,15 +129,13 @@ public class yacysearch_location { if (post == null) return prop; String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, ""); if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", ""); - String hostName = header.get("Host", Domains.LOCALHOST); - if (hostName.indexOf(':',0) == -1) hostName += ":" + env.getLocalPort(); final String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim(); // SRU compliance final boolean global = post.get("kml_resource", "local").equals("global"); prop.put("kml_date822", HeaderFramework.formatRFC1123(new Date())); prop.put("kml_promoteSearchPageGreeting", promoteSearchPageGreeting); - prop.put("kml_rssYacyImageURL", "http://" + hostName + "/env/grafics/yacy.png"); - prop.put("kml_searchBaseURL", "http://" + hostName + "/yacysearch_location.rss"); + prop.put("kml_rssYacyImageURL", peerContext + "/env/grafics/yacy.png"); + prop.put("kml_searchBaseURL", peerContext + "/yacysearch_location.rss"); prop.putXML("kml_rss_query", originalquerystring); prop.put("kml_rss_queryenc", originalquerystring.replace(' ', '+')); prop.put("kml_resource", global ? "global" : "local");