Disabled console webapp.

This commit is contained in:
dev
2011-06-17 11:48:46 +00:00
parent 435a667acb
commit 2ffc33eda0
15 changed files with 121 additions and 306 deletions

View File

@ -16,7 +16,7 @@
<copy file="LICENSE.txt" todir="plugin/" overwrite="true" />
<copy file="README.txt" todir="plugin/" overwrite="true" />
<copy file="scripts/clients.config" todir="plugin/" overwrite="true" />
<copy file="scripts/webapps.config" todir="plugin/console/" overwrite="true" />
<!--<copy file="scripts/webapps.config" todir="plugin/console/" overwrite="true" /> Console WebApp disabled-->
<copy file="scripts/plugin.config" todir="plugin/" overwrite="true" />
<exec executable="echo" osfamily="unix" failonerror="true" output="plugin/plugin.config" append="true">
<arg value="update-only=true" />
@ -30,12 +30,12 @@
<arg value="plugin/lib/I2PControl.jar.pack" />
<arg value="src/build/I2PControl.jar" />
</exec>
<exec executable="pack200" failonerror="true">
<arg value="--no-gzip"/>
<arg value="--effort=9"/>
<!--<exec executable="pack200" failonerror="true">
<arg value="-no-gzip"/> //Add a dash
<arg value="-effort=9"/> //Add a dash
<arg value="plugin/console/webapps/I2PControl.war.pack" />
<arg value="src/build/I2PControl.war.jar" />
</exec>
</exec> -->
<exec executable="scripts/makeplugin.sh" failonerror="true" >
<arg value="plugin" />
</exec>

View File

@ -1,7 +1,7 @@
name=I2PControl
signer=dev@robertfoss.se
consoleLinkName=I2PControl
consoleLinkURL=/I2PControl/
consoleLinkURL=http://localhost:7656
description=Remote Control Service
author=hottuna
websiteURL=http://XR1kDnLKSUO9lhZGmB9kq8a386yDXkgvqc~nCkfUMESL~XIUIYzXO6xkmbHHS6VANkAtapVPSb1x6iwA7S7BL1E9lnUwgBsK3Wzh9YpLVpYq2thFEWAI-mkUgrhcnSTn5VoetjR~Cv4sI7geDL4MsMEnmno5KKTwVJY6di3dJkzwKx4epjfs3KiCqizTqfLykc8KDitjQ~9-PvBUV9q79~reEsJ32AGSwGflV8a8S8OSv0Jw7V4AvljMLdIYD-FwVUCFHUHzqUcDSyEklmOQoYFxDc2fytx5v04H8YZH4Zp29tJq-O97lCx4TBZxyRaQnWcoE74D0ChTv8Y1~kRYwYloWbcya--XgvLgWbnGbOQZgFUpFc1OGhJFukgVHqTrj~S8DaC4Yv2~P7dcjItYZ12JBoq1wXbQN-ZP~BrOW9FJd7qP~AH4vT1MlstkOTxbIvhDVVY-fPvI7Wf~4IR5uwfeSO65luBpoMqlsNML4mTySv7TGkUVB51aVJkziEtDAAAA/

View File

@ -42,7 +42,8 @@
</target>
<target name="precompilejsp" depends="compile" >
<mkdir dir="build" />
<!-- disable console webapp
<mkdir dir="build" />
<mkdir dir="build/war/WEB-INF/classes" />
<path id="jspcp">
<path refid="cp" />
@ -73,16 +74,17 @@
<copy file="jsp/WEB-INF/web.xml" tofile="build/web.xml" />
<loadfile property="jspc.web.fragment" srcfile="build/web-fragment.xml" />
<replace file="build/web.xml">
<replacefilter token="&lt;!-- precompiled servlets --&gt;" value="${jspc.web.fragment}" />
<replacefilter token="&lt;!- precompiled servlets -&gt;" value="${jspc.web.fragment}" /> //Add double dash
</replace>
-->
</target>
<target name="war" depends="precompilejsp">
<copy file="jsp/index.html" todir="build/war" />
<target name="war" depends="precompilejsp">
<!-- Disable console webapp
<war destfile="build/I2PControl.war.jar" webxml="build/web.xml">
<fileset dir="build/war" />
</war>
-->
</target>
<target name="clean">

