310431 Default ErrorHandler as server Bean
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1566 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
84e467659e
commit
937d475839
|
@ -12,6 +12,7 @@ jetty-7.1.0-SNAPSHOT
|
|||
+ 309765 Added JSP module
|
||||
+ 310051 _configurationClasses now defaults to null in WebAppContext
|
||||
+ 310094 Improved start.jar usage and config files
|
||||
+ 310431 Default ErrorHandler as server Bean
|
||||
+ JETTY-903 Stop both caches
|
||||
+ JETTY-1200 SSL NIO Endpoint wraps non NIO buffers
|
||||
+ JETTY-1202 Use platform default algorithm for SecureRandom
|
||||
|
|
|
@ -261,9 +261,7 @@ public class XmlConfiguredJetty
|
|||
|
||||
public DeploymentManager getActiveDeploymentManager()
|
||||
{
|
||||
List<DeploymentManager> depmans = server.getBeans(DeploymentManager.class);
|
||||
Assert.assertEquals("DeploymentManager bean count",1,depmans.size());
|
||||
return depmans.get(0);
|
||||
return server.getBean(DeploymentManager.class);
|
||||
}
|
||||
|
||||
public File getJettyDir(String name)
|
||||
|
|
|
@ -256,15 +256,13 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
/* ------------------------------------------------------------ */
|
||||
protected IdentityService findIdentityService()
|
||||
{
|
||||
List<IdentityService> services = getServer().getBeans(IdentityService.class);
|
||||
if (services!=null && services.size()>0)
|
||||
return services.get(0);
|
||||
return null;
|
||||
return getServer().getBean(IdentityService.class);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
@Override
|
||||
protected void doStart()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -354,6 +352,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti
|
|||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected boolean checkSecurity(Request request)
|
||||
{
|
||||
switch(request.getDispatcherType())
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
|
@ -288,14 +289,14 @@ public class Response implements HttpServletResponse
|
|||
ContextHandler.Context context = request.getContext();
|
||||
if (context!=null)
|
||||
error_handler=context.getContextHandler().getErrorHandler();
|
||||
if (error_handler==null)
|
||||
error_handler = _connection.getConnector().getServer().getBean(ErrorHandler.class);
|
||||
if (error_handler!=null)
|
||||
{
|
||||
// TODO - probably should reset these after the request?
|
||||
request.setAttribute(Dispatcher.ERROR_STATUS_CODE,new Integer(code));
|
||||
request.setAttribute(Dispatcher.ERROR_MESSAGE, message);
|
||||
request.setAttribute(Dispatcher.ERROR_REQUEST_URI, request.getRequestURI());
|
||||
request.setAttribute(Dispatcher.ERROR_SERVLET_NAME,request.getServletName());
|
||||
|
||||
error_handler.handle(null,_connection.getRequest(),_connection.getRequest(),this );
|
||||
}
|
||||
else
|
||||
|
|
|
@ -14,15 +14,11 @@
|
|||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -499,6 +495,34 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
return beans;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get dependent bean of a specific class.
|
||||
* If more than one bean of the type exist, the first is returned.
|
||||
* @see #addBean(Object)
|
||||
* @param clazz
|
||||
* @return bean or null
|
||||
*/
|
||||
public <T> T getBean(Class<T> clazz)
|
||||
{
|
||||
Iterator<?> iter = _dependentBeans.iterator();
|
||||
T t=null;
|
||||
int count=0;
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Object o = iter.next();
|
||||
if (clazz.isInstance(o))
|
||||
{
|
||||
count++;
|
||||
if (t==null)
|
||||
t=(T)o;
|
||||
}
|
||||
}
|
||||
if (count>1)
|
||||
Log.debug("getBean({}) 1 of {}",clazz.getName(),count);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a LifeCycle object to be started/stopped
|
||||
* along with the Server
|
||||
|
|
|
@ -578,14 +578,9 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
old_context=__context.get();
|
||||
__context.set(_scontext);
|
||||
|
||||
if (_errorHandler==null)
|
||||
setErrorHandler(new ErrorHandler());
|
||||
|
||||
|
||||
// defers the calling of super.doStart()
|
||||
startContext();
|
||||
|
||||
|
||||
_availability=_shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE;
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -27,13 +27,11 @@ import org.eclipse.jetty.server.HttpConnection;
|
|||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Handler for Error pages
|
||||
* A handler that is registered at the org.eclipse.http.ErrorHandler
|
||||
* context attributed and called by the HttpResponse.sendError method to write a
|
||||
* error page.
|
||||
*
|
||||
* An ErrorHandler is registered with {@link ContextHandler#setErrorHandler(ErrorHandler)} or
|
||||
* {@link org.eclipse.jetty.server.Server#addBean(Object)}.
|
||||
* It is called by the HttpResponse.sendError method to write a error page.
|
||||
*
|
||||
*/
|
||||
public class ErrorHandler extends AbstractHandler
|
||||
|
|
|
@ -113,7 +113,6 @@ public class ServletContextHandler extends ContextHandler
|
|||
else if (parent instanceof HandlerCollection)
|
||||
((HandlerCollection)parent).addHandler(this);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the defaultSecurityHandlerClass.
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.jetty.io.ByteArrayBuffer;
|
|||
import org.eclipse.jetty.server.LocalConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.bio.SocketConnector;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
|
@ -60,6 +61,7 @@ public class ServletTester
|
|||
{
|
||||
try
|
||||
{
|
||||
_server.addBean(new ErrorHandler());
|
||||
_server.setSendServerVersion(false);
|
||||
_server.addConnector(_connector);
|
||||
_server.setHandler(_context);
|
||||
|
|
|
@ -253,6 +253,8 @@ public class ServletTest extends TestCase
|
|||
out.put(request0.getBytes("iso8859-1"));
|
||||
String responses = tester.getResponses(out).toString();
|
||||
|
||||
System.err.println(responses);
|
||||
|
||||
int offset = responses.indexOf("HTTP/1.1 500");
|
||||
assertTrue(offset>=0);
|
||||
offset = responses.indexOf("Content-Length: ",offset);
|
||||
|
|
Loading…
Reference in New Issue