use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestServletAnnotations method testWebServletAnnotationIgnore.
@Test
public void testWebServletAnnotationIgnore() throws Exception {
//an existing servlet OF THE SAME NAME has even 1 non-default mapping we can't use
//any of the url mappings in the annotation
WebAppContext wac = new WebAppContext();
ServletHolder servlet = new ServletHolder();
servlet.setClassName("org.eclipse.jetty.servlet.OtherDServlet");
servlet.setName("DServlet");
wac.getServletHandler().addServlet(servlet);
ServletMapping m = new ServletMapping();
m.setPathSpec("/default");
m.setDefault(true);
m.setServletName("DServlet");
wac.getServletHandler().addServletMapping(m);
ServletMapping m2 = new ServletMapping();
m2.setPathSpec("/other");
m2.setServletName("DServlet");
wac.getServletHandler().addServletMapping(m2);
WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null);
annotation.apply();
ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings();
assertEquals(2, resultMappings.length);
for (ServletMapping r : resultMappings) {
assertEquals(1, r.getPathSpecs().length);
if (!r.getPathSpecs()[0].equals("/default") && !r.getPathSpecs()[0].equals("/other"))
fail("Unexpected path in mapping");
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestResourceAnnotations method init.
@Before
public void init() throws Exception {
server = new Server();
wac = new WebAppContext();
wac.setServer(server);
injections = new InjectionCollection();
wac.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
InitialContext ic = new InitialContext();
comp = (Context) ic.lookup("java:comp");
env = comp.createSubcontext("env");
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class OneWebApp method main.
public static void main(String[] args) throws Exception {
// Create a basic jetty server object that will listen on port 8080.
// Note that if you set this to port 0 then a randomly available port
// will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
// The WebAppContext is the entity that controls the environment in
// which a web application lives and breathes. In this example the
// context path is being set to "/" so it is suitable for serving root
// context requests and then we see it setting the location of the war.
// A whole host of other configurations are available, ranging from
// configuring to support annotation scanning in the webapp (through
// PlusConfiguration) to choosing where the webapp will unpack itself.
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
File warFile = new File("../../tests/test-jmx/jmx-webapp/target/jmx-webapp");
webapp.setWar(warFile.getAbsolutePath());
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.
server.setHandler(webapp);
// Start things up!
server.start();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class AnnotatedServerEndpointTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
File testdir = MavenTestingUtils.getTargetTestingDir(AnnotatedServerEndpointTest.class.getName());
server = new WSServer(testdir, "app");
server.createWebInf();
server.copyEndpoint(ConfiguredEchoSocket.class);
server.copyClass(EchoSocketConfigurator.class);
server.copyClass(DateDecoder.class);
server.copyClass(TimeEncoder.class);
server.start();
WebAppContext webapp = server.createWebAppContext();
server.deployWebapp(webapp);
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class LargeAnnotatedTest method testEcho.
@Test
public void testEcho() throws Exception {
WSServer wsb = new WSServer(testdir, "app");
wsb.createWebInf();
wsb.copyEndpoint(LargeEchoConfiguredSocket.class);
try {
wsb.start();
URI uri = wsb.getServerBaseURI();
WebAppContext webapp = wsb.createWebAppContext();
wsb.deployWebapp(webapp);
// wsb.dump();
WebSocketClient client = new WebSocketClient(bufferPool);
try {
client.getPolicy().setMaxTextMessageSize(128 * 1024);
client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<Session> foo = client.connect(clientEcho, uri.resolve("echo/large"));
// wait for connect
foo.get(1, TimeUnit.SECONDS);
// The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies
byte[] txt = new byte[100 * 1024];
Arrays.fill(txt, (byte) 'o');
String msg = new String(txt, StandardCharsets.UTF_8);
clientEcho.sendMessage(msg);
Queue<String> msgs = clientEcho.awaitMessages(1);
Assert.assertEquals("Expected message", msg, msgs.poll());
} finally {
client.stop();
}
} finally {
wsb.stop();
}
}
Aggregations