本文整理汇总了Java中org.eclipse.jetty.server.handler.ContextHandler.setContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java ContextHandler.setContextPath方法的具体用法?Java ContextHandler.setContextPath怎么用?Java ContextHandler.setContextPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.ContextHandler
的用法示例。
在下文中一共展示了ContextHandler.setContextPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllServices
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
private HandlerList getAllServices() throws Exception{
// File server & Context Handler for root, also setting the index.html
// to be the "welcome file", i.e, autolink on root addresses.
ContextHandler rootContext = new ContextHandler();
rootContext.setContextPath("/*");
rootContext.setHandler(getResourceHandlers());
// Possible servlet lists, for all servlets or custom services you want to access later.
// Warning, it might become a little bit nested if you add to many classes.
ServletHandler questionHandler = new ServletHandler();
questionHandler.addServletWithMapping(QuestionHandler.class, "/question");
// Add the ResourceHandler to the server.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] {
rootContext ,
questionHandler,
});
return handlers;
}
示例2: main
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
// connector
// server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class)
// .setHttpCompliance(HttpCompliance.LEGACY);
// server.setHandler(new HelloHandler("Hi JettyEmbeded "," light测试"));
// Add a single handler on context "/hello"
ContextHandler context = new ContextHandler();
context.setContextPath( "/hello" );
context.setHandler( new HelloHandler("Hi JettyEmbeded "," light测试") );
// Can be accessed using http://localhost:8080/hello
server.setHandler( context );
server.start();
server.join();
}
示例3: main
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final ApiServer api = new ApiServer(new InetSocketAddress(9998));
PrometheusConfig cfg = createPrometheusConfig(args);
final Optional<File> _cfg = cfg.getConfiguration();
if (_cfg.isPresent())
registry_ = new PipelineBuilder(_cfg.get()).build();
else
registry_ = new PipelineBuilder(Configuration.DEFAULT).build();
api.start();
Runtime.getRuntime().addShutdownHook(new Thread(api::close));
Server server = new Server(cfg.getPort());
ContextHandler context = new ContextHandler();
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.setContextPath(cfg.getPath());
context.setHandler(new DisplayMetrics(registry_));
server.setHandler(context);
server.start();
server.join();
}
示例4: setUpGuiHandler
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
/**
* do setup for the static resource handler
* @return ContextHandler for the static resource handler
*/
private static ContextHandler setUpGuiHandler() throws MalformedURLException
{
ContextHandler context1 = new ContextHandler();
context1.setContextPath("/");
ResourceHandler res = new ResourceHandler();
res.setWelcomeFiles(new String[]{"index.html"});
res.setBaseResource(Resource.newResource("./resources/"));
context1.setHandler(res);
logger.info("<---gui handler initialised--->");
// WebAppContext webApp = new WebAppContext();
// webApp.setContextPath("/");
// webApp.setResourceBase("/home/orpheus/projects/BeSeen/BeSeenium/resources/");
// webApp.setWar("/home/orpheus/projects/BeSeen/BeSeenium/resources/quercus-4.0.18.war");
// webApp.setServer(server);
// context1.setHandler(webApp);
return context1;
}
示例5: systemRestart
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
private ContextHandler systemRestart() {
AbstractHandler system = new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
restartContexts();
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>Done</h1>");
}
};
ContextHandler context = new ContextHandler();
context.setContextPath("/vraptor/restart");
context.setResourceBase(".");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.setHandler(system);
return context;
}
示例6: doPreStart
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
@Override
protected void doPreStart() {
ContextHandler welcomeContext = new ContextHandler("/");
welcomeContext.setContextPath("/");
welcomeContext.setHandler(new WelcomeHandler(gpapProjectsFolder));
ContextHandler projectsListContext = new ContextHandler("/stage_gplist_download");
projectsListContext.setHandler(new ProjectListHandler(gpapProjectsFolder));
ContextHandler projectDownloadContext = new ContextHandler("/stage_gpproject_download");
projectDownloadContext.setHandler(new ProjectDownloadHandler(gpapProjectsFolder));
ContextHandler projectUploadContext = new ContextHandler("/stage_gpproject_upload");
projectUploadContext.setHandler(new ProjectUploadHandler(gpapProjectsFolder));
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]{welcomeContext, projectDownloadContext, projectUploadContext, projectsListContext});
_server.setHandler(contexts);
}
示例7: listen
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
@Override
public HttpServer listen(int port) throws Exception {
SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class));
sessionHandler.setHandler(new MiddlewareHandler(app));
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setResourceBase(".");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.setHandler(sessionHandler);
Server server = new Server(port);
server.setSessionIdManager(new HashSessionIdManager());
server.setHandler(context);
server.start();
server.join();
return this;
}
示例8: main
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server(8085);
ContextHandler context = new ContextHandler("/");
context.setContextPath("/");
context.setHandler(new HandlerGUI("Root Hello"));
ContextHandler contextFR = new ContextHandler("/fr");
contextFR.setHandler(new HandlerGUI("Bonjoir"));
ContextHandler contextIT = new ContextHandler("/it");
contextIT.setHandler(new HandlerGUI("Bongiorno"));
ContextHandler contextV = new ContextHandler("/");
contextV.setVirtualHosts(new String[] { "127.0.0.2" });
contextV.setHandler(new HandlerGUI("Virtual Hello"));
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { context, contextFR, contextIT, contextV });
server.setHandler(contexts);
server.start();
server.join();
}
示例9: configServer
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
@Override
protected void configServer(Server server, int port) {
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
ResourceHandler handler = new ResourceHandler();
ContextHandler context = new ContextHandler();
context.setContextPath("/dbus/");
context.setResourceBase(SystemUtils.USER_DIR + File.separator + "html");
context.setHandler(handler);
server.setHandler(context);
}
示例10: run
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public void run() {
try {
System.out.println("Listening on Reqs...");
Server server = new Server(Config.PORT);
// Handler for the voting API
ContextHandler votingContext = new ContextHandler();
votingContext.setContextPath("/vote");
votingContext.setHandler(new VoteHandler());
// Handler for the stats API
ContextHandler statContext = new ContextHandler();
statContext.setContextPath("/stats");
statContext.setHandler(new StatsHandler());
// summing all the Handlers up to one
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { votingContext, statContext});
server.setHandler(contexts);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: main
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public static void main( String[] args ) throws Exception
{
Server server = new Server(8080);
ContextHandler context = new ContextHandler("/");
context.setContextPath("/");
context.setHandler(new HelloHandler("Root Hello"));
ContextHandler contextFR = new ContextHandler("/fr");
contextFR.setHandler(new HelloHandler("Bonjoir"));
ContextHandler contextIT = new ContextHandler("/it");
contextIT.setHandler(new HelloHandler("Bongiorno"));
ContextHandler contextV = new ContextHandler("/");
contextV.setVirtualHosts(new String[] { "127.0.0.2" });
contextV.setHandler(new HelloHandler("Virtual Hello"));
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { context, contextFR, contextIT,
contextV });
server.setHandler(contexts);
server.start();
server.join();
}
示例12: main
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Map<String, String> settings = System.getenv();
// When run from app-runner, you must use the port set in the environment variable APP_PORT
int port = Integer.parseInt(settings.getOrDefault("APP_PORT", "8081"));
// All URLs must be prefixed with the app name, which is got via the APP_NAME env var.
String appName = settings.getOrDefault("APP_NAME", "my-app");
String env = settings.getOrDefault("APP_ENV", "local"); // "prod" or "local"
boolean isLocal = "local".equals(env);
log.info("Starting " + appName + " in " + env + " on port " + port);
Server jettyServer = new Server(new InetSocketAddress("localhost", port));
jettyServer.setStopAtShutdown(true);
HandlerList handlers = new HandlerList();
// TODO: set your own handlers
handlers.addHandler(resourceHandler(isLocal));
// you must serve everything from a directory named after your app
ContextHandler ch = new ContextHandler();
ch.setContextPath("/" + appName);
ch.setHandler(handlers);
jettyServer.setHandler(ch);
try {
jettyServer.start();
} catch (Throwable e) {
log.error("Error on start", e);
System.exit(1);
}
log.info("Started app at http://localhost:" + port + ch.getContextPath());
jettyServer.join();
}
示例13: addStaticResources
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
public void addStaticResources(String basePath, String resourcePath) {
ContextHandler capHandler = new ContextHandler();
capHandler.setContextPath(basePath);
ResourceHandler resHandler = new ResourceHandler();
resHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
resHandler.setEtags(true);
resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL);
capHandler.setHandler(resHandler);
handlers.add(capHandler);
}
示例14: swaggerUI
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
private static ContextHandler swaggerUI() throws Exception {
final ResourceHandler swaggerUIResourceHandler = new ResourceHandler();
String swaggerui = HServer.class.getClassLoader().getResource("swaggerui").toURI().toString();
swaggerUIResourceHandler.setResourceBase(swaggerui);
final ContextHandler swaggerUIContext = new ContextHandler();
swaggerUIContext.setContextPath("/docs/");
swaggerUIContext.setHandler(swaggerUIResourceHandler);
return swaggerUIContext;
}
示例15: setupServer
import org.eclipse.jetty.server.handler.ContextHandler; //导入方法依赖的package包/类
private static Server setupServer() throws Exception {
// String webDir = "target/classes/webui";
// String webDir = "src/main/resources/webui";
String webDir = WebServer.class.getClassLoader().getResource("webui").toExternalForm();
log.info("Base webdir is {}", webDir);
int httpPort = ConfigFactory.load().getInt("resource-reporting.visualization.webui-port");
log.info("Resource reporting web ui port is ", httpPort);
// Create Jetty server
Server server = new Server(httpPort);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "filter.html" });
resource_handler.setResourceBase(webDir);
WebSocketHandler wsHandler = new WebSocketHandler.Simple(PubSubProxyWebSocket.class);
ContextHandler context = new ContextHandler();
context.setContextPath("/ws");
context.setHandler(wsHandler);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { context, resource_handler, new DefaultHandler() });
server.setHandler(handlers);
ClusterResources.subscribeToAll(callback);
return server;
}