當前位置: 首頁>>代碼示例>>Java>>正文


Java Server.setConnectors方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.server.Server.setConnectors方法的典型用法代碼示例。如果您正苦於以下問題:Java Server.setConnectors方法的具體用法?Java Server.setConnectors怎麽用?Java Server.setConnectors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.server.Server的用法示例。


在下文中一共展示了Server.setConnectors方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: reverseProxy

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
private static void reverseProxy() throws Exception{
  Server server = new Server();

  SocketConnector connector = new SocketConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(8888);

  server.setConnectors(new Connector[]{connector});

  // Setup proxy handler to handle CONNECT methods
  ConnectHandler proxy = new ConnectHandler();
  server.setHandler(proxy);

  // Setup proxy servlet
  ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
  ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class);
  proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/");
  proxyServlet.setInitParameter("Prefix", "/");
  context.addServlet(proxyServlet, "/*");

  server.start();
}
 
開發者ID:tomkraljevic,項目名稱:jetty-embed-reverse-proxy-example,代碼行數:23,代碼來源:ProxyServer.java

示例2: run

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public void run(final int port) {
    try {
        final Server server = createServer();

        final ServletContextHandler context = new ServletContextHandler();
        context.setContextPath("/");
        server.setHandler(context);

        for (final MinijaxApplication application : applications) {
            addApplication(context, application);
        }

        final ServerConnector connector = createConnector(server);
        connector.setPort(port);
        server.setConnectors(new Connector[] { connector });
        server.start();
        server.join();

    } catch (final Exception ex) {
        throw new MinijaxException(ex);
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:23,代碼來源:Minijax.java

示例3: prepare

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:22,代碼來源:DashBoardServer.java

示例4: RestServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * Create a REST server for this herder using the specified configs.
 */
public RestServer(WorkerConfig config) {
    this.config = config;

    // To make the advertised port available immediately, we need to do some configuration here
    String hostname = config.getString(WorkerConfig.REST_HOST_NAME_CONFIG);
    Integer port = config.getInt(WorkerConfig.REST_PORT_CONFIG);

    jettyServer = new Server();

    ServerConnector connector = new ServerConnector(jettyServer);
    if (hostname != null && !hostname.isEmpty())
        connector.setHost(hostname);
    connector.setPort(port);
    jettyServer.setConnectors(new Connector[]{connector});
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:19,代碼來源:RestServer.java

示例5: createDevServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static Server createDevServer(int port, String contextPath) {

        Server server = new Server();
        server.setStopAtShutdown(true);

        ServerConnector connector = new ServerConnector(server);
        // 設置服務端口
        connector.setPort(port);
        connector.setReuseAddress(false);
        server.setConnectors(new Connector[] {connector});

        // 設置web資源根路徑以及訪問web的根路徑
        WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
        webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
        webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
        webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webAppCtx);

        return server;
    }
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:21,代碼來源:Launcher.java

示例6: createServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * 創建用於開發運行調試的JettyServer
 * @param port        訪問服務器的端口
 * @param contextPath 訪問服務器的地址
 * @param webAppPath  Web應用的目錄(需指向到WebRoot目錄下)
 */
private static Server createServer(int port, String contextPath, String webAppPath){
	Server server = new Server();
	//設置在JVM退出時關閉Jetty的鉤子
	//這樣就可以在整個功能測試時啟動一次Jetty,然後讓它在JVM退出時自動關閉
	server.setStopAtShutdown(true);
	//ServerConnector connector = new ServerConnector(server);
	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(port);
	//解決Windows下重複啟動Jetty不報告端口衝突的問題
	//在Windows下有個Windows + Sun的connector實現的問題,reuseAddress=true時重複啟動同一個端口的Jetty不會報錯
	//所以必須設為false,代價是若上次退出不幹淨(比如有TIME_WAIT),會導致新的Jetty不能啟動,但權衡之下還是應該設為False
	connector.setReuseAddress(false);
	server.setConnectors(new Connector[]{connector});
	//為了設置reuseAddress=false所以創建Connector,否則直接new Server(port)即可,通過查看Server源碼發現,二者是等效的
	//不過使用Connector的好處是可以讓Jetty監聽多個端口,此時創建多個綁定不同端口的Connector即可,最後一起setConnectors
	//Server server = new Server(port);
	//server.setStopAtShutdown(true);
	WebAppContext context = new WebAppContext(webAppPath, contextPath);
	//解決Windows環境下Lock靜態文件的問題
	//Jetty運行時會鎖住js、css等文件,導致不能修改保存,解決辦法是修改webdefault.xml中的useFileMappedBuffer=false
	//這裏試了很多遍都沒成功,後來注釋掉這裏的setDefaultsDescriptor(),也刪除項目中的webdefault-windows.xml
	//再重啟應用,竟然可以修改保存了,後來又反複重啟又試了幾次竟然都可以修改保存,很是奇怪
	//context.setDefaultsDescriptor("F:/Tool/Code/JavaSE/MyJettyDemo/test/webdefault-windows.xml");
	server.setHandler(context);
	return server;
}
 
開發者ID:v5java,項目名稱:demo-cas-server-web,代碼行數:33,代碼來源:JettyBootStrap.java

示例7: main

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        Server server = new Server();
        ServerConnector connector = new ServerConnector(server);
        connector.setPort(8080);
        server.setConnectors(new Connector[]{connector});

        WebAppContext context = new WebAppContext();
        context.setServer(server);
        context.setContextPath("/");
        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$");
        context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
        context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
        context.addBean(new ServletContainerInitializersStarter(context), true);

        // Prevent loading of logging classes
        context.getSystemClasspathPattern().add("org.apache.log4j.");
        context.getSystemClasspathPattern().add("org.slf4j.");
        context.getSystemClasspathPattern().add("org.apache.commons.logging.");

        ProtectionDomain protectionDomain = EmbeddedJettyServer.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();
        context.setWar(location.toExternalForm());

        server.setHandler(context);
        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:37,代碼來源:EmbeddedJettyServer.java

示例8: createServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
private static Server createServer(){
	Server server = new Server();
	server.setStopAtShutdown(true);
	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(port);
	connector.setReuseAddress(false);
	server.setConnectors(new Connector[]{connector});
	String webAppPath = JettyBootStrap.class.getClassLoader().getResource(".").getFile();
	webAppPath = webAppPath.substring(0, webAppPath.indexOf("target")) + "src/main/webapp";
	WebAppContext context = new WebAppContext(webAppPath, contextPath);
	server.setHandler(context);
	return server;
}
 
開發者ID:v5java,項目名稱:demo-springmvc-shiro,代碼行數:15,代碼來源:JettyBootStrap.java

示例9: configServer

import org.eclipse.jetty.server.Server; //導入方法依賴的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);
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:16,代碼來源:ResourceHttpServer.java

示例10: startServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
private void startServer() throws Exception {

        log.info("Starting http server on port " + httpPort);
        Server server = new Server(new QueuedThreadPool(threadCount));
        ServerConnector serverConnector = new ServerConnector(server);
        serverConnector.setPort(httpPort);
        if (!Strings.isNullOrEmpty(httpBindAddress)) {
            serverConnector.setHost(httpBindAddress);
        }
        server.setConnectors(new Connector[]{serverConnector});
        ServletContextHandler context = new ServletContextHandler();
        context.setMaxFormContentSize(maxFormContextSizeBytes);
        context.setContextPath("/");

        ServletHolder metricSearchServletHolder = new ServletHolder(metricSearchServlet);
        context.addServlet(metricSearchServletHolder, "/search/*");
        context.addServlet(metricSearchServletHolder, "/ban/*");
        context.addServlet(metricSearchServletHolder, "/multiBan/*");
        context.addServlet(metricSearchServletHolder, "/approve/*");
        context.addServlet(metricSearchServletHolder, "/multiApprove/*");
        context.addServlet(metricSearchServletHolder, "/hide/*");
        context.addServlet(metricSearchServletHolder, "/multiHide/*");

        ServletHolder monitoringServletHolder = new ServletHolder(monitoringServlet);
        context.addServlet(monitoringServletHolder, "/ping");
        context.addServlet(monitoringServletHolder, "/monitoring");

        ServletHolder metricDataServletHolder = new ServletHolder(metricDataServiceServlet);
        context.addServlet(metricDataServletHolder, "/metricData");

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
        server.setHandler(handlers);
        server.start();

        log.info("Web server started on port " + httpPort);
    }
 
開發者ID:yandex,項目名稱:graphouse,代碼行數:38,代碼來源:GraphouseWebServer.java

示例11: startServer

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * Method for starting the Jetty server with the ATS Agent webapp.
 * @param port the port on which to start the server.
 * @return the started server.
 * @throws IOException
 */
private static Server startServer() throws IOException {

    addAppender();

    final int agentPort = getAgentDefaultPort();
    log.info("Starting ATS agent at port: " + agentPort);

    final String jettyHome = getJettyHome();

    logSystemInformation(jettyHome);

    // start the server
    Connector connector = new SelectChannelConnector();
    connector.setPort(agentPort);

    Server server = new Server();
    server.setConnectors(new Connector[]{ connector });

    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/agentapp");
    webApp.setWar(jettyHome + "/webapp/agentapp.war");

    server.setHandler(webApp);
    server.setStopAtShutdown(true);

    setExtraClasspath(webApp, jettyHome);

    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    log.info("ATS agent started");
    return server;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:44,代碼來源:ContainerStarter.java

示例12: get

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public Server get() {
  Server server = new Server();
  server.setHandler(serverHandler);
  server.setConnectors(connectors.stream().map(cf -> cf.get(server)).toArray(Connector[]::new));

  return server;
}
 
開發者ID:sorskod,項目名稱:webserver,代碼行數:8,代碼來源:JettyServerProvider.java

示例13: init

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * Method used to initialize and start the SSE server
 */
public static void init()
{
	Server server = new Server();
	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(8070);
	connector.setAcceptors(3);
	connector.setThreadPool(new QueuedThreadPool(50));
	connector.setMaxIdleTime(72*60*60*1000);
	connector.setAcceptQueueSize(50000);
	connector.setRequestBufferSize(50000);
	connector.setResponseBufferSize(50000);
	server.setConnectors(new Connector[] { connector });
	ServletContextHandler context = new ServletContextHandler(
			ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	//context.setResourceBase(System.getProperty("java.io.tmpdir"));

	ServletHolder requestServletHolder = new ServletHolder(EventServer.class);
	context.addServlet(requestServletHolder, "/response");

	ServletHolder notificationServletHolder = new ServletHolder(NotificationServer.class);
	context.addServlet(notificationServletHolder, "/notification");


	server.setHandler(context);
	context.addEventListener(new ConfigureService());
	context.addEventListener(new NotificationService());

	try {
		server.start();
		LOG.info("Server Started");
		server.join();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}


}
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:43,代碼來源:JettyServer.java

示例14: start

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
public void start(boolean devMode, int port) throws Exception {

        Server server = new Server(new QueuedThreadPool(500));

        WebAppContext appContext = new WebAppContext();

        String resourceBasePath = "";
        //開發者模式
        if (devMode) {
            String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
            resourceBasePath = artifact + "/src/main/webapp";
        }
        appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml");
        appContext.setResourceBase(resourceBasePath);
        appContext.setExtractWAR(true);

        //init param
        appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        if (CommonUtils.isWindowOs()) {
            appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        }

        //for jsp support
        appContext.addBean(new JettyJspParser(appContext));
        appContext.addServlet(JettyJspServlet.class, "*.jsp");

        appContext.setContextPath("/");
        appContext.getServletContext().setExtendedListenerTypes(true);
        appContext.setParentLoaderPriority(true);
        appContext.setThrowUnavailableOnStartupException(true);
        appContext.setConfigurationDiscovered(true);
        appContext.setClassLoader(Thread.currentThread().getContextClassLoader());

        ServerConnector connector = new ServerConnector(server);
        connector.setHost("0.0.0.0");
        connector.setPort(port);
        server.setConnectors(new Connector[]{connector});
        server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024);
        server.setDumpAfterStart(false);
        server.setDumpBeforeStop(false);
        server.setStopAtShutdown(true);
        server.setHandler(appContext);
        logger.info("[opencron] JettyLauncher starting...");
        server.start();
    }
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:46,代碼來源:JettyLauncher.java

示例15: setUp

import org.eclipse.jetty.server.Server; //導入方法依賴的package包/類
/**
 * Set up server with handler
 *
 * @param handler
 * @return port
 * @throws Exception
 */
public static String setUp(final Handler handler) throws Exception {
  server = new Server();
  if (handler != null)
    server.setHandler(handler);
  Connector connector = new SelectChannelConnector();
  connector.setPort(0);
  server.setConnectors(new Connector[] { connector });
  server.start();

  proxy = new Server();
  Connector proxyConnector = new SelectChannelConnector();
  proxyConnector.setPort(0);
  proxy.setConnectors(new Connector[] { proxyConnector });

  ServletHandler proxyHandler = new ServletHandler();

  RequestHandler proxyCountingHandler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      proxyHitCount.incrementAndGet();
      String auth = request.getHeader("Proxy-Authorization");
      auth = auth.substring(auth.indexOf(' ') + 1);
      try {
        auth = B64Code.decode(auth, CHARSET_UTF8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      int colon = auth.indexOf(':');
      proxyUser.set(auth.substring(0, colon));
      proxyPassword.set(auth.substring(colon + 1));
      request.setHandled(false);
    }
  };

  HandlerList handlerList = new HandlerList();
  handlerList.addHandler(proxyCountingHandler);
  handlerList.addHandler(proxyHandler);
  proxy.setHandler(handlerList);

  ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
  proxyHolder.setAsyncSupported(true);

  proxy.start();

  proxyPort = proxyConnector.getLocalPort();

  return "http://localhost:" + connector.getLocalPort();
}
 
開發者ID:junicorn,項目名稱:NiuBi,代碼行數:57,代碼來源:ServerTestCase.java


注:本文中的org.eclipse.jetty.server.Server.setConnectors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。