use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.
the class JmxIT method startJetty.
public static void startJetty() throws Exception {
File target = MavenTestingUtils.getTargetDir();
File jettyBase = new File(target, "test-base");
File webapps = new File(jettyBase, "webapps");
File war = new File(webapps, "jmx-webapp.war");
//create server instance
__server = new Server(0);
//set up the webapp
WebAppContext context = new WebAppContext();
context.setWar(war.getCanonicalPath());
context.setContextPath("/jmx-webapp");
Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(__server);
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
__server.setHandler(context);
//set up jmx remote
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
__server.addBean(mbContainer);
JMXServiceURL serviceUrl = new JMXServiceURL("rmi", "localhost", 1099, "/jndi/rmi://localhost:1099/jmxrmi");
ConnectorServer jmxConnServer = new ConnectorServer(serviceUrl, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
__server.addBean(jmxConnServer);
//start server
__server.start();
//remember chosen port
__port = ((NetworkConnector) __server.getConnectors()[0]).getLocalPort();
}
use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.
the class QuickStartTest method testStandardTestWar.
@Test
public void testStandardTestWar() throws Exception {
PreconfigureStandardTestWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-standard-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/dump/info");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Dump Servlet"));
server.stop();
}
use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.
the class Quickstart method main.
public static void main(String... args) throws Exception {
if (args.length < 1)
error("No WAR file or directory given");
//war file or dir to start
String war = args[0];
//optional jetty context xml file to configure the webapp
Resource contextXml = null;
if (args.length > 1)
contextXml = Resource.newResource(args[1]);
Server server = new Server(8080);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
server.join();
}
use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.
the class AbstractHttpClientServerTest method startServer.
protected void startServer(Handler handler) throws Exception {
if (sslContextFactory != null) {
sslContextFactory.setEndpointIdentificationAlgorithm("");
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
sslContextFactory.setTrustStorePassword("storepwd");
}
if (server == null) {
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
}
connector = new ServerConnector(server, sslContextFactory);
server.addConnector(connector);
server.setHandler(handler);
server.start();
}
use of org.eclipse.jetty.server.Server in project jetty.project by eclipse.
the class HttpClientAuthenticationTest method start.
private void start(Authenticator authenticator, Handler handler) throws Exception {
server = new Server();
File realmFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService(realm, realmFile.getAbsolutePath());
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setAuthenticate(true);
//allow any authenticated user
constraint.setRoles(new String[] { "**" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/secure");
mapping.setConstraint(constraint);
securityHandler.addConstraintMapping(mapping);
securityHandler.setAuthenticator(authenticator);
securityHandler.setLoginService(loginService);
securityHandler.setHandler(handler);
start(securityHandler);
}
Aggregations