View File

@ -1,134 +0,0 @@
package net.i2p.i2pcontrol;
import com.thetransactioncompany.jsonrpc2.*;
import com.thetransactioncompany.jsonrpc2.server.*;
import java.text.*;
import java.util.*;
import javax.servlet.http.*;
/**
* Demonstration of the JSON-RPC 2.0 Server framework usage. The request
* handlers are implemented as static nested classes for convenience, but in
* real life applications may be defined as regular classes within their old
* source files.
*
* @author Vladimir Dzhuvinov
* @version 2011-03-05
*/
public class Example {
// Implements a handler for an "echo" JSON-RPC method
public static class EchoHandler implements RequestHandler {
// Reports the method names of the handled requests
public String[] handledRequests() {
return new String[]{"echo"};
}
// Processes the requests
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals("echo")) {
// Echo first parameter
List params = (List)req.getParams();
Object input = params.get(0);
return new JSONRPC2Response(input, req.getID());
}
else {
// Method name not supported
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}
}
}
// Implements a handler for "getDate" and "getTime" JSON-RPC methods
// that return the current date and time
public static class DateTimeHandler implements RequestHandler {
// Reports the method names of the handled requests
public String[] handledRequests() {
return new String[]{"getDate", "getTime"};
}
// Processes the requests
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals("getDate")) {
DateFormat df = DateFormat.getDateInstance();
String date = df.format(new Date());
return new JSONRPC2Response(date, req.getID());
}
else if (req.getMethod().equals("getTime")) {
DateFormat df = DateFormat.getTimeInstance();
String time = df.format(new Date());
return new JSONRPC2Response(time, req.getID());
}
else {
// Method name not supported
return new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID());
}
}
}
public static void main(String[] args) {
// Create a new JSON-RPC 2.0 request dispatcher
Dispatcher dispatcher = new Dispatcher();
// Register the "echo", "getDate" and "getTime" handlers with it
dispatcher.register(new EchoHandler());
dispatcher.register(new DateTimeHandler());
// Simulate an "echo" JSON-RPC 2.0 request
List echoParam = new LinkedList();
echoParam.add("Hello world!");
JSONRPC2Request req = new JSONRPC2Request("echo", echoParam, "req-id-01");
System.out.println("Request: \n" + req);
JSONRPC2Response resp = dispatcher.dispatch(req, null);
System.out.println("Response: \n" + resp);
// Simulate a "getDate" JSON-RPC 2.0 request
req = new JSONRPC2Request("getDate", "req-id-02");
System.out.println("Request: \n" + req);
resp = dispatcher.dispatch(req, null);
System.out.println("Response: \n" + resp);
// Simulate a "getTime" JSON-RPC 2.0 request
req = new JSONRPC2Request("getTime", "req-id-03");
System.out.println("Request: \n" + req);
resp = dispatcher.dispatch(req, null);
System.out.println("Response: \n" + resp);
}
}

View File

@ -0,0 +1,40 @@
package net.i2p.i2pcontrol;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.i2p.I2PAppContext;
import net.i2p.util.Log;
public class HistoryServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -4018705582081424641L;
private static I2PControlManager _manager;
private static Log _log;
@Override
public void init(){
_log = I2PAppContext.getGlobalContext().logManager().getLog(HistoryServlet.class);
_manager = I2PControlManager.getInstance();
}
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
httpServletResponse.setContentType("text/html");
PrintWriter out = httpServletResponse.getWriter();
out.println("<html>\n<body>");
out.println(_manager.getHistory());
out.println("</body>\n</html>");
out.close();
}
}

View File

