use of org.apache.catalina.deploy.ApplicationListener in project tomcat70 by apache.
the class TldConfig method execute.
/**
* Scan for and configure all tag library descriptors found in this
* web application.
*
* This supports a Tomcat-specific extension to the TLD search
* order defined in the JSP spec. It allows tag libraries packaged as JAR
* files to be shared by web applications by simply dropping them in a
* location that all web applications have access to (e.g.,
* <CATALINA_HOME>/lib). It also supports some of the weird and
* wonderful arrangements present when Tomcat gets embedded.
*
* The set of shared JARs to be scanned for TLDs is narrowed down by
* the <tt>noTldJars</tt> class variable, which contains the names of JARs
* that are known not to contain any TLDs.
*/
// Context.addApplicationListener(ApplicationListener) is deprecated.
@SuppressWarnings("deprecation")
public void execute() {
long t1 = System.currentTimeMillis();
/*
* Priority order of URIs required by spec is:
* 1. J2EE platform taglibs - Tomcat doesn't provide these
* 2. web.xml entries
* 3. JARS in WEB-INF/lib & TLDs under WEB-INF (equal priority)
* 4. Additional entries from the container
*
* Keep processing order in sync with o.a.j.compiler.TldLocationsCache
*/
// Stage 2 - web.xml entries
tldScanWebXml();
// Stage 3a - TLDs under WEB-INF (not lib or classes)
tldScanResourcePaths(WEB_INF);
// Stages 3b & 4
JarScanner jarScanner = context.getJarScanner();
TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(), tldCallBack, noTldJars);
if (tldCallBack.scanFoundNoTLDs()) {
log.info(sm.getString("tldConfig.noTldSummary"));
}
// Now add all the listeners we found to the listeners for this context
String[] list = getTldListeners();
if (log.isDebugEnabled())
log.debug(sm.getString("tldConfig.addListeners", Integer.valueOf(list.length)));
for (int i = 0; i < list.length; i++) {
context.addApplicationListener(new ApplicationListener(list[i], true));
}
long t2 = System.currentTimeMillis();
if (context instanceof StandardContext) {
((StandardContext) context).setTldScanTime(t2 - t1);
}
}
use of org.apache.catalina.deploy.ApplicationListener in project tomcat70 by apache.
the class TestWebSocket method testNoUpgrade.
@Test
public void testNoUpgrade() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Connection: upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 13" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an error response
// No upgrade means it is not treated an as upgrade request so a 404 is
// generated when the request reaches the Default Servlet.s
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 404"));
// Finished with the socket
client.close();
}
use of org.apache.catalina.deploy.ApplicationListener in project tomcat70 by apache.
the class TestWebSocket method testSimple.
@Test
public void testSimple() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Upgrade: websocket" + CRLF);
client.writer.write("Connection: keep-alive, upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 13" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an upgrade response
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
// Swallow the headers
String responseHeaderLine = client.reader.readLine();
while (!responseHeaderLine.equals("")) {
responseHeaderLine = client.reader.readLine();
}
// Now we can do WebSocket
client.sendMessage("foo", false);
client.sendMessage("foo", true);
Assert.assertEquals("foofoo", client.readMessage());
// Finished with the socket
client.close();
}
use of org.apache.catalina.deploy.ApplicationListener in project tomcat70 by apache.
the class TestWebSocket method testDetectWrongVersion.
@Test
public void testDetectWrongVersion() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Upgrade: websocket" + CRLF);
client.writer.write("Connection: upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 8" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an upgrade response
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 426"));
List<String> headerlines = new ArrayList<String>();
String responseHeaderLine = client.reader.readLine();
while (!responseHeaderLine.equals("")) {
headerlines.add(responseHeaderLine);
responseHeaderLine = client.reader.readLine();
}
Assert.assertTrue(headerlines.contains("Sec-WebSocket-Version: 13"));
// Finished with the socket
client.close();
}
use of org.apache.catalina.deploy.ApplicationListener in project tomcat70 by apache.
the class TestWebSocket method testKey.
@Test
public void testKey() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Upgrade: websocket" + CRLF);
client.writer.write("Connection: upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 13" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an upgrade response
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
String accept = null;
String responseHeaderLine = client.reader.readLine();
while (!responseHeaderLine.equals("")) {
if (responseHeaderLine.startsWith("Sec-WebSocket-Accept: ")) {
accept = responseHeaderLine.substring(responseHeaderLine.indexOf(':') + 2);
break;
}
responseHeaderLine = client.reader.readLine();
}
Assert.assertTrue(accept != null);
MessageDigest sha1Helper = MessageDigest.getInstance("SHA1");
sha1Helper.reset();
sha1Helper.update("TODO".getBytes(B2CConverter.ISO_8859_1));
String source = Base64.encode(sha1Helper.digest(WS_ACCEPT));
Assert.assertEquals(source, accept);
sha1Helper.reset();
sha1Helper.update("TOD".getBytes(B2CConverter.ISO_8859_1));
source = Base64.encode(sha1Helper.digest(WS_ACCEPT));
Assert.assertFalse(source.equals(accept));
// Finished with the socket
client.close();
}
Aggregations