Merge branch 'master' into jetty-8

This commit is contained in:
Jesse McConnell 2012-02-22 14:42:39 -06:00
commit 0731cbe64d
3 changed files with 72 additions and 43 deletions

View File

@ -18,6 +18,8 @@ import java.io.InputStream;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
/* ------------------------------------------------------------ */
@ -41,6 +43,8 @@ public interface HttpContent
/* ------------------------------------------------------------ */
public class ResourceAsHttpContent implements HttpContent
{
private static final Logger LOG = Log.getLogger(ResourceAsHttpContent.class);
final Resource _resource;
final Buffer _mimeType;
final int _maxBuffer;
@ -80,18 +84,34 @@ public interface HttpContent
/* ------------------------------------------------------------ */
public Buffer getIndirectBuffer()
{
InputStream inputStream = null;
try
{
if (_resource.length()<=0 || _maxBuffer<_resource.length())
if (_resource.length() <= 0 || _maxBuffer < _resource.length())
return null;
ByteArrayBuffer buffer = new ByteArrayBuffer((int)_resource.length());
buffer.readFrom(_resource.getInputStream(),(int)_resource.length());
inputStream = _resource.getInputStream();
buffer.readFrom(inputStream,(int)_resource.length());
return buffer;
}
catch(IOException e)
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
if (inputStream != null)
{
try
{
inputStream.close();
}
catch (IOException e)
{
LOG.warn("Couldn't close inputStream. Possible file handle leak",e);
}
}
}
}
/* ------------------------------------------------------------ */

View File

@ -55,25 +55,24 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
*
* Here is a typical jetty.xml configuration would be: <pre>
*
* &lt;Set name="handler"&gt;
* &lt;New id="Handlers" class="org.eclipse.jetty.rewrite.handler.RewriteHandler"&gt;
* &lt;New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler"&gt;
* &lt;Set name="rules"&gt;
* &lt;Array type="org.eclipse.jetty.rewrite.handler.Rule"&gt;
*
*
* &lt;Item&gt;
* &lt;New id="rewrite" class="org.eclipse.jetty.rewrite.handler.RewritePatternRule"&gt;
* &lt;Set name="pattern"&gt;/*&lt;/Set&gt;
* &lt;Set name="replacement"&gt;/test&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="rewrite" class="org.eclipse.jetty.rewrite.handler.ProxyRule"&gt;
* &lt;Set name="pattern"&gt;/*&lt;/Set&gt;
* &lt;Set name="proxyTo"&gt;http://webtide.com:8080&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="response" class="org.eclipse.jetty.rewrite.handler.ResponsePatternRule"&gt;
* &lt;Set name="pattern"&gt;/session/&lt;/Set&gt;
@ -81,7 +80,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;Set name="reason"&gt;Setting error code 400&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule"&gt;
* &lt;Set name="pattern"&gt;*.jsp&lt;/Set&gt;
@ -89,7 +88,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;Set name="value"&gt;dexter webserver&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule"&gt;
* &lt;Set name="pattern"&gt;*.jsp&lt;/Set&gt;
@ -97,21 +96,21 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;Set name="value"&gt;driven header purpose&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="redirect" class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule"&gt;
* &lt;Set name="pattern"&gt;/test/dispatch&lt;/Set&gt;
* &lt;Set name="location"&gt;http://jetty.eclipse.org&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="regexRewrite" class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule"&gt;
* &lt;Set name="regex"&gt;/test-jaas/$&lt;/Set&gt;
* &lt;Set name="replacement"&gt;/demo&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="forwardedHttps" class="org.eclipse.jetty.rewrite.handler.ForwardedSchemeHeaderRule"&gt;
* &lt;Set name="header"&gt;X-Forwarded-Scheme&lt;/Set&gt;
@ -119,10 +118,10 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;Set name="scheme"&gt;https&lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Item&gt;
*
*
* &lt;Item&gt;
* &lt;New id="virtualHost" class="org.eclipse.jetty.rewrite.handler.VirtualHostRuleContainer"&gt;
*
*
* &lt;Set name="virtualHosts"&gt;
* &lt;Array type="java.lang.String"&gt;
* &lt;Item&gt;eclipse.com&lt;/Item&gt;
@ -131,7 +130,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;Item&gt;www.eclipse.org&lt;/Item&gt;
* &lt;/Array&gt;
* &lt;/Set&gt;
*
*
* &lt;Call name="addRule"&gt;
* &lt;Arg&gt;
* &lt;New class="org.eclipse.jetty.rewrite.handler.CookiePatternRule"&gt;
@ -141,33 +140,34 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
* &lt;/New&gt;
* &lt;/Arg&gt;
* &lt;/Call&gt;
*
*
* &lt;/New&gt;
* &lt;/ Item&gt;
*
* &lt;/Item&gt;
*
* &lt;/Array&gt;
* &lt;/Set&gt;
*
* &lt;Set name="handler"&gt;
* &lt;New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"&gt;
* &lt;Set name="handlers"&gt;
* &lt;Array type="org.eclipse.jetty.server.Handler"&gt;
* &lt;Item&gt;
* &lt;New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/&gt;
* &lt;/Item&gt;
* &lt;Item&gt;
* &lt;New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/&gt;
* &lt;/Item&gt;
* &lt;Item&gt;
* &lt;New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/&gt;
* &lt;/Item&gt;
* &lt;/Array&gt;
* &lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Set&gt;
*
* &lt;/New&gt;
* &lt;/Set&gt;
*
* &lt;Set name="handler"&gt;
* &lt;New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"&gt;
* &lt;Set name="handlers"&gt;
* &lt;Array type="org.eclipse.jetty.server.Handler"&gt;
* &lt;Item&gt;
* &lt;Ref id="RewriteHandler"/&gt;
* &lt;/Item&gt;
* &lt;Item&gt;
* &lt;New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/&gt;
* &lt;/Item&gt;
* &lt;Item&gt;
* &lt;New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/&gt;
* &lt;/Item&gt;
* &lt;Item&gt;
* &lt;New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/&gt;
* &lt;/Item&gt;
* &lt;/Array&gt;
* &lt;/Set&gt;
* &lt;/New&gt;
* &lt;/Set&gt;
* </pre>
*
*/