@ -16,6 +16,7 @@ package net.i2p.i2pcontrol;
*
*/
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
@ -68,17 +69,17 @@ public class I2PControlController{
private static void start(String args[]) {
/*File pluginDir = new File(args[1]);
if (!pluginDir.exists())
throw new IllegalArgumentException("Plugin directory " + pluginDir.getAbsolutePath() + " does not exist");
*/
//File pluginDir = new File(args[1]);
//if (!pluginDir.exists())
// throw new IllegalArgumentException("Plugin directory " + pluginDir.getAbsolutePath() + " does not exist");
_server = new Server();
try {
_server.addListener(Settings.getListenIP() +":" +Settings.getListenPort());
ServletHttpContext context = (ServletHttpContext) _server.getContext("/");
context.addServlet("/", "net.i2p.i2pcontrol.JSONRPCServlet");
//context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.addServlet("/", "net.i2p.i2pcontrol.SettingsServlet");
context.addServlet("/jsonrpc", "net.i2p.i2pcontrol.JSONRPCServlet");
context.addServlet("/history", "net.i2p.i2pcontrol.HistoryServlet");
_server.start();
} catch (IOException e) {
_log.error("Unable to add listener " + Settings.getListenIP()+":"+Settings.getListenPort() + " - " + e.getMessage());

View File

@ -22,82 +22,23 @@ import java.lang.reflect.*;
* There can be only one - ie. even if the class is loaded in several different classloaders,
* there will be only one instance of the object.
*/
public class I2PControlManager implements ManagerInterface{
public class I2PControlManager{
private static StringBuilder _history;
/**
* This is effectively an instance of this class (although actually it may be instead a
* java.lang.reflect.Proxy wrapping an instance from the original classloader).
*/
public static ManagerInterface instance = null;
/**
* Retrieve an instance of AbsoluteSingleton from the original classloader. This is a true
* Singleton, in that there will only be one instance of this object in the virtual machine,
* even though there may be several copies of its class file loaded in different classloaders.
*/
public synchronized static ManagerInterface getInstance() {
ClassLoader myClassLoader = I2PControlManager.class.getClassLoader();
if (instance==null) {
// The root classloader is sun.misc.Launcher package. If we are not in a sun package,
// we need to get hold of the instance of ourself from the class in the root classloader.
if (! myClassLoader.toString().startsWith("sun.")) {
try {
// So we find our parent classloader
ClassLoader parentClassLoader = I2PControlManager.class.getClassLoader().getParent();
// And get the other version of our current class
Class otherClassInstance = parentClassLoader.loadClass(I2PControlManager.class.getName());
// And call its getInstance method - this gives the correct instance of ourself
Method getInstanceMethod = otherClassInstance.getDeclaredMethod("getInstance", new Class[] { });
Object otherAbsoluteSingleton = getInstanceMethod.invoke(null, new Object[] { } );
// But, we can't cast it to our own interface directly because classes loaded from
// different classloaders implement different versions of an interface.
// So instead, we use java.lang.reflect.Proxy to wrap it in an object that *does*
// support our interface, and the proxy will use reflection to pass through all calls
// to the object.
instance = (ManagerInterface) Proxy.newProxyInstance(myClassLoader,
new Class[] { ManagerInterface.class },
new PassThroughProxyHandler(otherAbsoluteSingleton));
// And catch the usual tedious set of reflection exceptions
// We're cheating here and just catching everything - don't do this in real code
} catch (Exception e) {
e.printStackTrace();
}
// We're in the root classloader, so the instance we have here is the correct one
} else {
public static I2PControlManager instance = null;
public synchronized static I2PControlManager getInstance() {
if (instance == null) {
instance = new I2PControlManager();
}
}
return instance;
}
private I2PControlManager() {
_history = new StringBuilder();
}
private String value = "";
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#getValue()
*/
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingletonInterface#getValue()
*/
public String getValue() { return value; }
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#setValue(java.lang.String)
*/
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingletonInterface#setValue(java.lang.String)
*/
public void setValue(String value) {
this.value = value;
}
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#prependHistory(java.lang.String)
*/
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingletonInterface#prependHistory(java.lang.String)
*/
@ -105,9 +46,6 @@ public class I2PControlManager implements ManagerInterface{
_history.insert(0,str + "<br>\n");
}
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#appendHistory(java.lang.String)
*/
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingletonInterface#appendHistory(java.lang.String)
*/
@ -116,9 +54,6 @@ public class I2PControlManager implements ManagerInterface{
}
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#getHistory()
*/
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingletonInterface#getHistory()
*/

View File

@ -43,14 +43,12 @@ import com.thetransactioncompany.jsonrpc2.server.*;
* Provide an JSON-RPC 2.0 API for remote controlling of I2P
*/
public class JSONRPCServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = -45075606818515212L;
private static final int BUFFER_LENGTH = 2048;
private static Dispatcher disp;
private static char[] readBuffer;
private static ManagerInterface _manager;
private static I2PControlManager _manager;
private static Log _log;
@ -58,20 +56,23 @@ public class JSONRPCServlet extends HttpServlet{
public void init(){
_log = I2PAppContext.getGlobalContext().logManager().getLog(JSONRPCServlet.class);
readBuffer = new char[BUFFER_LENGTH];
_manager = (ManagerInterface) I2PControlManager.getInstance();
_manager = I2PControlManager.getInstance();
disp = new Dispatcher();
disp.register(new EchoHandler());
disp.register(new StatHandler());
}
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
httpServletResponse.setContentType("text/html");
PrintWriter out = httpServletResponse.getWriter();
out.println("Nothing to see here");
out.close();
}
@Override
protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
String req = getRequest(httpServletRequest.getInputStream());

View File

@ -1,30 +0,0 @@
package net.i2p.i2pcontrol;
public interface ManagerInterface {
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#getValue()
*/
public abstract String getValue();
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#setValue(java.lang.String)
*/
public abstract void setValue(String value);
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#prependHistory(java.lang.String)
*/
public abstract void prependHistory(String str);
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#appendHistory(java.lang.String)
*/
public abstract void appendHistory(String str);
/* (non-Javadoc)
* @see net.i2p.i2pcontrol.SingleTonInterface#getHistory()
*/
public abstract String getHistory();
}

View File

@ -1,24 +0,0 @@
package net.i2p.i2pcontrol;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
* An invocation handler that passes on any calls made to it directly to its delegate.
* This is useful to handle identical classes loaded in different classloaders - the
* VM treats them as different classes, but they have identical signatures.
*
* Note this is using class.getMethod, which will only work on public methods.
*/
class PassThroughProxyHandler implements InvocationHandler {
private final Object delegate;
public PassThroughProxyHandler(Object delegate) {
this.delegate = delegate;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Method delegateMethod = delegate.getClass().getMethod(method.getName(), method.getParameterTypes());
return delegateMethod.invoke(delegate, args);
}
}

View File

@ -23,7 +23,7 @@ public class Settings {
public static int getListenPort() {
// TODO Auto-generated method stub
return 7658;
return 7656;
}
public static String getListenIP() {

View File

@ -0,0 +1,42 @@
package net.i2p.i2pcontrol;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.i2p.I2PAppContext;
import net.i2p.i2pcontrol.JSONRPCServlet.EchoHandler;
import net.i2p.i2pcontrol.JSONRPCServlet.StatHandler;
import net.i2p.util.Log;
import com.thetransactioncompany.jsonrpc2.server.Dispatcher;
public class SettingsServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -4018705582081424641L;
private static I2PControlManager _manager;
private static Log _log;
@Override
public void init(){
_log = I2PAppContext.getGlobalContext().logManager().getLog(SettingsServlet.class);
_manager = I2PControlManager.getInstance();
}
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
httpServletResponse.setContentType("text/html");
PrintWriter out = httpServletResponse.getWriter();
out.println("Settings be here");
out.close();
}
}

View File

@ -3,8 +3,8 @@
<display-name>I2PControl</display-name>
<welcome-file-list>
<!--<welcome-file>index.html</welcome-file>-->
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<welcome-file>index_jsp</welcome-file>
</welcome-file-list>-->
<servlet>
<servlet-name>index</servlet-name>

View File

@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Unicode Snowman Plugin for I2P</title>
<!--[if IE]>
<style type="text/css">
div {
font-family: Arial Unicode MS;
}
</style>
<![endif]-->
</head><body>
<div id="snowman" style="text-align: center; font-size: 4000%; color: #060; background: #cff; ">
</div>
</p><p>
Plugin test brought to you by zzz and the snowman
<a href="http://www.fileformat.info/info/unicode/char/2603/browsertest.htm">U+2603</a>
</p>
</body></html>

View File

@ -10,8 +10,10 @@ I2PControl
</h2>
<table cellspacing="8">
<tr><td><h3>History:</h3><td align="right"><%
ManagerInterface _manager = I2PControlManager.getInstance();
out.print( _manager.getHistory() );
out.print("1ne");
out.print("2wo");
out.print("3hree");
%>
</table>
</body>
</html>