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


Java NetworkConnector.getLocalPort方法代码示例

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


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

示例1: bindServer

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
/**
 * Bind method for the Jetty server. The test port is filled here.
 * 
 * @param server
 *            The Jetty server.
 */
public void bindServer(final Server server) {
    Connector[] connectors = server.getConnectors();
    for (int i = 0, n = connectors.length; (i < n) && (testPort == 0); i++) {
        if (connectors[i] instanceof NetworkConnector) {
            NetworkConnector networkConnector = (NetworkConnector) connectors[i];
            List<String> protocols = networkConnector.getProtocols();
            boolean httpAvailable = false;
            Iterator<String> protocolIterator = protocols.iterator();
            while (!httpAvailable && protocolIterator.hasNext()) {
                String protocol = protocolIterator.next();
                if (protocol.toLowerCase().startsWith("http")) {
                    httpAvailable = true;
                }
            }
            if (httpAvailable) {
                int localPort = networkConnector.getLocalPort();
                if (localPort > 0) {
                    testPort = localPort;
                }
            }
        }
    }
}
 
开发者ID:everit-org,项目名称:osgi-remote-jersey,代码行数:30,代码来源:JerseyExtenderTestComponent.java

示例2: startServer

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
@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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:RequestPartIntegrationTests.java

示例3: start

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
	this.jettyServer.start();

	Connector[] connectors = jettyServer.getConnectors();
	NetworkConnector connector = (NetworkConnector) connectors[0];
	this.port = connector.getLocalPort();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:JettyWebSocketTestServer.java

示例4: startJettyServer

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
@BeforeClass
public static void startJettyServer() throws Exception {

	// Let server pick its own random, available port.
	jettyServer = new Server(0);

	ServletContextHandler handler = new ServletContextHandler();
	byte[] bytes = helloWorld.getBytes("utf-8");
	handler.addServlet(new ServletHolder(new GetServlet(bytes, textContentType)), "/get");
	handler.addServlet(new ServletHolder(new GetServlet(new byte[0], textContentType)), "/get/nothing");
	handler.addServlet(new ServletHolder(new GetServlet(bytes, null)), "/get/nocontenttype");
	handler.addServlet(
			new ServletHolder(new PostServlet(helloWorld, "/post/1", bytes, textContentType)),
			"/post");
	handler.addServlet(
			new ServletHolder(new JsonPostServlet("/jsonpost/1", jsonContentType)),
			"/jsonpost");
	handler.addServlet(new ServletHolder(new StatusCodeServlet(204)), "/status/nocontent");
	handler.addServlet(new ServletHolder(new StatusCodeServlet(304)), "/status/notmodified");
	handler.addServlet(new ServletHolder(new ErrorServlet(404)), "/status/notfound");
	handler.addServlet(new ServletHolder(new ErrorServlet(500)), "/status/server");
	handler.addServlet(new ServletHolder(new UriServlet()), "/uri/*");
	handler.addServlet(new ServletHolder(new MultipartServlet()), "/multipart");
	handler.addServlet(new ServletHolder(new FormServlet()), "/form");
	handler.addServlet(new ServletHolder(new DeleteServlet()), "/delete");
	handler.addServlet(
			new ServletHolder(new PutServlet(helloWorld, bytes, textContentType)),
			"/put");

	jettyServer.setHandler(handler);
	jettyServer.start();

	Connector[] connectors = jettyServer.getConnectors();
	NetworkConnector connector = (NetworkConnector) connectors[0];
	port = connector.getLocalPort();
	baseUrl = "http://localhost:" + port;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:AbstractJettyServerTestCase.java

示例5: startJettyServer

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
@BeforeClass
public static void startJettyServer() throws Exception {

	// Let server pick its own random, available port.
	jettyServer = new Server(0);

	ServletContextHandler handler = new ServletContextHandler();
	handler.setContextPath("/");

	handler.addServlet(new ServletHolder(new EchoServlet()), "/echo");
	handler.addServlet(new ServletHolder(new ParameterServlet()), "/params");
	handler.addServlet(new ServletHolder(new StatusServlet(200)), "/status/ok");
	handler.addServlet(new ServletHolder(new StatusServlet(404)), "/status/notfound");
	handler.addServlet(new ServletHolder(new MethodServlet("DELETE")), "/methods/delete");
	handler.addServlet(new ServletHolder(new MethodServlet("GET")), "/methods/get");
	handler.addServlet(new ServletHolder(new MethodServlet("HEAD")), "/methods/head");
	handler.addServlet(new ServletHolder(new MethodServlet("OPTIONS")), "/methods/options");
	handler.addServlet(new ServletHolder(new PostServlet()), "/methods/post");
	handler.addServlet(new ServletHolder(new MethodServlet("PUT")), "/methods/put");
	handler.addServlet(new ServletHolder(new MethodServlet("PATCH")), "/methods/patch");

	jettyServer.setHandler(handler);
	jettyServer.start();

	Connector[] connectors = jettyServer.getConnectors();
	NetworkConnector connector = (NetworkConnector) connectors[0];
	baseUrl = "http://localhost:" + connector.getLocalPort();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:AbstractJettyServerTestCase.java

示例6: getPort

import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
public int getPort() {
  Connector[] connectors = server.getConnectors();
  NetworkConnector connector = (NetworkConnector) connectors[0];
  return connector.getLocalPort();
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:6,代码来源:ExampleServer.java


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