Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding Tomcat and issuing requests to the deployed application
    text
    copied!<p>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.</p> <p>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.</p> <pre> 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"); } } </pre> <p>The unpacked .war is definitely at <code>/Users/jbrains/ThirdParty/apache-tomcat-5.5.28-embed/webapps/TddJsfWeb/...</code> and <code>static.xhtml</code> is in the root of the unpacked .war folder.</p> <p>Please, please, show me how stupid I am. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload