当前位置: 首页>>代码示例>>Java>>正文


Java ServletContextHandler.setResourceBase方法代码示例

本文整理汇总了Java中org.eclipse.jetty.servlet.ServletContextHandler.setResourceBase方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextHandler.setResourceBase方法的具体用法?Java ServletContextHandler.setResourceBase怎么用?Java ServletContextHandler.setResourceBase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.servlet.ServletContextHandler的用法示例。


在下文中一共展示了ServletContextHandler.setResourceBase方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void run() throws Exception {
	org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
	Server server = new Server(port);
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setWelcomeFiles(new String[]{ "demo.html" });
       context.setResourceBase(httpPath);
       HashSessionIdManager idmanager = new HashSessionIdManager();
       server.setSessionIdManager(idmanager);
       HashSessionManager manager = new HashSessionManager();
       SessionHandler sessions = new SessionHandler(manager);
       sessions.setHandler(context);
       context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
       ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
       context.addServlet(holderPwd,"/*");
       server.setHandler(sessions);
       server.start();
       server.join();
}
 
开发者ID:punkbrwstr,项目名称:pinto,代码行数:20,代码来源:Demo.java

示例2: run

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void run() throws Exception {

		org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
		Server server = new Server(port);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(httpPath);
        HashSessionIdManager idmanager = new HashSessionIdManager();
        server.setSessionIdManager(idmanager);
        HashSessionManager manager = new HashSessionManager();
        SessionHandler sessions = new SessionHandler(manager);
        sessions.setHandler(context);
        context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
        ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
        context.addServlet(holderPwd,"/*");
        server.setHandler(sessions);
		new Thread(new Console(getPinto(),port,build, () -> {
			try {
				server.stop();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}), "console_thread").start();
        server.start();
        server.join();
	}
 
开发者ID:punkbrwstr,项目名称:pinto,代码行数:27,代码来源:Main.java

示例3: run

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void run() {
	ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
	servletContextHandler.setContextPath("/");
	servletContextHandler.setResourceBase("./res");
	servletContextHandler.addFilter(CommonFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));//增加过滤器
	servletContextHandler.addServlet(LoginServlet.class, "/login.cgi");
	servletContextHandler.addServlet(UserinfoServlet.class, "/userinfo.cgi");
	servletContextHandler.addServlet(FileBrowseServlet.class, "/file_browse.cgi");
	servletContextHandler.addServlet(DefaultServlet.class, "/");
	servletContextHandler.addServlet(ChangePassword.class, "/changepassword.cgi");
	servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/device/add_device_to_group.cgi");
	servletContextHandler.addServlet(AddGroupServlet.class, "/group/add_group.cgi");
	servletContextHandler.addServlet(GetGroupsServlet.class	, "/group/get_groups.cgi");
	servletContextHandler.addServlet(EditGroupServlet.class, "/group/edit_group.cgi");
	servletContextHandler.addServlet(GetAllGroupsServlet.class, "/group/get_all_groups.cgi");
	servletContextHandler.addServlet(DeteleGroupServlet.class, "/group/delete_group.cgi");
	servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/group/add_device_to_group.cgi");
	servletContextHandler.addServlet(DeleteDeviceFromGroupServlet.class,"/group/delete_device_from_group.cgi");
	
	ServletHolder fileUploadServletHolder = new ServletHolder(new UploadServlet());
	fileUploadServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(System.getProperty("user.dir") +JettyConfig.UPLOAD_TMP_PATH));
	servletContextHandler.addServlet(fileUploadServletHolder, "/upload.cgi");
	
	servletContextHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
       
       server.setHandler(servletContextHandler);
       try {
		server.start();
		server.join();
		
	} catch (Exception e) {
		logger.error("",e);
	}
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:35,代码来源:JettyServer.java

示例4: start

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public synchronized void start(int port, boolean join) throws Exception {
	
	if(server != null) {
		throw new IllegalStateException("Server is already running");
	}
	
	Guice.createInjector(sm);

	//Swagger
	String resourceBasePath = Main.class.getResource("/swagger-ui").toExternalForm();
	this.server = new Server(port);
	
	ServletContextHandler context = new ServletContextHandler();
	context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
	context.setResourceBase(resourceBasePath);
	context.setWelcomeFiles(new String[] { "index.html" });
	
	server.setHandler(context);


	DefaultServlet staticServlet = new DefaultServlet();
	context.addServlet(new ServletHolder(staticServlet), "/*");
	
	server.start();
	System.out.println("Started server on http://localhost:" + port + "/");
	try {
		boolean create = Boolean.getBoolean("loadSample");
		if(create) {
			System.out.println("Creating kitchensink workflow");
			createKitchenSink(port);
		}
	}catch(Exception e) {
		logger.error(e.getMessage(), e);
	}
	
	if(join) {
		server.join();
	}

}
 
开发者ID:Netflix,项目名称:conductor,代码行数:41,代码来源:ConductorServer.java

示例5: createContext

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
protected void createContext( Server server, File repositoryDirectory )
    throws IOException
{
    ServletContextHandler context = new ServletContextHandler();
    context.setResourceBase( repositoryDirectory.getAbsolutePath() );
    context.setContextPath( "/" );
    ServletHolder sh = new ServletHolder( DefaultServlet.class );
    context.addServlet( sh, "/" );
    server.setHandler( context );

}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:12,代码来源:DownloadRemoteIndexTaskTest.java

示例6: WebUIApp

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public WebUIApp() throws IOException {
    server = new Server();

    AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    springContext.setClassLoader(this.getClass().getClassLoader());
    springContext.setConfigLocation("com.sst.burpextender.proxyhistory.webui.springmvc.config");

    DispatcherServlet dispatcherServlet = new DispatcherServlet(springContext);
    ServletHolder springServletHolder = new ServletHolder("mvc-dispatcher", dispatcherServlet);

    // ref: https://github.com/bkielczewski/example-spring-mvc-jetty
    // ref: https://github.com/fernandospr/spring-jetty-example
    ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath("/");
    contextHandler.addServlet(springServletHolder, "/*");
    contextHandler.addEventListener(new ContextLoaderListener(springContext));
    contextHandler.setResourceBase(new ClassPathResource("/webui", WebUIApp.class).getURI().toString());

    /* NOTE: Burp Extender において、 burp.BurpExtender については jar をロードしたclass loader内で実行される。
     * 一方、Tabなど独自のUIを追加した場合は、UIから呼ばれるコードはBurp自身のclass loader内で実行される。
     * つまり、Webアプリのstart/stopをBurp上に追加したUIからそのまま = Swingのスレッド内から呼び出す場合、
     * その一連の過程で使われるclass loaderはburp自身のものであり、
     * 「Burp Extender の jar 内のclassを見つけることができない。」
     * # 実際に見てみると、Thread.currentThread().getContextClassLoader() が sun.misc.Launcher$AppClassLoader となる.
     * 
     * その結果として、特に何の手当もしなかった場合、以下のような様々な、予期せぬclass loading関連の例外に遭遇する。
     * - Spring で setConfigLocation() で指定したパッケージがスキャンされない。
     * - Spring で @ComponentScan(basePackages = xxx) で指定したパッケージがスキャンされない。
     * ==> 結果として Spring MVC の初期化時に "No annotated classes found for specified class/package" のログが出力される。
     * - Spring + Thymeleaf 内部でのSpring EL式の生成で class not found 例外発生
     * 
     * そこで、Jetty側のレベルでclass loaderをカスタマイズする。
     * 本クラスのインスタンスをロードした class loader であれば、Burp Extender の jar をロードしているので、それを使うようにする。
     * これにより、Spring の annotation class のスキャンや、Spring MVC 内部で発生する様々な class loading が本来の形で動作するようになる。
     */
    contextHandler.setClassLoader(this.getClass().getClassLoader());

    CharacterEncodingFilter utf8Filter = new CharacterEncodingFilter();
    utf8Filter.setEncoding("UTF-8");
    utf8Filter.setForceEncoding(true);
    FilterHolder filterHolder = new FilterHolder(utf8Filter);
    EnumSet<DispatcherType> allDispatcher = EnumSet.of(
        DispatcherType.ASYNC,
        DispatcherType.ERROR,
        DispatcherType.FORWARD,
        DispatcherType.INCLUDE,
        DispatcherType.REQUEST);
    contextHandler.addFilter(filterHolder, "/*", allDispatcher);

    server.setHandler(contextHandler);
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:53,代码来源:WebUIApp.java

示例7: initJettyServer

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private void initJettyServer() {
    InetSocketAddress address = new InetSocketAddress(config.getHost(), config.getPort());
    jettyServer = new Server(address);

    handler = new ServletContextHandler();
    handler.setContextPath(config.getContextPath());
    handler.setClassLoader(new JbootServerClassloader(JettyServer.class.getClassLoader()));
    handler.setResourceBase(getRootClassPath());

    JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
    if (shiroConfig.isConfigOK()) {
        handler.addEventListener(new EnvironmentLoaderListener());
        handler.addFilter(ShiroFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    }

    //JFinal
    FilterHolder jfinalFilter = handler.addFilter(JFinalFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    jfinalFilter.setInitParameter("configClass", Jboot.me().getJbootConfig().getJfinalConfig());

    JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
    if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
        handler.addServlet(HystrixMetricsStreamServlet.class, hystrixConfig.getUrl());
    }


    JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
    if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
        handler.addEventListener(new JbootMetricServletContextListener());
        handler.addEventListener(new JbootHealthCheckServletContextListener());
        handler.addServlet(AdminServlet.class, metricsConfig.getUrl());
    }

    io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
    ContextListeners listeners = new ContextListeners();

    JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);


    for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
        for (String path : entry.getValue().getUrlMapping()) {
            handler.addServlet(entry.getValue().getServletClass(), path);
        }
    }


    for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
        handler.addEventListener(ClassKits.newInstance(listenerClass));
    }

    jettyServer.setHandler(handler);
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:52,代码来源:JettyServer.java

示例8: main

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
/**
 * Server starter to initialize the server.
 * @param args
 */
