Here are the examples of the java api org.apache.catalina.startup.Tomcat.start() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
680 Examples
19
Source : TomcatServer.java
with Apache License 2.0
from zzzzbw
with Apache License 2.0
from zzzzbw
@Override
public void startServer() throws Exception {
tomcat.start();
String address = tomcat.getServer().getAddress();
int port = tomcat.getConnector().getPort();
log.info("local address: http://{}:{}", address, port);
tomcat.getServer().await();
}
19
Source : TestCustomSsl.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestCustomTrustManager(boolean serverTrustAll) throws Exception {
if (!TesterSupport.RFC_5746_SUPPORTED) {
// Make sure SSL renegotiation is not disabled in the JVM
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
}
Tomcat tomcat = getTomcatInstance();
replacedume.replacedumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isRenegotiationSupported(getTomcatInstance()));
TesterSupport.configureClientCertContext(tomcat);
// Override the defaults
ProtocolHandler handler = tomcat.getConnector().getProtocolHandler();
if (handler instanceof AbstractHttp11JsseProtocol) {
((AbstractHttp11JsseProtocol<?>) handler).setTruststoreFile(null);
} else {
// Unexpected
fail("Unexpected handler type");
}
if (serverTrustAll) {
tomcat.getConnector().setAttribute("trustManagerClreplacedName", "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
}
// Start Tomcat
tomcat.start();
TesterSupport.configureClientSsl();
// Unprotected resource
ByteChunk res = getUrl("https://localhost:" + getPort() + "/unprotected");
replacedertEquals("OK", res.toString());
// Protected resource
res.recycle();
int rc = -1;
try {
rc = getUrl("https://localhost:" + getPort() + "/protected", res, null, null);
} catch (SocketException se) {
if (serverTrustAll) {
fail(se.getMessage());
se.printStackTrace();
}
} catch (SSLException he) {
if (serverTrustAll) {
fail(he.getMessage());
he.printStackTrace();
}
}
if (serverTrustAll) {
replacedertEquals(200, rc);
replacedertEquals("OK-" + TesterSupport.ROLE, res.toString());
} else {
replacedertTrue(rc != 200);
replacedertEquals("", res.toString());
}
}
19
Source : TestELInJsp.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestELMisc(boolean quoteAttributeEL) throws Exception {
Tomcat tomcat = getTomcatInstance();
// Create the context (don't use addWebapp as we want to modify the
// JSP Servlet settings).
File appDir = new File("test/webapp-3.0");
StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
// Configure the defaults and then tweak the JSP servlet settings
// Note: Min value for maxLoadedJsps is 2
Tomcat.initWebappDefaults(ctxt);
Wrapper w = (Wrapper) ctxt.findChild("jsp");
String jspName;
if (quoteAttributeEL) {
jspName = "/test/el-misc-with-quote-attribute-el.jsp";
w.addInitParameter("quoteAttributeEL", "true");
} else {
jspName = "/test/el-misc-no-quote-attribute-el.jsp";
w.addInitParameter("quoteAttributeEL", "false");
}
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + jspName);
String result = res.toString();
replacedertEcho(result, "00-\\\\\\\"${'hello world'}");
replacedertEcho(result, "01-\\\\\\\"\\${'hello world'}");
replacedertEcho(result, "02-\\\"${'hello world'}");
replacedertEcho(result, "03-\\\"\\hello world");
replacedertEcho(result, "2az-04");
replacedertEcho(result, "05-a2z");
replacedertEcho(result, "06-az2");
replacedertEcho(result, "2az-07");
replacedertEcho(result, "08-a2z");
replacedertEcho(result, "09-az2");
replacedertEcho(result, "10-${'foo'}bar");
replacedertEcho(result, "11-\\\"}");
replacedertEcho(result, "12-foo\\bar\\baz");
replacedertEcho(result, "13-foo\\bar\\baz");
replacedertEcho(result, "14-foo\\bar\\baz");
replacedertEcho(result, "15-foo\\bar\\baz");
replacedertEcho(result, "16-foo\\bar\\baz");
replacedertEcho(result, "17-foo\\'bar'\\"baz"");
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithTESavedRequest() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: savedrequest" + SimpleHttpClient.CRLF + "Content-Length: 9" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "test=data";
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse501());
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithTEUnsupported() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: unsupported" + SimpleHttpClient.CRLF + "Content-Length: 9" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "test=data";
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse501());
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithTEBuffered() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: buffered" + SimpleHttpClient.CRLF + "Content-Length: 9" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "test=data";
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse501());
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithTEVoid() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: void" + SimpleHttpClient.CRLF + "Content-Length: 9" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "test=data";
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse501());
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestWithTEChunked(boolean withCL) throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + (withCL ? "Content-length: 1" + SimpleHttpClient.CRLF : "") + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "9" + SimpleHttpClient.CRLF + "test=data" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse200());
replacedertTrue(client.getResponseBody().contains("test - data"));
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithTEIdenreplacedy() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: idenreplacedy" + SimpleHttpClient.CRLF + "Content-Length: 9" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "test=data";
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse200());
replacedertTrue(client.getResponseBody().contains("test - data"));
}
19
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWithUnknownExpectation() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Expect: unknoen" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse417());
}
19
Source : TestStandardContext.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug49922() throws Exception {
// Test that filter mapping works. Test that the same filter is
// called only once, even if is selected by several mapping
// url-patterns or by both a url-pattern and a servlet-name.
// Set up a container
Tomcat tomcat = getTomcatInstance();
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
ByteChunk result = new ByteChunk();
// Check filter and servlet aren't called
int rc = getUrl("http://localhost:" + getPort() + "/bug49922/foo", result, null);
replacedertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
replacedertTrue(result.getLength() > 0);
// Check extension mapping works
result = getUrl("http://localhost:" + getPort() + "/foo.do");
replacedertEquals("FilterServlet", result.toString());
// Check path mapping works
result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet");
replacedertEquals("FilterServlet", result.toString());
// Check servlet name mapping works
result = getUrl("http://localhost:" + getPort() + "/foo.od");
replacedertEquals("FilterServlet", result.toString());
// Check filter is only called once
result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.do");
replacedertEquals("FilterServlet", result.toString());
result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.od");
replacedertEquals("FilterServlet", result.toString());
// Check dispatcher mapping
result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
replacedertEquals("Target", result.toString());
result = getUrl("http://localhost:" + getPort() + "/bug49922/forward");
replacedertEquals("FilterTarget", result.toString());
result = getUrl("http://localhost:" + getPort() + "/bug49922/include");
replacedertEquals("IncludeFilterTarget", result.toString());
}
19
Source : TestStandardContext.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWebappListenerConfigureFail() throws Exception {
// Test that if LifecycleListener on webapp fails during
// configure_start event and if the cause of the failure is gone,
// the context can be started without a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingLifecycleListener listener = new FailingLifecycleListener();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.addLifecycleListener(listener);
try {
context.start();
fail();
} catch (LifecycleException ex) {
// As expected
}
replacedertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
listener.setFail(false);
context.start();
replacedertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
replacedertEquals("Target", result.toString());
}
19
Source : 1401.java
with MIT License
from masud-technope
with MIT License
from masud-technope
@Test
public void testWebappListenerConfigureFail() throws Exception {
// Test that if LifecycleListener on webapp fails during
// configure_start event and if the cause of the failure is gone,
// the context can be started without a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingLifecycleListener listener = new FailingLifecycleListener();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.addLifecycleListener(listener);
try {
context.start();
fail();
} catch (LifecycleException ex) {
}
replacedertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
listener.setFail(false);
context.start();
replacedertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
replacedertEquals("Target", result.toString());
}
19
Source : HttpServer.java
with Apache License 2.0
from li-liangshan
with Apache License 2.0
from li-liangshan
public void start() {
if (started) {
return;
}
synchronized (lock) {
if (started) {
return;
}
try {
tomcat.start();
tomcat.getServer().await();
started = true;
} catch (LifecycleException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
19
Source : Sparrow.java
with MIT License
from kelthuzadx
with MIT License
from kelthuzadx
private void serve() {
try {
tomcat.start();
logger.info("Sparrow started");
tomcat.getServer().await();
} catch (LifecycleException e) {
e.printStackTrace();
}
}
19
Source : IntegrationTests.java
with GNU General Public License v3.0
from hantsy
with GNU General Public License v3.0
from hantsy
@BeforeAll
public void beforeAll() throws LifecycleException {
tomcat.start();
System.out.println("Tomcat server is running at port:" + tomcat.getConnector().getLocalPort());
}
19
Source : TestMimeHeadersIntegration.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
private void runHeadersTest(final boolean successExpected, final Tomcat tomcat, final int count, final int expectedMaxHeaderCount) throws Exception {
tomcat.start();
String header = "A:B" + SimpleHttpClient.CRLF;
StringBuilder request = new StringBuilder();
request.append("GET / HTTP/1.0" + SimpleHttpClient.CRLF);
for (int i = 0; i < count; i++) {
request.append(header);
}
request.append(SimpleHttpClient.CRLF);
Client client = new Client(tomcat);
client.setRequest(new String[] { request.toString() });
try {
client.connect();
client.processRequest();
client.disconnect();
} catch (SocketException ex) {
// Connection was closed by Tomcat
if (successExpected) {
// unexpected
log.error(ex.getMessage(), ex);
} else {
log.warn(ex.getMessage(), ex);
}
}
if (successExpected) {
alv.validateAccessLog(1, 200, 0, 3000);
// Response 200
replacedert.replacedertTrue("Response line is: " + client.getResponseLine(), client.getResponseLine() != null && client.isResponse200());
replacedert.replacedertEquals("OK", client.getResponseBody());
} else {
alv.validateAccessLog(1, 400, 0, 3000);
// Connection aborted or response 400
replacedert.replacedertTrue("Response line is: " + client.getResponseLine(), client.getResponseLine() == null || client.isResponse400());
}
int maxHeaderCount = ((Integer) tomcat.getConnector().getProperty("maxHeaderCount")).intValue();
replacedert.replacedertEquals(expectedMaxHeaderCount, maxHeaderCount);
if (maxHeaderCount > 0) {
replacedert.replacedertEquals(maxHeaderCount, alv.arraySize);
} else if (maxHeaderCount < 0) {
int maxHttpHeaderSize = ((Integer) tomcat.getConnector().getProperty("maxHttpHeaderSize")).intValue();
int headerCount = Math.min(count, maxHttpHeaderSize / header.length() + 1);
int arraySize = 1;
while (arraySize < headerCount) {
arraySize <<= 1;
}
replacedert.replacedertEquals(arraySize, alv.arraySize);
}
}
19
Source : TestLargeUpload.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
@Override
protected void configureAndStartWebApplication() throws LifecycleException {
Tomcat tomcat = getTomcatInstance();
// Retain '/simple' url-pattern since it enables code re-use
Context ctxt = tomcat.addContext("", null);
Tomcat.addServlet(ctxt, "read", new DataReadServlet());
ctxt.addServletMappingDecoded("/simple", "read");
tomcat.start();
}
19
Source : TestChunkedInputFilter.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
private void doTestExtensionSizeLimit(int len, boolean ok) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
replacedert.replacedertTrue(tomcat.getConnector().setProperty("maxExtensionSize", Integer.toString(EXT_SIZE_LIMIT)));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(ok));
ctx.addServletMappingDecoded("/", "servlet");
tomcat.start();
String extName = ";foo=";
StringBuilder extValue = new StringBuilder(len);
for (int i = 0; i < (len - extName.length()); i++) {
extValue.append("x");
}
String[] request = new String[] { "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "3" + extName + extValue.toString() + SimpleHttpClient.CRLF + "a=0" + SimpleHttpClient.CRLF + "4" + SimpleHttpClient.CRLF + "&b=1" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF };
TrailerClient client = new TrailerClient(tomcat.getConnector().getLocalPort());
client.setRequest(request);
client.connect();
client.processRequest();
if (ok) {
replacedert.replacedertTrue(client.isResponse200());
} else {
replacedert.replacedertTrue(client.isResponse500());
}
}
19
Source : TestStandardWrapper.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
@Test
public void testSecurityAnnotationsNoWebXmlConstraints() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-servletsecurity");
tomcat.addWebapp(null, "", appDir.getAbsolutePath());
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc;
rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
replacedert.replacedertTrue(bc.getLength() > 0);
replacedert.replacedertEquals(403, rc);
}
19
Source : TestStandardWrapper.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
@Test
public void testSecurityAnnotationsWebXmlPriority() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-fragments");
Context ctx = tomcat.addWebapp(null, "", appDir.getAbsolutePath());
skipTldsForResourceJars(ctx);
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc;
rc = getUrl("http://localhost:" + getPort() + "/testStandardWrapper/securityAnnotationsWebXmlPriority", bc, null, null);
replacedert.replacedertTrue(bc.getLength() > 0);
replacedert.replacedertEquals(403, rc);
}
19
Source : TestDefaultInstanceManager.java
with GNU General Public License v3.0
from guang19
with GNU General Public License v3.0
from guang19
private DefaultInstanceManager doClreplacedUnloadingPrep() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Create the context (don't use addWebapp as we want to modify the
// JSP Servlet settings).
File appDir = new File("test/webapp");
StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
ctxt.addServletContainerInitializer(new JasperInitializer(), null);
// Configure the defaults and then tweak the JSP servlet settings
// Note: Min value for maxLoadedJsps is 2
Tomcat.initWebappDefaults(ctxt);
Wrapper w = (Wrapper) ctxt.findChild("jsp");
w.addInitParameter("maxLoadedJsps", "2");
tomcat.start();
return (DefaultInstanceManager) ctxt.getInstanceManager();
}
19
Source : Launcher.java
with Apache License 2.0
from DaveVoorhis
with Apache License 2.0
from DaveVoorhis
protected boolean go() {
try {
tomcat.start();
} catch (Throwable e) {
System.out.println("Launch failure due to: " + e);
e.printStackTrace();
return false;
}
return true;
}
19
Source : TestMimeHeadersIntegration.java
with MIT License
from chenmudu
with MIT License
from chenmudu
private void runHeadersTest(final boolean successExpected, final Tomcat tomcat, final int count, final int expectedMaxHeaderCount) throws Exception {
tomcat.start();
String header = "A:B" + SimpleHttpClient.CRLF;
StringBuilder request = new StringBuilder();
request.append("GET / HTTP/1.0" + SimpleHttpClient.CRLF);
for (int i = 0; i < count; i++) {
request.append(header);
}
request.append(SimpleHttpClient.CRLF);
Client client = new Client(tomcat);
client.setRequest(new String[] { request.toString() });
try {
client.connect();
client.processRequest();
client.disconnect();
} catch (SocketException ex) {
// Connection was closed by Tomcat
if (successExpected) {
// unexpected
log.error(ex.getMessage(), ex);
} else {
log.warn(ex.getMessage(), ex);
}
}
if (successExpected) {
alv.validateAccessLog(1, 200, 0, 3000);
// Response 200
replacedert.replacedertTrue("Response line is: " + client.getResponseLine(), client.getResponseLine() != null && client.isResponse200());
replacedert.replacedertEquals("OK", client.getResponseBody());
} else {
alv.validateAccessLog(1, 400, 0, 3000);
// Connection aborted or response 400
replacedert.replacedertTrue("Response line is: " + client.getResponseLine(), client.getResponseLine() == null || client.isResponse400());
}
int maxHeaderCount = ((Integer) tomcat.getConnector().getProperty("maxHeaderCount")).intValue();
replacedert.replacedertEquals(expectedMaxHeaderCount, maxHeaderCount);
if (maxHeaderCount > 0) {
replacedert.replacedertEquals(maxHeaderCount, alv.arraySize);
} else if (maxHeaderCount < 0) {
int maxHttpHeaderSize = ((Integer) tomcat.getConnector().getAttribute("maxHttpHeaderSize")).intValue();
int headerCount = Math.min(count, maxHttpHeaderSize / header.length() + 1);
int arraySize = 1;
while (arraySize < headerCount) {
arraySize <<= 1;
}
replacedert.replacedertEquals(arraySize, alv.arraySize);
}
}
19
Source : TestChunkedInputFilter.java
with MIT License
from chenmudu
with MIT License
from chenmudu
private void doTestExtensionSizeLimit(int len, boolean ok) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setProperty("maxExtensionSize", Integer.toString(EXT_SIZE_LIMIT));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(ok));
ctx.addServletMappingDecoded("/", "servlet");
tomcat.start();
String extName = ";foo=";
StringBuilder extValue = new StringBuilder(len);
for (int i = 0; i < (len - extName.length()); i++) {
extValue.append("x");
}
String[] request = new String[] { "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "3" + extName + extValue.toString() + SimpleHttpClient.CRLF + "a=0" + SimpleHttpClient.CRLF + "4" + SimpleHttpClient.CRLF + "&b=1" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF };
TrailerClient client = new TrailerClient(tomcat.getConnector().getLocalPort());
client.setRequest(request);
client.connect();
client.processRequest();
if (ok) {
replacedert.replacedertTrue(client.isResponse200());
} else {
replacedert.replacedertTrue(client.isResponse500());
}
}
18
Source : TestBug49158.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Override
@Test
public void testCookiesInstance() throws Exception {
Tomcat tomcat = getTomcatInstance();
addServlets(tomcat);
tomcat.start();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
ByteChunk res = new ByteChunk();
getUrl("http://localhost:" + getPort() + "/" + path, res, headers);
List<String> cookieHeaders = headers.get("Set-Cookie");
replacedertEquals("There should only be one Set-Cookie header in this test", 1, cookieHeaders.size());
}
18
Source : TestGenerator.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void testBug48701(String jsp) throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/" + jsp);
String result = res.toString();
replacedertEcho(result, "00-Preplaced");
}
18
Source : TestELInJsp.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug56029() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
// This test needs the JSTL libraries
File lib = new File("webapps/examples/WEB-INF/lib");
ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug56029.jspx");
String result = res.toString();
replacedert.replacedertTrue(result.contains("[1]:[1]"));
}
18
Source : TestELInJsp.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug56147() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
// This test needs the JSTL libraries
File lib = new File("webapps/examples/WEB-INF/lib");
ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug56147.jsp");
String result = res.toString();
replacedertEcho(result, "00-OK");
}
18
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testResponseWithErrorChunked() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctxt = tomcat.addContext("", null);
// Add protected servlet
Tomcat.addServlet(ctxt, "ChunkedResponseWithErrorServlet", new ResponseWithErrorServlet(true));
ctxt.addServletMapping("/*", "ChunkedResponseWithErrorServlet");
tomcat.start();
String request = "GET /anything HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
// Expected response is a 200 response followed by an incomplete chunked
// body.
replacedertTrue(client.isResponse200());
// There should not be an end chunk
replacedertFalse(client.getResponseBody().endsWith("0"));
// The last portion of text should be there
replacedertTrue(client.getResponseBody().endsWith("line03"));
}
18
Source : TestAbstractHttp11Processor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testPipelining() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctxt = tomcat.addContext("", null);
// Add protected servlet
Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet());
ctxt.addServletMapping("/foo", "TesterServlet");
tomcat.start();
String requestPart1 = "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF;
String requestPart2 = "Host: any" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
final Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { requestPart1, requestPart2 });
client.setRequestPause(1000);
client.setUseContentLength(true);
client.connect();
Runnable send = new Runnable() {
@Override
public void run() {
try {
client.sendRequest();
client.sendRequest();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
Thread t = new Thread(send);
t.start();
// Sleep for 1500 ms which should mean the all of request 1 has been
// sent and half of request 2
Thread.sleep(1500);
// Now read the first response
client.readResponse(true);
replacedertFalse(client.isResponse50x());
replacedertTrue(client.isResponse200());
replacedertEquals("OK", client.getResponseBody());
// Read the second response. No need to sleep, read will block until
// there is data to process
client.readResponse(true);
replacedertFalse(client.isResponse50x());
replacedertTrue(client.isResponse200());
replacedertEquals("OK", client.getResponseBody());
}
18
Source : TestChunkedInputFilter.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestExtensionSizeLimit(int len, boolean ok) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setProperty("maxExtensionSize", Integer.toString(EXT_SIZE_LIMIT));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(ok));
ctx.addServletMapping("/", "servlet");
tomcat.start();
String extName = ";foo=";
StringBuilder extValue = new StringBuilder(len);
for (int i = 0; i < (len - extName.length()); i++) {
extValue.append("x");
}
String[] request = new String[] { "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "3" + extName + extValue.toString() + SimpleHttpClient.CRLF + "a=0" + SimpleHttpClient.CRLF + "4" + SimpleHttpClient.CRLF + "&b=1" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF };
TrailerClient client = new TrailerClient(tomcat.getConnector().getLocalPort());
client.setRequest(request);
client.connect();
client.processRequest();
if (ok) {
replacedertTrue(client.isResponse200());
} else {
replacedertTrue(client.isResponse500());
}
}
18
Source : TestChunkedInputFilter.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
/**
* @param expectPreplaced
* If the servlet is expected to process the request
* @param expectReadWholeBody
* If the servlet is expected to fully read the body and reliably
* deliver a response
* @param chunks
* Text of chunks
* @param readLimit
* Do not read more than this many bytes
* @param expectReadCount
* Expected count of read bytes
* @throws Exception
* Unexpected
*/
private void doTestChunkSize(boolean expectPreplaced, boolean expectReadWholeBody, String chunks, int readLimit, int expectReadCount) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
BodyReadServlet servlet = new BodyReadServlet(expectPreplaced, readLimit);
Tomcat.addServlet(ctx, "servlet", servlet);
ctx.addServletMapping("/", "servlet");
tomcat.start();
String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: text/plain" + SimpleHttpClient.CRLF;
if (expectPreplaced) {
request += "Connection: close" + SimpleHttpClient.CRLF;
}
request += SimpleHttpClient.CRLF + chunks + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
TrailerClient client = new TrailerClient(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
Exception processException = null;
client.connect();
try {
client.processRequest();
} catch (Exception e) {
// Socket was probably closed before client had a chance to read
// response
processException = e;
}
if (expectPreplaced) {
if (expectReadWholeBody) {
replacedertNull(processException);
}
if (processException == null) {
replacedertTrue(client.getResponseLine(), client.isResponse200());
replacedertEquals(String.valueOf(expectReadCount), client.getResponseBody());
}
replacedertEquals(expectReadCount, servlet.getCountRead());
} else {
if (processException == null) {
replacedertTrue(client.getResponseLine(), client.isResponse500());
}
replacedertEquals(0, servlet.getCountRead());
replacedertTrue(servlet.getExceptionDuringRead());
}
}
18
Source : TestChunkedInputFilter.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestChunkingCRLF(boolean chunkHeaderUsesCRLF, boolean chunkUsesCRLF, boolean firstheaderUsesCRLF, boolean secondheaderUsesCRLF, boolean endUsesCRLF, boolean expectPreplaced) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Configure allowed trailer headers
tomcat.getConnector().setProperty("allowedTrailerHeaders", "X-Trailer1,X-Trailer2");
EchoHeaderServlet servlet = new EchoHeaderServlet(expectPreplaced);
Tomcat.addServlet(ctx, "servlet", servlet);
ctx.addServletMapping("/", "servlet");
tomcat.start();
String[] request = new String[] { "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "3" + (chunkHeaderUsesCRLF ? SimpleHttpClient.CRLF : LF) + "a=0" + (chunkUsesCRLF ? SimpleHttpClient.CRLF : LF) + "4" + SimpleHttpClient.CRLF + "&b=1" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + "x-trailer1: Test", "Value1" + (firstheaderUsesCRLF ? SimpleHttpClient.CRLF : LF) + "x-trailer2: TestValue2" + (secondheaderUsesCRLF ? SimpleHttpClient.CRLF : LF) + (endUsesCRLF ? SimpleHttpClient.CRLF : LF) };
TrailerClient client = new TrailerClient(tomcat.getConnector().getLocalPort());
client.setRequest(request);
client.connect();
Exception processException = null;
try {
client.processRequest();
} catch (Exception e) {
// Socket was probably closed before client had a chance to read
// response
processException = e;
}
if (expectPreplaced) {
replacedertTrue(client.isResponse200());
replacedertEquals("nullnull7TestValue1TestValue2", client.getResponseBody());
replacedertNull(processException);
replacedertFalse(servlet.getExceptionDuringRead());
} else {
if (processException == null) {
replacedertTrue(client.getResponseLine(), client.isResponse500());
} else {
// Use fall-back for checking the error occurred
replacedertTrue(servlet.getExceptionDuringRead());
}
}
}
18
Source : TestAbstractAjpProcessor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testKeepAlive() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setProperty("connectionTimeout", "-1");
tomcat.start();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "helloWorld", new HelloWorldServlet());
ctx.addServletMapping("/", "helloWorld");
SimpleAjpClient ajpClient = new SimpleAjpClient();
ajpClient.setPort(getPort());
ajpClient.connect();
validateCpong(ajpClient.cping());
TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
forwardMessage.addHeader("X-DUMMY-HEADER", "IGNORE");
// Complete the message - no extra headers required.
forwardMessage.end();
// Two requests
for (int i = 0; i < 2; i++) {
TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage);
// Expect 3 packets: headers, body, end
validateResponseHeaders(responseHeaders, 200, "OK");
TesterAjpMessage responseBody = ajpClient.readMessage();
validateResponseBody(responseBody, HelloWorldServlet.RESPONSE_TEXT);
validateResponseEnd(ajpClient.readMessage(), true);
// Give connections plenty of time to time out
Thread.sleep(2000);
// Double check the connection is still open
validateCpong(ajpClient.cping());
}
ajpClient.disconnect();
}
18
Source : TestAbstractAjpProcessor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
public void doTestPost(boolean multipleCL, int expectedStatus, String expectedMessage) throws Exception {
Tomcat tomcat = getTomcatInstance();
// Use the normal Tomcat ROOT context
File root = new File("test/webapp-3.0");
tomcat.addWebapp("", root.getAbsolutePath());
tomcat.start();
SimpleAjpClient ajpClient = new SimpleAjpClient();
ajpClient.setPort(getPort());
ajpClient.connect();
validateCpong(ajpClient.cping());
ajpClient.setUri("/echo-params.jsp");
ajpClient.setMethod("POST");
TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
forwardMessage.addHeader(0xA008, "9");
if (multipleCL) {
forwardMessage.addHeader(0xA008, "99");
}
forwardMessage.addHeader(0xA007, "application/x-www-form-urlencoded");
forwardMessage.end();
TesterAjpMessage bodyMessage = ajpClient.createBodyMessage("test=data".getBytes());
TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage, bodyMessage);
validateResponseHeaders(responseHeaders, expectedStatus, expectedMessage);
if (expectedStatus == HttpServletResponse.SC_OK) {
// Expect 3 messages: headers, body, end for a valid request
TesterAjpMessage responseBody = ajpClient.readMessage();
validateResponseBody(responseBody, "test - data");
validateResponseEnd(ajpClient.readMessage(), true);
// Double check the connection is still open
validateCpong(ajpClient.cping());
} else {
// Expect 2 messages: headers, end for an invalid request
validateResponseEnd(ajpClient.readMessage(), false);
}
ajpClient.disconnect();
}
18
Source : TestAbstractAjpProcessor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testSecret() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setProperty("requiredSecret", "RIGHTSECRET");
tomcat.start();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "helloWorld", new HelloWorldServlet());
ctx.addServletMapping("/", "helloWorld");
SimpleAjpClient ajpClient = new SimpleAjpClient();
ajpClient.setPort(getPort());
ajpClient.connect();
validateCpong(ajpClient.cping());
TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
forwardMessage.end();
TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage);
// Expect 3 packets: headers, body, end
validateResponseHeaders(responseHeaders, 403, "Forbidden");
// TesterAjpMessage responseBody = ajpClient.readMessage();
// validateResponseBody(responseBody, HelloWorldServlet.RESPONSE_TEXT);
validateResponseEnd(ajpClient.readMessage(), false);
ajpClient.connect();
validateCpong(ajpClient.cping());
forwardMessage = ajpClient.createForwardMessage();
forwardMessage.addAttribute(0x0C, "WRONGSECRET");
forwardMessage.end();
responseHeaders = ajpClient.sendMessage(forwardMessage);
// Expect 3 packets: headers, body, end
validateResponseHeaders(responseHeaders, 403, "Forbidden");
// responseBody = ajpClient.readMessage();
// validateResponseBody(responseBody, HelloWorldServlet.RESPONSE_TEXT);
validateResponseEnd(ajpClient.readMessage(), false);
ajpClient.connect();
validateCpong(ajpClient.cping());
forwardMessage = ajpClient.createForwardMessage();
forwardMessage.addAttribute(0x0C, "RIGHTSECRET");
forwardMessage.end();
responseHeaders = ajpClient.sendMessage(forwardMessage);
// Expect 3 packets: headers, body, end
validateResponseHeaders(responseHeaders, 200, "OK");
TesterAjpMessage responseBody = ajpClient.readMessage();
validateResponseBody(responseBody, HelloWorldServlet.RESPONSE_TEXT);
validateResponseEnd(ajpClient.readMessage(), true);
ajpClient.disconnect();
}
18
Source : TestAbstractAjpProcessor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testLargeResponse() throws Exception {
int ajpPacketSize = 16000;
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setProperty("packetSize", Integer.toString(ajpPacketSize));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
FixedResponseSizeServlet servlet = new FixedResponseSizeServlet(15000, 16000);
Tomcat.addServlet(ctx, "FixedResponseSizeServlet", servlet);
ctx.addServletMapping("/", "FixedResponseSizeServlet");
tomcat.start();
SimpleAjpClient ajpClient = new SimpleAjpClient(ajpPacketSize);
ajpClient.setPort(getPort());
ajpClient.connect();
validateCpong(ajpClient.cping());
ajpClient.setUri("/");
TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
forwardMessage.end();
TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage);
// Expect 3 messages: headers, body, end for a valid request
validateResponseHeaders(responseHeaders, 200, "OK");
TesterAjpMessage responseBody = ajpClient.readMessage();
replacedert.replacedertTrue(responseBody.len > 15000);
validateResponseEnd(ajpClient.readMessage(), true);
// Double check the connection is still open
validateCpong(ajpClient.cping());
ajpClient.disconnect();
}
18
Source : TestAbstractAjpProcessor.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
/*
* Bug 55453
*/
@Test
public void test304WithBody() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "bug55453", new Tester304WithBodyServlet());
ctx.addServletMapping("/", "bug55453");
tomcat.start();
SimpleAjpClient ajpClient = new SimpleAjpClient();
ajpClient.setPort(getPort());
ajpClient.connect();
validateCpong(ajpClient.cping());
TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
forwardMessage.end();
TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage, null);
// Expect 2 messages: headers, end
validateResponseHeaders(responseHeaders, 304, "Not Modified");
validateResponseEnd(ajpClient.readMessage(), true);
// Double check the connection is still open
validateCpong(ajpClient.cping());
ajpClient.disconnect();
}
18
Source : TestErrorReportValve.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug53071() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "errorServlet", new ErrorServlet());
ctx.addServletMapping("/", "errorServlet");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort());
replacedert.replacedertTrue(res.toString().contains("<p><b>message</b> <u>" + ErrorServlet.ERROR_TEXT + "</u></p>"));
}
18
Source : TestStandardSessionIntegration.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doTestInvalidate(boolean useClustering) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "bug56578", new Bug56578Servlet());
ctx.addServletMapping("/bug56578", "bug56578");
if (useClustering) {
tomcat.getEngine().setCluster(new SimpleTcpCluster());
ctx.setDistributable(true);
ctx.setManager(ctx.getCluster().createManager(""));
}
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/bug56578");
replacedert.replacedertEquals("Preplaced", res.toString());
}
18
Source : TestStandardContextResources.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testResources2() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0-fragments");
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMapping("/getresource", "getresource");
tomcat.start();
replacedertPageContains("/test/getresource?path=/resourceF.jsp", "<p>resourceF.jsp in resources2.jar</p>");
replacedertPageContains("/test/getresource?path=/resourceA.jsp", "<p>resourceA.jsp in the web application</p>");
replacedertPageContains("/test/getresource?path=/resourceB.jsp", "<p>resourceB.jsp in resources.jar</p>");
replacedertPageContains("/test/getresource?path=/folder/resourceC.jsp", "<p>resourceC.jsp in the web application</p>");
replacedertPageContains("/test/getresource?path=/folder/resourceD.jsp", "<p>resourceD.jsp in resources.jar</p>");
replacedertPageContains("/test/getresource?path=/folder/resourceE.jsp", "<p>resourceE.jsp in the web application</p>");
}
18
Source : TestStandardContextResources.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testResourcesWebInfClreplacedes() throws Exception {
Tomcat tomcat = getTomcatInstance();
// app dir is relative to server home
File appDir = new File("test/webapp-3.0-fragments");
// Need to cast to be able to set StandardContext specific attribute
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
ctxt.setAddWebinfClreplacedesResources(true);
tomcat.start();
replacedertPageContains("/test/resourceA.jsp", "<p>resourceA.jsp in the web application</p>");
replacedertPageContains("/test/resourceB.jsp", "<p>resourceB.jsp in resources.jar</p>");
replacedertPageContains("/test/folder/resourceC.jsp", "<p>resourceC.jsp in the web application</p>");
replacedertPageContains("/test/folder/resourceD.jsp", "<p>resourceD.jsp in resources.jar</p>");
replacedertPageContains("/test/folder/resourceE.jsp", "<p>resourceE.jsp in the web application</p>");
replacedertPageContains("/test/resourceG.jsp", "<p>resourceG.jsp in WEB-INF/clreplacedes</p>");
}
18
Source : TestStandardContext.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug46243() throws Exception {
// This tests that if a Filter init() fails then the web application
// is not put into service. (BZ 46243)
// This also tests that if the cause of the failure is gone,
// the context can be started without a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
File docBase = new File(tomcat.getHost().getAppBase(), "ROOT");
if (!docBase.mkdirs() && !docBase.isDirectory()) {
fail("Unable to create docBase");
}
Context root = tomcat.addContext("", "ROOT");
configureTest46243Context(root, true);
tomcat.start();
// Configure the client
Bug46243Client client = new Bug46243Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { REQUEST });
client.connect();
client.processRequest();
replacedertTrue(client.isResponse404());
// Context failed to start. This checks that automatic transition
// from FAILED to STOPPED state was successful.
replacedertEquals(LifecycleState.STOPPED, root.getState());
// Prepare context for the second attempt
// Configuration was cleared on stop() thanks to
// StandardContext.resetContext(), so we need to configure it again
// from scratch.
configureTest46243Context(root, false);
root.start();
// The same request is processed successfully
client.connect();
client.processRequest();
replacedertTrue(client.isResponse200());
replacedertEquals(Bug46243Filter.clreplaced.getName() + HelloWorldServlet.RESPONSE_TEXT, client.getResponseBody());
}
18
Source : TestStandardContext.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testWebappLoaderStartFail() throws Exception {
// Test that if WebappLoader start() fails and if the cause of
// the failure is gone, the context can be started without
// a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingWebappLoader loader = new FailingWebappLoader();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.setLoader(loader);
try {
context.start();
fail();
} catch (LifecycleException ex) {
// As expected
}
replacedertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
loader.setFail(false);
context.start();
replacedertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
replacedertEquals("Target", result.toString());
}
18
Source : TestStandardContext.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testTldListener() throws Exception {
// Set up a container
Tomcat tomcat = getTomcatInstance();
File docBase = new File("test/webapp-3.0");
Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
// Start the context
tomcat.start();
// Stop the context
ctx.stop();
String log = TesterTldListener.getLog();
replacedert.replacedertTrue(log, log.contains("Preplaced-01"));
replacedert.replacedertTrue(log, log.contains("Preplaced-02"));
replacedert.replacedertFalse(log, log.contains("FAIL"));
}
18
Source : TestApplicationHttpRequest.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
private void doQueryStringTest(String originalQueryString, String forwardQueryString, Map<String, String[]> expected) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
if (forwardQueryString == null) {
Tomcat.addServlet(ctx, "forward", new ForwardServlet("/display"));
} else {
Tomcat.addServlet(ctx, "forward", new ForwardServlet("/display?" + forwardQueryString));
}
ctx.addServletMapping("/forward", "forward");
Tomcat.addServlet(ctx, "display", new DisplayParameterServlet(expected));
ctx.addServletMapping("/display", "display");
tomcat.start();
ByteChunk response = new ByteChunk();
StringBuilder target = new StringBuilder("http://localhost:");
target.append(getPort());
target.append("/forward");
if (originalQueryString != null) {
target.append('?');
target.append(originalQueryString);
}
int rc = getUrl(target.toString(), response, null);
replacedert.replacedertEquals(200, rc);
replacedert.replacedertEquals("OK", response.toString());
}
18
Source : TestSendFile.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testSendFile() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
File[] files = new File[ITERATIONS];
for (int i = 0; i < ITERATIONS; i++) {
files[i] = generateFile(TEMP_DIR, "-" + i, EXPECTED_CONTENT_LENGTH * (i + 1));
}
try {
for (int i = 0; i < ITERATIONS; i++) {
WritingServlet servlet = new WritingServlet(files[i]);
Tomcat.addServlet(root, "servlet" + i, servlet);
root.addServletMapping("/servlet" + i, "servlet" + i);
}
tomcat.start();
ByteChunk bc = new ByteChunk();
Map<String, List<String>> respHeaders = new HashMap<String, List<String>>();
for (int i = 0; i < ITERATIONS; i++) {
long start = System.currentTimeMillis();
int rc = getUrl("http://localhost:" + getPort() + "/servlet" + i, bc, null, respHeaders);
replacedertEquals(HttpServletResponse.SC_OK, rc);
System.out.println("Client received " + bc.getLength() + " bytes in " + (System.currentTimeMillis() - start) + " ms.");
replacedertEquals(EXPECTED_CONTENT_LENGTH * (i + 1), bc.getLength());
bc.recycle();
}
} finally {
for (File f : files) {
f.delete();
}
}
}
18
Source : TestResponse.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
/**
* Tests an issue noticed during the investigation of BZ 52811.
*/
@Test
public void testCharset() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new CharsetServlet());
ctx.addServletMapping("/", "servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
replacedertEquals("OK", bc.toString());
}
18
Source : TestResponse.java
with Apache License 2.0
from wangyingjie
with Apache License 2.0
from wangyingjie
@Test
public void testBug52811() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new Bug52811Servlet());
ctx.addServletMapping("/", "servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
replacedertEquals("OK", bc.toString());
}
See More Examples