本文整理汇总了Java中org.eclipse.jetty.server.ServerConnector类的典型用法代码示例。如果您正苦于以下问题:Java ServerConnector类的具体用法?Java ServerConnector怎么用?Java ServerConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerConnector类属于org.eclipse.jetty.server包,在下文中一共展示了ServerConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JettyAdminServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
public JettyAdminServer(String address, int port, int timeout, String commandUrl) {
this.port = port;
this.idleTimeout = timeout;
this.commandUrl = commandUrl;
this.address = address;
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setHost(address);
connector.setPort(port);
connector.setIdleTimeout(idleTimeout);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/*");
server.setHandler(context);
context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*");
}
示例2: jettyServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@Bean
public Server jettyServer(ApplicationContext context) throws Exception {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
Servlet servlet = new JettyHttpHandlerAdapter(handler);
Server server = new Server();
ServletContextHandler contextHandler = new ServletContextHandler(server, "");
contextHandler.addServlet(new ServletHolder(servlet), "/");
contextHandler.start();
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(port);
server.addConnector(connector);
return server;
}
示例3: beforeClass
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
jettyServer = new Server(0);
WebAppContext webApp = new WebAppContext();
webApp.setServer(jettyServer);
webApp.setContextPath(CONTEXT_PATH);
webApp.setWar("src/test/webapp");
jettyServer.setHandler(webApp);
jettyServer.start();
serverPort = ((ServerConnector)jettyServer.getConnectors()[0]).getLocalPort();
testRestTemplate = new TestRestTemplate(new RestTemplateBuilder()
.rootUri("http://localhost:" + serverPort + CONTEXT_PATH));
}
示例4: customize
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@Override
public void customize(Server server) {
// HTTPS Configuration
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(8443);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// SSL Context Factory for HTTPS and HTTP/2
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, "h2");
// HTTP/2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, new HTTP2ServerConnectionFactory(httpsConfig));
http2Connector.setPort(8443);
server.addConnector(http2Connector);
}
示例5: start
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
public void start(int listenPort, String dbname) throws Exception {
if (Objects.nonNull(server) && server.isRunning()) {
LOG.info("ineternal webui already running at port [" + listenPort + "].");
throw new Exception("already running at port[" + listenPort + "]");
}
// remove old connectors
Connector[] oldConnectors = server.getConnectors();
if (Objects.nonNull(oldConnectors)) {
for (Connector oldc : oldConnectors) {
server.removeConnector(oldc);
}
}
// add new connector
ServerConnector connector = new ServerConnector(server);
connector.setPort(listenPort);
server.setConnectors(new Connector[] { connector });
// set dbname
ServletContextHandler contextHandler = (ServletContextHandler) server.getHandler();
contextHandler.setAttribute("dbname", dbname);
server.start();
LOG.info("internal webui server started with listening port [" + listenPort + "].");
}
示例6: startJetty
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private void startJetty() throws Exception {
QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
Server server = new Server(jettyThreadPool);
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
http.setPort(jettyListenPort);
server.addConnector(http);
ContextHandler contextHandler = new ContextHandler();
contextHandler.setHandler(botSocketHandler);
server.setHandler(contextHandler);
server.start();
server.join();
}
示例7: LegacyHttpServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private LegacyHttpServer(int port, int threads) {
this.server = new Server(new QueuedThreadPool(threads));
server.setHandler(
new AbstractHandler() {
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException {
final String method = baseRequest.getParameter("method");
if ("helloworld.Greeter/SayHello".equals(method)) {
baseRequest.setHandled(true);
sayHello(baseRequest, response);
}
}
});
final ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
}
示例8: setUp
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Jetty [Configuring]");
ServletContextHandler servletContext = new ServletContextHandler();
servletContext.setContextPath("/");
servletContext.addServlet(PingPongServlet.class, PingPongServlet.PATH);
servletContext.addServlet(ExceptionServlet.class, ExceptionServlet.PATH);
ServletHolder servletHolder = servletContext.addServlet(AsyncServlet.class, AsyncServlet.PATH);
servletHolder.setAsyncSupported(true);
jetty = new Server(0);
jetty.setHandler(servletContext);
System.out.println("Jetty [Starting]");
jetty.start();
System.out.println("Jetty [Started]");
serverPort = ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
}
示例9: attachServerConnector
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
/**
* Attaches a server connector listening on the specified port to the server. Further the connector
* is hooked into the configuration system to received runtime port changes
*
* @param server
* the Jetty server
*
* @return the created conector
*/
private static ServerConnector attachServerConnector(final Server server) {
int initialHttpPort = Configuration.getInteger("jetty.http.port", 8080);
//TODO config set accept queue size
//TODO config acceptor num
//TODO config selector num
//TODO config idle timeout
final ServerConnector connector = new ServerConnector(server);
connector.setPort(initialHttpPort);
server.addConnector(connector);
Configuration.addListener(ConfigChangeListener.forConfigProperty("jetty.http.port", (k, v) -> {
LOG.info("Changing http port to " + v);
connector.setPort(Integer.parseInt(v));
try {
connector.stop();
connector.start();
LOG.info("HTTP Port changed");
} catch (Exception e) {
LOG.log(Level.SEVERE, "Restarting connector failed", e);
}
}));
return connector;
}
示例10: extractTableRowForDefaultServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private static List<ApplicationUrlsGenerator> extractTableRowForDefaultServer(Environment environment, ServerConnector connector) {
String protocol = connector.getDefaultProtocol();
int port = connector.getLocalPort();
if ("admin".equals(connector.getName())) {
String adminContextPath = environment.getAdminContext().getContextPath();
return ImmutableList.of(
new ApplicationUrlsGenerator(ADMIN_URL_TYPE, isHttps(protocol), port, adminContextPath),
new ApplicationUrlsGenerator(HEALTHCHECK_URL_TYPE, isHttps(protocol), port, adminContextPath)
);
}
return ImmutableList.of(
new ApplicationUrlsGenerator(APPLICATION_URL_TYPE, isHttps(protocol), port, environment.getApplicationContext().getContextPath())
);
}
示例11: extractRowsForSimpleServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private static List<ApplicationUrlsGenerator> extractRowsForSimpleServer(Environment environment, ServerConnector connector) {
return ImmutableList.of(
new ApplicationUrlsGenerator(
APPLICATION_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getApplicationContext().getContextPath()
),
new ApplicationUrlsGenerator(
ADMIN_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getAdminContext().getContextPath()
),
new ApplicationUrlsGenerator(
HEALTHCHECK_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getAdminContext().getContextPath()
)
);
}
示例12: run
import org.eclipse.jetty.server.ServerConnector; //导入依赖的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);
}
}
示例13: createConnector
import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
/**
* Creates a server connector.
*
* If an HTTPS key store is configured, returns a SSL connector for HTTPS.
*
* Otherwise, returns a normal HTTP connector by default.
*
* @param server The server.
* @return The server connector.
*/
@SuppressWarnings("squid:S2095")
private ServerConnector createConnector(final Server server) {
final String keyStorePath = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PATH);
if (keyStorePath == null || keyStorePath.isEmpty()) {
// Normal HTTP
return new ServerConnector(server);
}
final String keyStorePassword = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PASSWORD);
final String keyManagerPassword = (String) configuration.get(MinijaxProperties.SSL_KEY_MANAGER_PASSWORD);
final HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(Minijax.class.getClassLoader().getResource(keyStorePath).toExternalForm());
sslContextFactory.setKeyStorePassword(keyStorePassword);
sslContextFactory.setKeyManagerPassword(keyManagerPassword);
return new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, "http/1.1"),
new HttpConnectionFactory(https));
}
示例14: prepare
import org.eclipse.jetty.server.ServerConnector; //导入依赖的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);
}
}
示例15: RestServer
import org.eclipse.jetty.server.ServerConnector; //导入依赖的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});
}