forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head d2e954c054d89a425c9791067ac7998433e95a23)
to branch 'i2p.i2p.zzz.jetty9' (head adcba23cab31b88e430ee09bf45fd1b6789a1719)
This commit is contained in:
@@ -31,12 +31,12 @@ public class I2PLogger implements Logger
|
||||
{
|
||||
private final Log _log;
|
||||
|
||||
StringBuilder _buffer = new StringBuilder();
|
||||
private final StringBuilder _buffer = new StringBuilder();
|
||||
|
||||
static {
|
||||
//static {
|
||||
// So people don't wonder where the logs went
|
||||
System.out.println("INFO: Jetty " + Server.getVersion() + " logging to I2P logs using class " + Server.class.getName());
|
||||
}
|
||||
//System.out.println("INFO: Jetty " + Server.getVersion() + " logging to I2P logs using class " + Server.class.getName());
|
||||
//}
|
||||
|
||||
public I2PLogger()
|
||||
{
|
||||
@@ -115,10 +115,14 @@ public class I2PLogger implements Logger
|
||||
{
|
||||
// some of these are serious, some aren't
|
||||
// no way to get it right
|
||||
if (th != null)
|
||||
_log.logAlways(Log.WARN, msg + ": " + th);
|
||||
else
|
||||
if (th != null) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn(msg, th);
|
||||
else
|
||||
_log.logAlways(Log.WARN, msg + ": " + th);
|
||||
} else {
|
||||
_log.logAlways(Log.WARN, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void format(String msg, Object arg0, Object arg1)
|
||||
|
||||
@@ -75,6 +75,7 @@ public class I2PRequestLog extends AbstractLifeCycle implements RequestLog
|
||||
private boolean _logLatency = false;
|
||||
private boolean _logCookies = false;
|
||||
private boolean _logServer = false;
|
||||
private boolean _b64;
|
||||
|
||||
private transient OutputStream _out;
|
||||
private transient OutputStream _fileOut;
|
||||
@@ -241,6 +242,15 @@ public class I2PRequestLog extends AbstractLifeCycle implements RequestLog
|
||||
_preferProxiedForAddress = preferProxiedForAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b64 true to enable base 64 logging. False for base 32 logging. Default false.
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public void setB64(boolean b64)
|
||||
{
|
||||
_b64 = b64;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void log(Request request, Response response)
|
||||
{
|
||||
@@ -279,11 +289,15 @@ public class I2PRequestLog extends AbstractLifeCycle implements RequestLog
|
||||
}
|
||||
|
||||
if (addr == null) {
|
||||
// TODO offer B32 option
|
||||
addr = request.getHeader("X-I2P-DestHash");
|
||||
if(addr != null)
|
||||
addr += ".i2p";
|
||||
else
|
||||
if (_b64) {
|
||||
addr = request.getHeader("X-I2P-DestHash");
|
||||
if (addr != null)
|
||||
addr += ".i2p";
|
||||
} else {
|
||||
// 52chars.b32.i2p
|
||||
addr = request.getHeader("X-I2P-DestB32");
|
||||
}
|
||||
if (addr == null)
|
||||
addr = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Properties;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.app.*;
|
||||
import static net.i2p.app.ClientAppState.*;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.PortMapper;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
@@ -38,6 +39,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
/**
|
||||
* Start Jetty where the args are one or more XML files.
|
||||
* Save a reference to the Server so it can be cleanly stopped later.
|
||||
* Caller must call startup()
|
||||
*
|
||||
* This is like XmlConfiguration.main(), which is essentially what
|
||||
* org.mortbay.start.Main does.
|
||||
@@ -73,6 +75,7 @@ public class JettyStart implements ClientApp {
|
||||
/**
|
||||
* Modified from XmlConfiguration.main()
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void parseArgs(String[] args) throws Exception {
|
||||
Properties properties=new Properties();
|
||||
XmlConfiguration last=null;
|
||||
@@ -99,7 +102,7 @@ public class JettyStart implements ClientApp {
|
||||
}
|
||||
}
|
||||
|
||||
public void startup() {
|
||||
public synchronized void startup() {
|
||||
if (_state != INITIALIZED)
|
||||
return;
|
||||
if (_jettys.isEmpty()) {
|
||||
@@ -109,7 +112,7 @@ public class JettyStart implements ClientApp {
|
||||
}
|
||||
}
|
||||
|
||||
private class Starter extends Thread {
|
||||
private class Starter extends I2PAppThread {
|
||||
public Starter() {
|
||||
super("JettyStarter");
|
||||
changeState(STARTING);
|
||||
@@ -165,7 +168,7 @@ public class JettyStart implements ClientApp {
|
||||
}
|
||||
}
|
||||
|
||||
private class Stopper extends Thread {
|
||||
private class Stopper extends I2PAppThread {
|
||||
public Stopper() {
|
||||
super("JettyStopper");
|
||||
changeState(STOPPING);
|
||||
@@ -218,7 +221,8 @@ public class JettyStart implements ClientApp {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new JettyStart(null, null, args);
|
||||
JettyStart js = new JettyStart(null, null, args);
|
||||
js.startup();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -139,7 +139,7 @@ public class RequestWrapper {
|
||||
String key = e.getKey();
|
||||
if( key.toLowerCase(Locale.US).compareToIgnoreCase( "content-type") == 0 ) {
|
||||
String value = e.getValue();
|
||||
int i = value.indexOf( ";" );
|
||||
int i = value.indexOf( ';' );
|
||||
if( i != -1 )
|
||||
result = value.substring( 0, i );
|
||||
else
|
||||
|
||||
@@ -84,10 +84,10 @@ public class XSSRequestWrapper extends HttpServletRequestWrapper {
|
||||
* Parameter names starting with "nofilter_" will not be filtered.
|
||||
*/
|
||||
@Override
|
||||
public Map getParameterMap() {
|
||||
Map rv = new HashMap();
|
||||
for (Enumeration keys = getParameterNames(); keys.hasMoreElements(); ) {
|
||||
String k = (String) keys.nextElement();
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
Map<String, String[]> rv = new HashMap<String, String[]>();
|
||||
for (Enumeration<String> keys = getParameterNames(); keys.hasMoreElements(); ) {
|
||||
String k = keys.nextElement();
|
||||
String[] v = getParameterValues(k);
|
||||
if (v != null)
|
||||
rv.put(k, v);
|
||||
|
||||
@@ -219,6 +219,7 @@ public class MultiPartRequest
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Hashtable[] getMultipleParams(String name)
|
||||
{
|
||||
List<Object> parts = _partMap.getValues(name);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ByteArrayPool
|
||||
public static final int __POOL_SIZE=
|
||||
Integer.getInteger("org.mortbay.util.ByteArrayPool.pool_size",8).intValue();
|
||||
|
||||
public static final ThreadLocal __pools=new BAThreadLocal();
|
||||
public static final ThreadLocal<byte[][]> __pools = new BAThreadLocal();
|
||||
public static final AtomicInteger __slot = new AtomicInteger();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@@ -39,7 +39,7 @@ public class ByteArrayPool
|
||||
*/
|
||||
public static byte[] getByteArray(int size)
|
||||
{
|
||||
byte[][] pool = (byte[][])__pools.get();
|
||||
byte[][] pool = __pools.get();
|
||||
boolean full=true;
|
||||
for (int i=pool.length;i-->0;)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public class ByteArrayPool
|
||||
/* ------------------------------------------------------------ */
|
||||
public static byte[] getByteArrayAtLeast(int minSize)
|
||||
{
|
||||
byte[][] pool = (byte[][])__pools.get();
|
||||
byte[][] pool = __pools.get();
|
||||
for (int i=pool.length;i-->0;)
|
||||
{
|
||||
if (pool[i]!=null && pool[i].length>=minSize)
|
||||
@@ -84,7 +84,7 @@ public class ByteArrayPool
|
||||
if (b==null)
|
||||
return;
|
||||
|
||||
byte[][] pool = (byte[][])__pools.get();
|
||||
byte[][] pool = __pools.get();
|
||||
for (int i=pool.length;i-->0;)
|
||||
{
|
||||
if (pool[i]==null)
|
||||
@@ -103,9 +103,10 @@ public class ByteArrayPool
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private static final class BAThreadLocal extends ThreadLocal
|
||||
private static final class BAThreadLocal extends ThreadLocal<byte[][]>
|
||||
{
|
||||
protected Object initialValue()
|
||||
@Override
|
||||
protected byte[][] initialValue()
|
||||
{
|
||||
return new byte[__POOL_SIZE][];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user