View File

@ -575,6 +575,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
* @return Returns the Override Descriptor.
* @deprecated use {@link #getOverrideDescriptors()}
*/
@Deprecated
public String getOverrideDescriptor()
{
if (_overrideDescriptors.size()!=1)
@ -686,20 +687,26 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
private void loadServerClasses()
{
if (_serverClasses != null)
{
return;
}
//look for a Server attribute with the list of Server classes
//to apply to every web application. If not present, use our defaults.
// look for a Server attribute with the list of Server classes
// to apply to every web application. If not present, use our defaults.
Server server = getServer();
if (server != null)
{
Object serverClasses = server.getAttribute(SERVER_SRV_CLASSES);
if (serverClasses != null || serverClasses instanceof String[])
if (serverClasses != null && serverClasses instanceof String[])
{
_serverClasses = new ClasspathPattern((String[])serverClasses);
}
}
if (_serverClasses == null)
{
_serverClasses = new ClasspathPattern(__dftServerClasses);
}
}
/* ------------------------------------------------------------ */
@ -873,6 +880,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
* @param overrideDescriptor The overrideDescritpor to set.
* @deprecated use {@link #setOverrideDescriptors(List)}
*/
@Deprecated
public void setOverrideDescriptor(String overrideDescriptor)
{
_overrideDescriptors.clear();
@ -960,7 +968,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
@Override
public void addEventListener(EventListener listener)
{
setEventListeners((EventListener[])LazyList.addToArray(getEventListeners(), listener, EventListener.class));
setEventListeners(LazyList.addToArray(getEventListeners(), listener, EventListener.class));
}
@ -1217,6 +1225,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
public class Context extends ServletContextHandler.Context
{
/* ------------------------------------------------------------ */
@Override
public URL getResource(String path) throws MalformedURLException
{
Resource resource=WebAppContext.this.getResource(path);