本文整理匯總了Java中org.eclipse.jetty.server.Connector類的典型用法代碼示例。如果您正苦於以下問題:Java Connector類的具體用法?Java Connector怎麽用?Java Connector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Connector類屬於org.eclipse.jetty.server包,在下文中一共展示了Connector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reverseProxy
import org.eclipse.jetty.server.Connector; //導入依賴的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();
}
示例2: start
import org.eclipse.jetty.server.Connector; //導入依賴的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 + "].");
}
示例3: afterPropertiesSet
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
public void afterPropertiesSet() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
Integer port = getPort();
if (port != null && port > 0) {
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例4: main
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
Server server = (Server) configuration.configure();
int port = 8081;
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
}
server.start();
server.join();
}
示例5: run
import org.eclipse.jetty.server.Connector; //導入依賴的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);
}
}
示例6: prepare
import org.eclipse.jetty.server.Connector; //導入依賴的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);
}
}
示例7: RestServer
import org.eclipse.jetty.server.Connector; //導入依賴的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});
}
示例8: createDevServer
import org.eclipse.jetty.server.Connector; //導入依賴的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;
}
示例9: installListeners
import org.eclipse.jetty.server.Connector; //導入依賴的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()]));
}
示例10: lifeCycleStarted
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
@Override
public void lifeCycleStarted(LifeCycle bean) {
if (bean instanceof Server) {
Server server = (Server)bean;
Connector[] connectors = server.getConnectors();
if (connectors == null || connectors.length == 0) {
server.dumpStdErr();
throw new IllegalStateException("No Connector");
} else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) {
server.dumpStdErr();
throw new IllegalStateException("Connector not started");
}
ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
if (context == null || !context.isAvailable()) {
server.dumpStdErr();
throw new IllegalStateException("No Available Context");
}
}
}
示例11: getEmbeddedServletContainer
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
ServletContextInitializer... initializers) {
JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
int port = (getPort() >= 0 ? getPort() : 0);
InetSocketAddress address = new InetSocketAddress(getAddress(), port);
Server server = createServer(address);
configureWebAppContext(context, initializers);
server.setHandler(addHandlerWrappers(context));
this.logger.info("Server initialized with port: " + port);
if (getSsl() != null && getSsl().isEnabled()) {
SslContextFactory sslContextFactory = new SslContextFactory();
configureSsl(sslContextFactory, getSsl());
AbstractConnector connector = getSslServerConnectorFactory()
.getConnector(server, sslContextFactory, port);
server.setConnectors(new Connector[] { connector });
}
for (JettyServerCustomizer customizer : getServerCustomizers()) {
customizer.customize(server);
}
if (this.useForwardHeaders) {
new ForwardHeadersCustomizer().customize(server);
}
return getJettyEmbeddedServletContainer(server);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:26,代碼來源:JettyEmbeddedServletContainerFactory.java
示例12: removeFromServer
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
public void removeFromServer(Server server) {
for (Connector connector : server.getConnectors()) {
if (connector instanceof NetworkTrafficServerConnector) {
NetworkTrafficServerConnector serverConnector = (NetworkTrafficServerConnector)connector;
if (serverConnector.getPort() == port && serverConnector.getHost().equals(host)) {
server.removeConnector(serverConnector);
if (server.isStarted()) {
try {
serverConnector.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
}
示例13: createServerInSource
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
/**
* 創建用於開發運行調試的Jetty Server, 以src/main/webapp為Web應用目錄.
*/
public static Server createServerInSource(int port, String contextPath) {
Server server = new Server();
// 設置在JVM退出時關閉Jetty的鉤子。
server.setStopAtShutdown(true);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
// 解決Windows下重複啟動Jetty居然不報告端口衝突的問題.
connector.setReuseAddress(false);
server.setConnectors(new Connector[] { connector });
WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
// 修改webdefault.xml,解決Windows下Jetty Lock住靜態文件的問題.
webContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
server.setHandler(webContext);
return server;
}
示例14: start
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
/**
* Creates and starts the server with the current state (credentials, port). After startup, the method will return
* and not block.
*
* @throws IllegalStateException if the server has already been started
* @throws Exception if creation of the server fails
*/
public void start() throws Exception {
if (jettyServer != null) {
throw new IllegalStateException("Server already started");
}
jettyServer = new Server(0);
connector = new ServerConnector(jettyServer); // NOSONAR
connector.setPort(getPort());
jettyServer.setConnectors(new Connector[]{connector});
HttpManagerBuilder builder = new HttpManagerBuilder();
builder.setResourceFactory(new MiltonWebDAVResourceFactory(this.rootFolder, userCredentials));
builder.setEnableBasicAuth(userCredentials != null && !userCredentials.isEmpty());
HttpManager mgr = builder.buildHttpManager();
jettyServer.setHandler(new MiltonHandler(mgr));
jettyServer.start();
while (!jettyServer.isStarted()) {
Thread.sleep(50);
}
}
示例15: testHttpConnectorsHttpsOnly
import org.eclipse.jetty.server.Connector; //導入依賴的package包/類
@Test
public void testHttpConnectorsHttpsOnly() {
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file:///tmp/keystore");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file:///tmp/truststore");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");
System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123");
System.setProperty(AthenzConsts.ATHENZ_PROP_IDLE_TIMEOUT, "10001");
AthenzJettyContainer container = new AthenzJettyContainer();
container.createServer(100);
HttpConfiguration httpConfig = container.newHttpConfiguration();
container.addHTTPConnectors(httpConfig, 0, 8082, 0);
Server server = container.getServer();
Connector[] connectors = server.getConnectors();
assertEquals(connectors.length, 1);
assertTrue(connectors[0].getProtocols().contains("http/1.1"));
assertTrue(connectors[0].getProtocols().contains("ssl"));
}