下面列出了javax.servlet.annotation.WebInitParam#org.eclipse.jetty.servlet.ServletHolder 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public FrontendEmbeddedWebServer(
final Stage aStage, final Backend aBackend, final PreviewProcessor aPreviewProcessor) {
jetty = new Server(PORT_NUMMER);
final var theWebApp = new WebAppContext();
theWebApp.setContextPath("/");
theWebApp.setBaseResource(Resource.newClassPathResource("/webapp"));
theWebApp.setDescriptor("WEB-INF/web.xml");
theWebApp.setClassLoader(getClass().getClassLoader());
theWebApp.addServlet(new ServletHolder(new SearchServlet(aBackend, "http://127.0.0.1:" + PORT_NUMMER)), SearchServlet.URL + "/*");
theWebApp.addServlet(new ServletHolder(new BringToFrontServlet(aStage)), BringToFrontServlet.URL);
theWebApp.addServlet(new ServletHolder(new SuggestionServlet(aBackend)), SuggestionServlet.URL);
theWebApp.addServlet(new ServletHolder(new ThumbnailServlet(aBackend, aPreviewProcessor)), ThumbnailServlet.URL + "/*");
jetty.setHandler(theWebApp);
}
public int run(String[] args) throws Exception {
URI uri = new URI("http://" + conf.get(HTRACE_VIEWER_HTTP_ADDRESS_KEY,
HTRACE_VIEWER_HTTP_ADDRESS_DEFAULT));
InetSocketAddress addr = new InetSocketAddress(uri.getHost(), uri.getPort());
server = new Server(addr);
ServletContextHandler root =
new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
server.setHandler(root);
String resourceBase = server.getClass()
.getClassLoader()
.getResource("webapps/htrace")
.toExternalForm();
root.setResourceBase(resourceBase);
root.setWelcomeFiles(new String[]{"index.html"});
root.addServlet(new ServletHolder(new DefaultServlet()),
"/");
root.addServlet(new ServletHolder(new HBaseSpanViewerTracesServlet(conf)),
"/gettraces");
root.addServlet(new ServletHolder(new HBaseSpanViewerSpansServlet(conf)),
"/getspans/*");
server.start();
server.join();
return 0;
}
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
* servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuthz) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
if (authenticationEnabled && requireAuthz) {
FilterHolder filter = new FilterHolder(AdminAuthorizedFilter.class);
filter.setName(AdminAuthorizedFilter.class.getSimpleName());
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setDispatches(FilterMapping.ALL);
fmap.setFilterName(AdminAuthorizedFilter.class.getSimpleName());
webAppContext.getServletHandler().addFilter(filter, fmap);
}
webAppContext.addServlet(holder, pathSpec);
}
public static void main(String[] args) throws Exception {
var websocketAddress = new InetSocketAddress("localhost", WEBSOCKET_PORT);
var twootrServer = new TwootrServer(websocketAddress);
twootrServer.start();
System.setProperty("org.eclipse.jetty.LEVEL", "INFO");
var context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setResourceBase(System.getProperty("user.dir") + "/src/main/webapp");
context.setContextPath("/");
ServletHolder staticContentServlet = new ServletHolder(
"staticContentServlet", DefaultServlet.class);
staticContentServlet.setInitParameter("dirAllowed", "true");
context.addServlet(staticContentServlet, "/");
var jettyServer = new Server(STATIC_PORT);
jettyServer.setHandler(context);
jettyServer.start();
jettyServer.dumpStdErr();
jettyServer.join();
}
public static void main(final String[] args) throws Exception {
final Server server = new Server(8686);
final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
final ServletContextHandler staticContext = new ServletContextHandler();
staticContext.setContextPath("/static");
staticContext.addServlet(staticHolder, "/*");
staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString());
// Register and map the dispatcher servlet
final ServletHolder cxfServletHolder = new ServletHolder(new CXFServlet());
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addEventListener(new ContextLoaderListener());
context.addServlet(cxfServletHolder, "/rest/*");
context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
context.setInitParameter("contextConfigLocation", StatsConfig.class.getName());
HandlerList handlers = new HandlerList();
handlers.addHandler(staticContext);
handlers.addHandler(context);
server.setHandler(handlers);
server.start();
server.join();
}
@Before
public void before() throws Exception {
File tmpSolrHome = createTempDir().toFile();
FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());
final SortedMap<ServletHolder, String> extraServlets = new TreeMap<>();
final ServletHolder solrRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
solrRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
extraServlets.put(solrRestApi, "/schema/*"); // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'
System.setProperty("managed.schema.mutable", "true");
System.setProperty("enable.update.log", "false");
createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-minimal.xml", "schema-rest.xml",
"/solr", true, extraServlets);
if (random().nextBoolean()) {
log.info("These tests are run with V2 API");
restTestHarness.setServerProvider(() -> jetty.getBaseUrl().toString() + "/____v2/cores/" + DEFAULT_TEST_CORENAME);
}
}
public static void main( String[] args ) throws Exception {
Server server = new Server(8080);
// Create the 'root' Spring application context
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addEventListener(new ContextLoaderListener());
context.setInitParameter("contextClass",AnnotationConfigWebApplicationContext.class.getName());
context.setInitParameter("contextConfigLocation",AppConfig.class.getName());
// Create default servlet (servlet api required)
// The name of DefaultServlet should be set to 'defualt'.
final ServletHolder defaultHolder = new ServletHolder( "default", DefaultServlet.class );
defaultHolder.setInitParameter( "resourceBase", System.getProperty("user.dir") );
context.addServlet( defaultHolder, "/" );
server.setHandler(context);
WebSocketServerContainerInitializer.configureContext(context);
server.start();
server.join();
}
protected Server() throws Exception {
org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);
final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(servletHolder, "/*");
servletHolder.setInitParameter("jaxrs.serviceClasses", Sample.class.getName());
servletHolder.setInitParameter("jaxrs.features",
Swagger2Feature.class.getName());
servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
new String[] {
MultipartProvider.class.getName(),
JacksonJsonProvider.class.getName(),
ApiOriginFilter.class.getName()
}, ",")
);
server.setHandler(context);
server.start();
server.join();
}
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new HelloModule(args));
injector.getAllBindings();
injector.createChildInjector().getAllBindings();
Server server = new Server(8080);
ServletContextHandler servletHandler = new ServletContextHandler();
servletHandler.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
servletHandler.setInitParameter("resteasy.role.based.security", "true");
servletHandler.addFilter(new FilterHolder(injector.getInstance(HelloFilter.class)), "/*", null);
//servletHandler.addServlet(DefaultServlet.class, "/*");
servletHandler.addServlet(sh, "/*");
server.setHandler(servletHandler);
server.start();
server.join();
}
public static void main(String[] args) throws IOException {
PcapServiceCli cli = new PcapServiceCli(args);
cli.parse();
Server server = new Server(cli.getPort());
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder h = new ServletHolder(new HttpServletDispatcher());
h.setInitParameter("javax.ws.rs.Application", "com.opensoc.pcapservice.rest.JettyServiceRunner");
context.addServlet(h, "/*");
server.setHandler(context);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) throws Exception {
if(args.length != 1) {
throw new Exception("Need exactly two argument containing th path to the configuration " +
"followed by the port number the server should use");
}
final String configPath = args[0];
// Setup a minimal servlet context for hosting our message broker servlet.
final Server server = new Server(0);
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/qa-regress");
final MessageBrokerServlet messageBrokerServlet = new MessageBrokerServlet();
final ServletHolder servlet = new ServletHolder(messageBrokerServlet);
servlet.setInitParameter("services.configuration.file", configPath);
context.addServlet(servlet, "/messagebroker/amf/*");
server.setHandler(context);
server.setDumpAfterStart(true);
try {
server.start();
} catch(Exception e) {
e.printStackTrace();
}
int port = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
System.out.println("Port:" + port);
}
public JavaNetReverseProxy(File cacheFolder) throws Exception {
this.cacheFolder = cacheFolder;
cacheFolder.mkdirs();
QueuedThreadPool qtp = new QueuedThreadPool();
qtp.setName("Jetty (JavaNetReverseProxy)");
server = new Server(qtp);
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(this), "/");
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
server.start();
localPort = connector.getLocalPort();
}
public void testConnectToNewNodesUsingHttp1() throws Exception {
JettyConfig jettyConfig = JettyConfig.builder()
.withServlet(new ServletHolder(Http2SolrClientTest.DebugServlet.class), "/debug/*")
.useOnlyHttp1(false)
.build();
createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
try (Http2SolrClient client = new Http2SolrClient.Builder(jetty.getBaseUrl().toString() + "/debug/foo")
.useHttp1_1(true)
.build()) {
assertTrue(client.getHttpClient().getTransport() instanceof HttpClientTransportOverHTTP);
try {
client.query(new SolrQuery("*:*"), SolrRequest.METHOD.GET);
} catch (BaseHttpSolrClient.RemoteSolrException ignored) {}
} finally {
afterSolrJettyTestBase();
}
}
private static WebAppContext setupWebAppContext(VarOneConfiguration conf) {
WebAppContext webApp = new WebAppContext();
webApp.setContextPath(conf.getServerContextPath());
File warPath = new File(conf.getString(ConfVars.VARONE_WAR));
if (warPath.isDirectory()) {
webApp.setResourceBase(warPath.getPath());
webApp.setParentLoaderPriority(true);
} else {
// use packaged WAR
webApp.setWar(warPath.getAbsolutePath());
File warTempDirectory = new File(conf.getRelativeDir(ConfVars.VARONE_WAR_TEMPDIR));
warTempDirectory.mkdir();
LOG.info("VarOneServer Webapp path: {}" + warTempDirectory.getPath());
webApp.setTempDirectory(warTempDirectory);
}
// Explicit bind to root
webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
return webApp;
}
@Override
protected int createServer() throws Exception
{
int port = super.getPort();
server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addEventListener(new CdiServletRequestListener());
context.addServlet(new ServletHolder(new RequestServlet()),"/*");
server.start();
return port;
}
@SuppressWarnings("squid:S2095")
private Server createRedirectorServer() {
int unsecurePort = conf.get(HTTP_PORT_KEY, HTTP_PORT_DEFAULT);
String hostname = conf.get(HTTP_BIND_HOST, HTTP_BIND_HOST_DEFAULT);
QueuedThreadPool qtp = new QueuedThreadPool(25);
qtp.setName(serverName + "Redirector");
qtp.setDaemon(true);
Server server = new LimitedMethodServer(qtp);
InetSocketAddress addr = new InetSocketAddress(hostname, unsecurePort);
ServerConnector connector = new ServerConnector(server);
connector.setHost(addr.getHostName());
connector.setPort(addr.getPort());
server.setConnectors(new Connector[]{connector});
ServletContextHandler context = new ServletContextHandler();
context.addServlet(new ServletHolder(new RedirectorServlet()), "/*");
context.setContextPath("/");
server.setHandler(context);
return server;
}
private static WebAppContext setupWebAppContext(ExplorerConfiguration conf) {
WebAppContext webApp = new WebAppContext();
File webapp = new File(conf.getString(ExplorerConfiguration.ConfVars.EXPLORER_WAR));
if (webapp.isDirectory()) { // Development mode, read from FS
webApp.setDescriptor(webapp+"/WEB-INF/web.xml");
webApp.setResourceBase(webapp.getPath());
webApp.setContextPath("/");
webApp.setParentLoaderPriority(true);
} else { //use packaged WAR
webApp.setWar(webapp.getAbsolutePath());
}
ServletHolder servletHolder = new ServletHolder(new DefaultServlet());
servletHolder.setInitParameter("cacheControl","private, max-age=0, must-revalidate");
webApp.addServlet(servletHolder, "/*");
return webApp;
}
private ServletContextHandler getMetricsHandler() {
MetricRegistry registry = Metrics.getRegistry();
HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry();
healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath()));
registry.registerAll(new GarbageCollectorMetricSet());
registry.registerAll(new MemoryUsageGaugeSet());
registry.registerAll(new ThreadStatesGaugeSet());
registry.registerAll(new JvmAttributeGaugeSet());
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("/__metrics");
servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry);
servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry);
servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*");
return servletContextHandler;
}
private Handler getPoseidonHandler() {
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("/");
servletContextHandler.addServlet(new ServletHolder(getPoseidonServlet()), "/*");
servletContextHandler.addServlet(new ServletHolder(rotationCheckServlet), "/_poseidon/rotation");
servletContextHandler.addServlet(new ServletHolder(backInRotationServlet), "/_poseidon/bir");
servletContextHandler.addServlet(new ServletHolder(outOfRotationServlet), "/_poseidon/oor");
configuration.registerServlets().forEach(servlet -> servletContextHandler.addServlet(servlet.getRight(), servlet.getLeft()));
addFilters(servletContextHandler);
InstrumentedHandler instrumentedHandler = new InstrumentedHandler(Metrics.getRegistry());
instrumentedHandler.setHandler(servletContextHandler);
return instrumentedHandler;
}
protected void run() {
server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
final ServletHolder servletHolder =
new ServletHolder(new CXFNonSpringJaxrsServlet(new BookApplicationNonSpring()));
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(servletHolder, "/*");
//servletHolder.setInitParameter("jaxrs.serviceClasses", BookStore.class.getName());
server.setHandler(context);
try {
server.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Swagger core handler - Needed for the RestFul api documentation
*
* @return ServletContextHandler of Swagger
*/
private static ServletContextHandler setupSwaggerContextHandler(int port) {
// Configure Swagger-core
final ServletHolder SwaggerServlet = new ServletHolder(
new com.wordnik.swagger.jersey.config.JerseyJaxrsConfig());
SwaggerServlet.setName("JerseyJaxrsConfig");
SwaggerServlet.setInitParameter("api.version", "1.0.0");
SwaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:" + port + "/api");
SwaggerServlet.setInitOrder(2);
// Setup the handler
final ServletContextHandler handler = new ServletContextHandler();
handler.setSessionHandler(new SessionHandler());
handler.addServlet(SwaggerServlet, "/api-docs/*");
return handler;
}
private static void setupRestApiContextHandler(WebAppContext webapp, SubmarineConfiguration conf) {
final ServletHolder servletHolder =
new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer());
servletHolder.setInitParameter("javax.ws.rs.Application", SubmarineServer.class.getName());
servletHolder.setName("rest");
servletHolder.setForcedPath("rest");
webapp.setSessionHandler(new SessionHandler());
webapp.addServlet(servletHolder, "/api/*");
}
@Override
protected void configureWebAppContext(WebAppContext webAppContext)
{
super.configureWebAppContext(webAppContext);
// the tenant servlet with alfresco managed authentication
ServletHolder servletHolder = new ServletHolder(CmisAtomPubServlet.class);
servletHolder.setInitParameter("callContextHandler", "org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler");
webAppContext.addServlet(servletHolder, "/cmisatom/*");
}
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
* servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
// Jetty doesn't like the same path spec mapping to different servlets, so
// if there's already a mapping for this pathSpec, remove it and assume that
// the newest one is the one we want
final ServletMapping[] servletMappings =
webAppContext.getServletHandler().getServletMappings();
for (ServletMapping servletMapping : servletMappings) {
if (servletMapping.containsPathSpec(pathSpec)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found existing " + servletMapping.getServletName() +
" servlet at path " + pathSpec + "; will replace mapping" +
" with " + holder.getName() + " servlet");
}
ServletMapping[] newServletMappings =
ArrayUtil.removeFromArray(servletMappings, servletMapping);
webAppContext.getServletHandler()
.setServletMappings(newServletMappings);
break;
}
}
webAppContext.addServlet(holder, pathSpec);
if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(FilterMapping.ALL);
handler.addFilterMapping(fmap);
}
}
private static WebAppContext createWebAppContext(Builder b,
AccessControlList adminsAcl, final String appDir) {
WebAppContext ctx = new WebAppContext();
ctx.setDefaultsDescriptor(null);
ServletHolder holder = new ServletHolder(new DefaultServlet());
Map<String, String> params = ImmutableMap.<String, String>builder()
.put("acceptRanges", "true")
.put("dirAllowed", "false")
.put("gzip", "true")
.put("useFileMappedBuffer", "true")
.build();
holder.setInitParameters(params);
ctx.setWelcomeFiles(new String[] {"index.html"});
ctx.addServlet(holder, "/");
ctx.setDisplayName(b.name);
ctx.setContextPath("/");
ctx.setWar(appDir + "/" + b.name);
String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY);
if (tempDirectory != null && !tempDirectory.isEmpty()) {
ctx.setTempDirectory(new File(tempDirectory));
ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory);
}
ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf);
ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
addNoCacheFilter(ctx);
return ctx;
}
public static Handler create() {
ServletHolder consoleHolder = new ServletHolder( "console", MockServlet.class );
consoleHolder.setInitParameter( "contentType", "text/html" );
consoleHolder.setInitParameter( "content", "<html>Console UI goes here.</html>" );
ServletContextHandler consoleContext = new ServletContextHandler( ServletContextHandler.SESSIONS );
consoleContext.setContextPath( "/console" );
consoleContext.setResourceBase( "target/classes" );
consoleContext.addServlet( consoleHolder, "/*" );
return consoleContext;
}
private CXFServlet configStandaloneServer() {
httpServer = new org.eclipse.jetty.server.Server(httpPort);
Bus bus = BusFactory.getDefaultBus(true);
ContextHandlerCollection contexts = new ContextHandlerCollection();
httpServer.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/",
ServletContextHandler.SESSIONS);
CXFServlet cxf = new CXFServlet();
cxf.setBus(bus);
ServletHolder servlet = new ServletHolder(cxf);
root.addServlet(servlet, "/cxf/*");
return cxf;
}
private static void addServlets(ServletContextHandler context)
{
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
context.addServlet(RecommendationsService.class, "/recommendations");
context.addServlet(ListApplicationsService.class, "/listApplications");
context.addServlet(HealthService.class, "/health");
}
@BeforeClass
public static void startServer() throws Exception {
// Let server pick its own random, available port.
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
Class<?> config = CommonsMultipartResolverTestConfig.class;
ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class);
commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName());
commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
handler.addServlet(commonsResolverServlet, "/commons-resolver/*");
config = StandardMultipartResolverTestConfig.class;
ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
standardResolverServlet.setInitParameter("contextConfigLocation", config.getName());
standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
handler.addServlet(standardResolverServlet, "/standard-resolver/*");
server.setHandler(handler);
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
public void start() throws Exception
{
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
// Setup the basic application "context" for this application at "/"
// This is also known as the handler tree (in jetty speak)
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
server.setHandler(contextHandler);
WebSocketServlet webSocketServlet = new WebSocketServlet()
{
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
{
return websocket;
}
};
contextHandler.addServlet(new ServletHolder(webSocketServlet), "/pubsub");
server.start();
if (port == 0) {
port = server.getConnectors()[0].getLocalPort();
}
}