本文整理汇总了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;
}
}
}
}
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例6: getPort
import org.eclipse.jetty.server.NetworkConnector; //导入方法依赖的package包/类
public int getPort() {
Connector[] connectors = server.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
return connector.getLocalPort();
}