minor cleanups and test improvements
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2603 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
703aca3449
commit
312cf416ec
|
@ -443,12 +443,10 @@ public class ContextDeployer extends AbstractLifeCycle
|
|||
return null;
|
||||
|
||||
XmlConfiguration xmlConfiguration=new XmlConfiguration(resource.getURL());
|
||||
HashMap properties = new HashMap();
|
||||
properties.put("Server", _contexts.getServer());
|
||||
xmlConfiguration.getIdMap().put("Server", _contexts.getServer());
|
||||
if (_configMgr!=null)
|
||||
properties.putAll(_configMgr.getProperties());
|
||||
xmlConfiguration.getProperties().putAll(_configMgr.getProperties());
|
||||
|
||||
xmlConfiguration.setProperties(properties);
|
||||
ContextHandler context=(ContextHandler)xmlConfiguration.configure();
|
||||
|
||||
// merge attributes
|
||||
|
|
|
@ -64,12 +64,10 @@ public class ContextProvider extends ScanningAppProvider
|
|||
if (resource.exists() && FileID.isXmlFile(file))
|
||||
{
|
||||
XmlConfiguration xmlc = new XmlConfiguration(resource.getURL());
|
||||
Map<String,String> props = new HashMap<String,String>();
|
||||
|
||||
xmlc.getIdMap().put("Server",getDeploymentManager().getServer());
|
||||
if (getConfigurationManager() != null)
|
||||
props.putAll(getConfigurationManager().getProperties());
|
||||
xmlc.setProperties(props);
|
||||
xmlc.getProperties().putAll(getConfigurationManager().getProperties());
|
||||
return (ContextHandler)xmlc.configure();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BlockingChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
public static void init() throws Exception
|
||||
{
|
||||
BlockingChannelConnector connector = new BlockingChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
|
||||
|
||||
startServer(connector);
|
||||
}
|
||||
|
|
|
@ -22,14 +22,20 @@ import java.io.OutputStream;
|
|||
import java.net.Socket;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
||||
{
|
||||
protected static final int MAX_IDLE_TIME=250;
|
||||
|
||||
static
|
||||
{
|
||||
System.setProperty("org.eclipse.jetty.io.nio.IDLE_TICK","100");
|
||||
|
@ -37,7 +43,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
|
||||
|
||||
@Test
|
||||
public void testSelectConnectorMaxIdleWithRequest10() throws Exception
|
||||
public void testMaxIdleWithRequest10() throws Exception
|
||||
{
|
||||
configureServer(new HelloWorldHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
|
@ -68,7 +74,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelectConnectorMaxIdleWithRequest11() throws Exception
|
||||
public void testMaxIdleWithRequest11() throws Exception
|
||||
{
|
||||
configureServer(new EchoHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
|
@ -102,7 +108,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
|
||||
|
||||
@Test
|
||||
public void testSelectConnectorMaxIdleNoRequest() throws Exception
|
||||
public void testMaxIdleNoRequest() throws Exception
|
||||
{
|
||||
configureServer(new EchoHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
|
@ -127,7 +133,130 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
}
|
||||
Assert.assertTrue(System.currentTimeMillis()-start<5000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMaxIdleWithSlowRequest() throws Exception
|
||||
{
|
||||
configureServer(new EchoHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
assertFalse(client.isClosed());
|
||||
|
||||
OutputStream os=client.getOutputStream();
|
||||
InputStream is=client.getInputStream();
|
||||
|
||||
String content="Wibble\r\n";
|
||||
byte[] contentB=content.getBytes("utf-8");
|
||||
os.write((
|
||||
"GET / HTTP/1.0\r\n"+
|
||||
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
|
||||
"connection: keep-alive\r\n"+
|
||||
"Content-Length: "+(contentB.length*20)+"\r\n"+
|
||||
"Content-Type: text/plain\r\n"+
|
||||
"Connection: close\r\n"+
|
||||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
for (int i =0;i<20;i++)
|
||||
{
|
||||
Thread.sleep(50);
|
||||
os.write(contentB);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
String in = IO.toString(is);
|
||||
int offset=0;
|
||||
for (int i =0;i<20;i++)
|
||||
{
|
||||
offset=in.indexOf("Wibble",offset+1);
|
||||
Assert.assertTrue(""+i,offset>0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxIdleWithSlowResponse() throws Exception
|
||||
{
|
||||
configureServer(new SlowResponseHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
assertFalse(client.isClosed());
|
||||
|
||||
OutputStream os=client.getOutputStream();
|
||||
InputStream is=client.getInputStream();
|
||||
|
||||
os.write((
|
||||
"GET / HTTP/1.0\r\n"+
|
||||
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
|
||||
"connection: keep-alive\r\n"+
|
||||
"Connection: close\r\n"+
|
||||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
String in = IO.toString(is);
|
||||
int offset=0;
|
||||
for (int i =0;i<20;i++)
|
||||
{
|
||||
offset=in.indexOf("Hello World",offset+1);
|
||||
Assert.assertTrue(""+i,offset>0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxIdleWithWait() throws Exception
|
||||
{
|
||||
configureServer(new WaitHandler());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
assertFalse(client.isClosed());
|
||||
|
||||
OutputStream os=client.getOutputStream();
|
||||
InputStream is=client.getInputStream();
|
||||
|
||||
os.write((
|
||||
"GET / HTTP/1.0\r\n"+
|
||||
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
|
||||
"connection: keep-alive\r\n"+
|
||||
"Connection: close\r\n"+
|
||||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
String in = IO.toString(is);
|
||||
int offset=in.indexOf("Hello World");
|
||||
Assert.assertTrue(offset>0);
|
||||
}
|
||||
|
||||
protected static class SlowResponseHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
||||
for (int i=0;i<20;i++)
|
||||
{
|
||||
out.write("Hello World\r\n".getBytes());
|
||||
out.flush();
|
||||
try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected static class WaitHandler extends AbstractHandler
|
||||
{
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
OutputStream out = response.getOutputStream();
|
||||
try{Thread.sleep(2000);}catch(Exception e){e.printStackTrace();}
|
||||
out.write("Hello World\r\n".getBytes());
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
public static void init() throws Exception
|
||||
{
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
|
||||
startServer(connector);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SocketTimeoutTest extends ConnectorTimeoutTest
|
|||
public static void init() throws Exception
|
||||
{
|
||||
SocketConnector connector = new SocketConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
|
||||
startServer(connector);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
public static void init() throws Exception
|
||||
{
|
||||
SslSelectChannelConnector connector = new SslSelectChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
|
|
|
@ -36,10 +36,8 @@ public class SslSocketTimeoutTest extends ConnectorTimeoutTest
|
|||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
|
||||
|
||||
SslSocketConnector connector = new SslSocketConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
|
@ -55,8 +53,7 @@ public class SslSocketTimeoutTest extends ConnectorTimeoutTest
|
|||
trustManagerFactory.init(keystore);
|
||||
_sslContext = SSLContext.getInstance("SSL");
|
||||
_sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
|||
if(Log.isDebugEnabled())
|
||||
Log.debug("Configure: "+jetty);
|
||||
XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL());
|
||||
setupXmlConfiguration(jetty_config, web_inf);
|
||||
setupXmlConfiguration(context,jetty_config, web_inf);
|
||||
jetty_config.configure(context);
|
||||
}
|
||||
finally
|
||||
|
@ -89,6 +89,16 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures some well-known properties before the XmlConfiguration reads
|
||||
* the configuration.
|
||||
* @param jetty_config The configuration object.
|
||||
*/
|
||||
private void setupXmlConfiguration(WebAppContext context, XmlConfiguration jetty_config, Resource web_inf)
|
||||
{
|
||||
setupXmlConfiguration(jetty_config,web_inf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures some well-known properties before the XmlConfiguration reads
|
||||
|
@ -98,13 +108,6 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
|||
private void setupXmlConfiguration(XmlConfiguration jetty_config, Resource web_inf)
|
||||
{
|
||||
Map<String,String> props = jetty_config.getProperties();
|
||||
if (props == null)
|
||||
{
|
||||
props = new HashMap<String, String>();
|
||||
jetty_config.setProperties(props);
|
||||
}
|
||||
|
||||
// TODO - should this be an id rather than a property?
|
||||
props.put(PROPERTY_THIS_WEB_INF_URL, String.valueOf(web_inf.getURL()));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<Configure class="org.eclipse.jetty.xml.TestConfiguration">
|
||||
|
||||
<Set name="Test">SetValue</Set>
|
||||
<Set name="Test" type="int">2</Set>
|
||||
<Set name="Test" type="int"><Property name="does.not.exist" default="2"/></Set>
|
||||
|
||||
<Set name="PropertyTest"><Property name="anIntegerNoActualPropDefined" default="18080"/></Set>
|
||||
|
||||
|
|
Loading…
Reference in New Issue