當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。