ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SecurityHandler sh = new SecurityHandler();
_server.setHandler(sh);
sh.setUserRealm(userRealm);
sh.setConstraintMappings(new ConstraintMapping[]{cm});
sh.setAuthenticator(new BasicAuthenticator());
Handler testHandler = new AbstractHandler()
{
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
{
System.out.println("passed authentication!");
Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
base_request.setHandled(true);
response.setStatus(200);
if (request.getServerName().equals("jetty.mortbay.org"))
{
response.getOutputStream().println("Proxy request: "+request.getRequestURL());
}
else if (request.getMethod().equalsIgnoreCase("GET"))
{
response.getOutputStream().println("<hello>");
for (int i=0; i<100; i++)
{
response.getOutputStream().println(" <world>"+i+"</world>");
if (i%20==0)
response.getOutputStream().flush();
}
response.getOutputStream().println("</hello>");
}
else
{
copyStream(request.getInputStream(),response.getOutputStream());
}
}
};
sh.setHandler(testHandler);
_server.start();
_port = connector.getLocalPort();
}