01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.tm.webmbean;
23:
24: import javax.management.MBeanServer;
25: import javax.management.ObjectName;
26:
27: import org.apache.catalina.connector.Connector;
28: import org.apache.coyote.memory.MemoryProtocolHandler;
29: import org.apache.tomcat.util.buf.ByteChunk;
30: import org.jboss.system.ServiceMBeanSupport;
31:
32: /**
33: * Server Side Web test.
34: *
35: * @author adrian@jboss.org
36: * @version $Revision: 57211 $
37: */
38: public class WebTest extends ServiceMBeanSupport implements
39: WebTestMBean {
40: public void test() throws Exception {
41: MBeanServer server = getServer();
42: ObjectName name = new ObjectName(
43: "jboss.web:type=Service,serviceName=jboss.web");
44: Connector connector = new Connector(
45: "org.apache.coyote.memory.MemoryProtocolHandler");
46: MemoryProtocolHandler handler = (MemoryProtocolHandler) connector
47: .getProtocolHandler();
48: server.invoke(name, "addConnector", new Object[] { connector },
49: new String[] { Connector.class.getName() });
50: try {
51: ByteChunk input = new ByteChunk(1024);
52: ByteChunk output = new ByteChunk(1024);
53: org.apache.coyote.Request req = new org.apache.coyote.Request();
54: req.decodedURI().setString("/webbmtcleanuptest/test1.jsp");
55: req.method().setString("GET");
56: org.apache.coyote.Response resp = new org.apache.coyote.Response();
57: handler.process(req, input, resp, output);
58: if (resp.getStatus() != 200)
59: throw new Error(output.toString());
60:
61: input = new ByteChunk(1024);
62: output = new ByteChunk(1024);
63: req = new org.apache.coyote.Request();
64: req.decodedURI().setString("/webbmtcleanuptest/test2.jsp");
65: req.method().setString("GET");
66: resp = new org.apache.coyote.Response();
67: handler.process(req, input, resp, output);
68: if (resp.getStatus() != 200)
69: throw new Error(output.toString());
70: } finally {
71: try {
72: connector.stop();
73: } finally {
74: connector.destroy();
75: }
76: }
77: }
78: }
|