public static void main(String[] args) {
    Server server = new Server(PORT);
    ServletContextHandler servhandler = new ServletContextHandler(ServletContextHandler.SESSIONS);

    VelocityEngine velocity = new VelocityEngine();
    velocity.init();

    servhandler.setResourceBase(DIR);
    servhandler.setContextPath("/");
    servhandler.setAttribute("templateEngine", velocity);

    servhandler.addServlet(IndexServlet.class, "/index");
    servhandler.addServlet(HotelServlet.class, "/hotel");
    servhandler.addServlet(CategoryServlet.class, "/category");
    servhandler.addServlet(CityServlet.class, "/city");
    servhandler.addServlet(PageServlet.class, "/page");
    servhandler.addServlet(HotelDetailServlet.class, "/hotelDetail");
    servhandler.addServlet(ReviewServlet.class, "/review");
    servhandler.addServlet(LikeServlet.class, "/like");
    servhandler.addServlet(ReviewModalServlet.class, "/reviewmodal");
    servhandler.addServlet(ShowLikeServlet.class, "/showlike");
    servhandler.addServlet(AttractionServlet.class, "/attraction");
    servhandler.addServlet(MyPageServlet.class, "/mypage");
    servhandler.addServlet(ClearServlet.class, "/clear");
    server.setHandler(servhandler);

    ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
    holderPwd.setInitParameter("dirAllowed","false");
    servhandler.addServlet(holderPwd,"/");

    System.out.println("Starting server on port " + PORT + "...");

    try {
        server.start();
        server.join();

        System.out.println("Exiting...");
    }
    catch (Exception ex) {
        System.out.println("Interrupted while running server. " + ex);
        System.exit(-1);
    }
}
 
开发者ID:brianisadog,项目名称:hotelApp,代码行数:48,代码来源:JettyServer.java

示例9: main

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
/**
 * Run the Wikipedia application.
 *
 * @param args  command line arguments
 * @throws Exception if the server fails to start or crashes
 */
public static void main(String[] args) throws Exception {
    int port = 9998;

    Server server = new Server(port);
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);

    servletContextHandler.addEventListener(new MetricServletContextListener());
    servletContextHandler.addEventListener(new HealthCheckServletContextListener());

    servletContextHandler.setContextPath("/");
    servletContextHandler.setResourceBase("src/main/webapp");

    //Activate codahale metrics
    FilterHolder instrumentedFilterHolder = new FilterHolder(InstrumentedFilter.class);
    instrumentedFilterHolder.setName("instrumentedFilter");
    instrumentedFilterHolder.setAsyncSupported(true);
    servletContextHandler.addFilter(instrumentedFilterHolder, "/*", EnumSet.noneOf(DispatcherType.class));

    // Static resource handler
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setResourceBase("src/main/webapp");

    // Add the handlers to the server
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resourceHandler, servletContextHandler });
    server.setHandler(handlers);

    ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/v1/*");
    servletHolder.setInitOrder(1);
    servletHolder.setInitParameter(
            "javax.ws.rs.Application",
            "com.yahoo.bard.webservice.application.ResourceConfig");
    servletHolder.setInitParameter(
            "jersey.config.server.provider.packages",
            "com.yahoo.bard.webservice.web.endpoints");

    servletContextHandler.addServlet(AdminServlet.class, "/*");

    server.start();

    markDimensionCacheHealthy(port);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:50,代码来源:WikiMain.java

示例10: main

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
/**
 * Run a generic setup which mirrors all information from druid into fili configuration.
 *
 * @param args  Command line arguments.
 *
 * @throws Exception if the server fails to start or crashes.
 */
public static void main(String[] args) throws Exception {
    int port = SYSTEM_CONFIG.getIntProperty(FILI_PORT);

    Server server = new Server(port);
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);

    servletContextHandler.addEventListener(new MetricServletContextListener());
    servletContextHandler.addEventListener(new HealthCheckServletContextListener());

    servletContextHandler.setContextPath("/");
    servletContextHandler.setResourceBase("src/main/webapp");

    //Activate codahale metrics
    FilterHolder instrumentedFilterHolder = new FilterHolder(InstrumentedFilter.class);
    instrumentedFilterHolder.setName("instrumentedFilter");
    instrumentedFilterHolder.setAsyncSupported(true);
    servletContextHandler.addFilter(instrumentedFilterHolder, "/*", EnumSet.noneOf(DispatcherType.class));

    // Static resource handler
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setResourceBase("src/main/webapp");

    // Add the handlers to the server
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resourceHandler, servletContextHandler});
    server.setHandler(handlers);

    ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/v1/*");
    servletHolder.setInitOrder(1);
    servletHolder.setInitParameter(
            "javax.ws.rs.Application",
            "com.yahoo.bard.webservice.application.ResourceConfig"
    );
    servletHolder.setInitParameter(
            "jersey.config.server.provider.packages",
            "com.yahoo.bard.webservice.web.endpoints"
    );

    servletContextHandler.addServlet(AdminServlet.class, "/*");

    server.start();
}
 
开发者ID:yahoo,项目名称:fili,代码行数:51,代码来源:GenericMain.java


注:本文中的org.eclipse.jetty.servlet.ServletContextHandler.setResourceBase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。