本文整理汇总了Java中org.eclipse.jetty.server.ServerConnector.setHost方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConnector.setHost方法的具体用法?Java ServerConnector.setHost怎么用?Java ServerConnector.setHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.ServerConnector
的用法示例。
在下文中一共展示了ServerConnector.setHost方法的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: 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});
}
示例4: setUp
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
PullHttpChangeIngestorCommonTest.init();
final ServerConnector http = new ServerConnector(jetty);
http.setPort(0);
http.setHost("localhost");
http.setIdleTimeout(3000L);
jetty.addConnector(http);
jetty.start();
Thread.sleep(1000);
if (!jetty.isStarted()) {
throw new IllegalStateException("Jetty server not started");
}
}
示例5: JettyHttpTestServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public JettyHttpTestServer(String host, int port){
this.host = host;
this.port = port;
server = new Server();
ServerConnector http = new ServerConnector(server);
http.setHost(host);
http.setPort(port);
http.setIdleTimeout(30000);
server.addConnector(http);
server.setHandler(new RequestHandler());
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
this.port = http.getLocalPort();
}
示例6: start
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public void start() {
try {
final ServerConnector httpConnector = new ServerConnector(server);
httpConnector.setHost(root.host);
httpConnector.setPort(root.port);
httpConnector.setIdleTimeout(config.getInt("web.idle-timeout"));
server.addConnector(httpConnector);
final HandlerList handlers = new HandlerList();
handlers.addHandler(inContext("/static", newResourcesHandler()));
handlers.addHandler(inContext("/", new RootHandler(version, routes)));
server.setHandler(handlers);
server.start();
log.info("Web Server started on http://" + root.host + ":" + root.port);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
throw new RuntimeException(ex);
}
}
示例7: installListeners
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private static void installListeners(Server server, Collection<? extends InetSocketAddress> addresses) {
final List<Connector> connectors = new ArrayList<>(addresses.size());
for (InetSocketAddress address : addresses) {
final ServerConnector server_connector = new ServerConnector(server);
server_connector.setReuseAddress(true);
if (address.getAddress() != null) {
if (!address.getAddress().isAnyLocalAddress()) {
LOG.log(Level.INFO, "Binding API server address: {0}", address.getAddress().getHostAddress());
server_connector.setHost(address.getAddress().getHostAddress());
}
} else if (address.getHostString() != null) {
LOG.log(Level.INFO, "Binding API server address name: {0}", address.getHostString());
server_connector.setHost(address.getHostString());
}
LOG.log(Level.INFO, "Binding API server port: {0}", address.getPort());
server_connector.setPort(address.getPort());
connectors.add(server_connector);
}
server.setConnectors(connectors.toArray(new Connector[connectors.size()]));
}
示例8: jettyServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
/** Build a Jetty server */
private static Server jettyServer(int port, boolean loopback) {
Server server = new Server() ;
HttpConnectionFactory f1 = new HttpConnectionFactory() ;
// Some people do try very large operations ... really, should use POST.
f1.getHttpConfiguration().setRequestHeaderSize(512 * 1024);
f1.getHttpConfiguration().setOutputBufferSize(5 * 1024 * 1024) ;
// Do not add "Server: Jetty(....) when not a development system.
if ( true )
f1.getHttpConfiguration().setSendServerVersion(false) ;
ServerConnector connector = new ServerConnector(server, f1) ;
connector.setPort(port) ;
server.addConnector(connector);
if ( loopback )
connector.setHost("localhost");
return server ;
}
示例9: setUp
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
component = new WebsocketComponent();
component.setCamelContext(new DefaultCamelContext());
System.out.println("Server : " + server.isStarted());
server = component.createServer();
System.out.println("Server : " + server.isStarted());
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(1988);
server.addConnector(connector);
WebsocketEndpoint endpoint = (WebsocketEndpoint) component.createEndpoint("websocket://x");
producer = (WebsocketProducer) endpoint.createProducer();
component.connect(producer);
// wire the consumer with the endpoint so that WebSocketComponent.getConnectorKey() works without throwing NPE
when(consumer.getEndpoint()).thenReturn(endpoint);
}
示例10: startServer
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的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);
}
示例11: get
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@Override
public ServerConnector get(Server server) {
HttpConfiguration configuration = new HttpConfiguration(defaultConfig);
configuration.setSecurePort(configurator.getPort());
configuration.setSecureScheme(HttpScheme.HTTPS.asString());
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(configuration));
connector.setPort(configurator.getPort());
connector.setHost(configurator.getHost());
return connector;
}
示例12: get
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public ServerConnector get(Server server) {
HttpConfiguration configuration = new HttpConfiguration(defaultConfig);
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(configuration));
connector.setPort(configurator.getPort());
connector.setHost(configurator.getHost());
return connector;
}
示例13: createConnector
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private void createConnector(Properties properties) {
final ServerConnector http = new ServerConnector(jetty);
http.setPort(Integer.parseInt(properties.getProperty(PORT_KEY, "0")));
http.setHost(properties.getProperty(HOST_KEY, "localhost"));
// Severely taxed or distant environments may have significant delays when executing.
http.setIdleTimeout(30000L);
jetty.addConnector(http);
logger.info("Added an http connector on the host '{}' and port '{}'", new Object[]{http.getHost(), http.getPort()});
}
示例14: setUp
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
PullHttpChangeIngestorCommonTest.init();
SslContextFactory ssl = new SslContextFactory();
ssl.setKeyStorePath("./src/test/resources/localhost-ks.jks");
ssl.setKeyStorePassword("localtest");
ssl.setKeyStoreType("JKS");
ssl.setTrustStorePath("./src/test/resources/localhost-ts.jks");
ssl.setTrustStorePassword("localtest");
ssl.setTrustStoreType("JKS");
ssl.setNeedClientAuth(true);
// build the connector
final ServerConnector https = new ServerConnector(jetty, ssl);
// set host and port
https.setPort(0);
https.setHost("localhost");
// Severely taxed environments may have significant delays when executing.
https.setIdleTimeout(30000L);
// add the connector
jetty.addConnector(https);
jetty.start();
Thread.sleep(1000);
if (!jetty.isStarted()) {
throw new IllegalStateException("Jetty server not started");
}
}
示例15: httpConnector
import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private ServerConnector httpConnector(HttpConfiguration httpConfig) {
// === jetty-http.xml ===
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
http.setHost(CONFIG.getJetty().getServerHost());
http.setPort(CONFIG.getJetty().getHttpPort());
http.setIdleTimeout(IDLE_TIMEOUT);
return http;
}