Merge branch 'jetty-7' into release-7

This commit is contained in:
Jesse McConnell 2013-05-20 06:47:08 -05:00
commit 4cba93e8d4
5 changed files with 91 additions and 53 deletions

View File

@ -37,6 +37,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Logger;
@ -520,8 +521,7 @@ public class HashSessionManager extends AbstractSessionManager
}
finally
{
if (in != null)
try {in.close();} catch (Exception x) {__log.ignore(x);}
if (in != null) IO.close(in);
if (error != null)
{
@ -568,30 +568,41 @@ public class HashSessionManager extends AbstractSessionManager
* defaultReadObject
*/
DataInputStream in = new DataInputStream(is);
String clusterId = in.readUTF();
in.readUTF(); // nodeId
long created = in.readLong();
long accessed = in.readLong();
int requests = in.readInt();
if (session == null)
session = (HashedSession)newSession(created, accessed, clusterId);
session.setRequests(requests);
int size = in.readInt();
if (size>0)
try
{
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(in);
for (int i=0; i<size;i++)
String clusterId = in.readUTF();
in.readUTF(); // nodeId
long created = in.readLong();
long accessed = in.readLong();
int requests = in.readInt();
if (session == null)
session = (HashedSession)newSession(created, accessed, clusterId);
session.setRequests(requests);
int size = in.readInt();
if (size>0)
{
String key = ois.readUTF();
Object value = ois.readObject();
session.setAttribute(key,value);
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(in);
try
{
for (int i=0; i<size;i++)
{
String key = ois.readUTF();
Object value = ois.readObject();
session.setAttribute(key,value);
}
}
finally
{
IO.close(ois);
}
}
ois.close();
return session;
}
finally
{
IO.close(in);
}
else
in.close();
return session;
}

View File

@ -121,6 +121,7 @@ public class HashedSession extends AbstractSession
fos = new FileOutputStream(file);
willPassivate();
save(fos);
IO.close(fos);
if (reactivate)
didActivate();
else
@ -129,14 +130,9 @@ public class HashedSession extends AbstractSession
catch (Exception e)
{
saveFailed(); // We won't try again for this session
if (fos != null)
{
// Must not leave the file open if the saving failed
IO.close(fos);
// No point keeping the file if we didn't save the whole session
file.delete();
throw e;
}
if (fos != null) IO.close(fos);
if (file != null) file.delete(); // No point keeping the file if we didn't save the whole session
throw e;
}
}
}
@ -192,9 +188,10 @@ public class HashedSession extends AbstractSession
fis = new FileInputStream(file);
_idled = false;
_hashSessionManager.restoreSession(fis, this);
didActivate();
IO.close(fis);
didActivate();
// If we are doing period saves, then there is no point deleting at this point
if (_hashSessionManager._savePeriodMs == 0)
file.delete();
@ -202,7 +199,7 @@ public class HashedSession extends AbstractSession
catch (Exception e)
{
LOG.warn("Problem de-idling session " + super.getId(), e);
IO.close(fis);
if (fis != null) IO.close(fis);//Must ensure closed before invalidate
invalidate();
}
}

View File

@ -516,24 +516,18 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
*/
@Override
public void doStart()
{
try
{
initializeDatabase();
prepareTables();
cleanExpiredSessions();
super.doStart();
if (LOG.isDebugEnabled())
LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec");
_timer=new Timer("JDBCSessionScavenger", true);
setScavengeInterval(getScavengeInterval());
}
catch (Exception e)
{
LOG.warn("Problem initialising JettySessionIds table", e);
}
throws Exception
{
initializeDatabase();
prepareTables();
cleanExpiredSessions();
super.doStart();
if (LOG.isDebugEnabled())
LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec");
_timer=new Timer("JDBCSessionScavenger", true);
setScavengeInterval(getScavengeInterval());
}
/**
* Stop the scavenger.
*/

View File

@ -125,8 +125,13 @@ public class MultiPartFilter implements Filter
// TODO - handle encodings
String contentTypeBoundary = "";
if (content_type.indexOf("boundary=") >= 0)
contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(content_type.indexOf("boundary="))).trim());
int bstart = content_type.indexOf("boundary=");
if (bstart >= 0)
{
int bend = content_type.indexOf(";", bstart);
bend = (bend < 0? content_type.length(): bend);
contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(bstart,bend)).trim());
}
String boundary="--"+contentTypeBoundary;

View File

@ -164,7 +164,38 @@ public class MultipartFilterTest
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
@Test
public void testContentTypeWithCharset() throws Exception
{
// generated and parsed test
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
// test GET
request.setMethod("POST");
request.setVersion("HTTP/1.0");
request.setHeader("Host","tester");
request.setURI("/context/dump");
String boundary="XyXyXy";
request.setHeader("Content-Type","multipart/form-data; boundary=\""+boundary+"\"; charset=ISO-8859-1");
String content = "--" + boundary + "\r\n"+
"Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n"+
"Content-Type: application/octet-stream\r\n\r\n"+
"How now brown cow."+
"\r\n--" + boundary + "--\r\n\r\n";
request.setContent(content);
response.parse(tester.getResponses(request.generate()));
assertTrue(response.getMethod()==null);
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
@Test
public void testEncodedPost() throws Exception