I'm aware that 'embedded' is an overloaded term, especially with regard to web components in the Java world. I'm using it to mean "done entirely in a Java class with no xml configuration". An example of this is below.
My question is - is there a proven way to do embedded web testing of JSF-2.0 components? I mean starting up a server with opening a port (that a selenium test could theoretically connect to). I'm not interested in the Selenium startup.
All I want is to be able to point to an existing JSF-2.0 page, an existing backing bean, and have it served up on a given port.
与此最接近的似乎是 Jetty 中的此页面:http: //musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html
我希望 Tomcat 或 Glassfish 或另一个库中有另一个示例可以更好地解释这一点。
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
public class HelloHandler extends AbstractHandler
{
public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>Hello World</h1>");
}
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
server.setHandler(new HelloHandler());
server.start();
server.join();
}
}