OK, I'm completely stuck. I want to run Tomcat in embedded mode so I can test an application without running the server in a separate process. I'm missing something simple, stupid, and important, and I need your help to see it.
This test fails with an HTTP error 400, Bad Request. I've tried MemoryProtocolHandler, context.invoke(), ... I don't know what to do. Maybe you see something simple.
package ca.jbrains.jsfunit.learning.test;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.MemoryRealm;
import org.apache.catalina.startup.Embedded;
import org.junit.After;
import org.junit.Test;
import com.gargoylesoftware.htmlunit.WebClient;
public class LearnEmbeddedTomcatTest {
private Embedded embedded;
private Container host;
private Engine engine;
@Test
public void deploySampleApplicationFromFileSystem() throws Exception {
String tomcatPath = "/Users/jbrains/ThirdParty/apache-tomcat-5.5.28-embed";
// Create an embedded server
embedded = new Embedded();
embedded.setCatalinaHome(tomcatPath);
embedded.setRealm(new MemoryRealm());
// Create an engine
engine = embedded.createEngine();
engine.setDefaultHost("localhost");
// Create a default virtual host
host = embedded.createHost("localhost", tomcatPath + "/webapps");
engine.addChild(host);
// Create an application context
Context context = embedded.createContext("TddJsfWeb", tomcatPath
+ "/webapps/TddJsfWeb");
host.addChild(context);
// Install the assembled container hierarchy
embedded.addEngine(engine);
// Assemble and install a default HTTP connector
Connector connector = embedded.createConnector("localhost", 8080,
"http");
embedded.addConnector(connector);
// Start the embedded server
embedded.setAwait(true);
embedded.start();
WebClient webClient = new WebClient();
webClient.getPage("http://localhost:8080/TddJsfWeb/static.xhtml");
}
}
The unpacked .war is definitely at /Users/jbrains/ThirdParty/apache-tomcat-5.5.28-embed/webapps/TddJsfWeb/... and static.xhtml is in the root of the unpacked .war folder.
Please, please, show me how stupid I am. Thanks.