Hooray... sonews/0.5.0 final
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Remove all lines to abort the collapse operation.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.web;
21 import java.io.IOException;
22 import java.util.HashSet;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.sonews.util.StringTemplate;
28 * Servlet that shows the Peers and the Peering Rules.
29 * @author Christian Lins
32 public class SonewsPeerServlet extends AbstractSonewsServlet
35 private static final long serialVersionUID = 245345346356L;
38 public void doGet(HttpServletRequest req, HttpServletResponse resp)
43 connectToNewsserver();
44 StringTemplate tmpl = getTemplate("SonewsPeerServlet.tmpl");
46 // Read peering rules from newsserver
47 printlnToNewsserver("XDAEMON LIST PEERINGRULES");
48 String line = readlnFromNewsserver();
49 if(!line.startsWith("200 "))
51 throw new IOException("Unexpected reply: " + line);
54 // Create FEED_RULES String
55 HashSet<String> peers = new HashSet<String>();
56 StringBuilder feedRulesStr = new StringBuilder();
59 line = readlnFromNewsserver();
66 feedRulesStr.append(line);
67 feedRulesStr.append("<br/>");
69 String[] lineChunks = line.split(" ");
70 peers.add(lineChunks[1]);
74 // Create PEERS string
75 StringBuilder peersStr = new StringBuilder();
76 for(String peer : peers)
78 peersStr.append(peer);
79 peersStr.append("<br/>");
83 tmpl.set("PEERS", peersStr.toString());
84 tmpl.set("PEERING_RULES", feedRulesStr.toString());
85 tmpl.set("SERVERNAME", hello.split(" ")[2]);
86 tmpl.set("TITLE", "Peers");
88 resp.getWriter().println(tmpl.toString());
89 resp.getWriter().flush();
90 resp.setStatus(HttpServletResponse.SC_OK);
91 disconnectFromNewsserver();