本文整理匯總了Java中org.eclipse.jetty.server.Server類的典型用法代碼示例。如果您正苦於以下問題:Java Server類的具體用法?Java Server怎麽用?Java Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Server類屬於org.eclipse.jetty.server包,在下文中一共展示了Server類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JettyAdminServer
import org.eclipse.jetty.server.Server; //導入依賴的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: main
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(PUBLIC_HTML);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
//page reloaded by the timer
context.addServlet(TimerServlet.class, "/timer");
//part of a page reloaded by the timer
context.addServlet(AjaxTimerServlet.class, "/server-time");
//long-polling waits till a message
context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
//web chat
context.addServlet(WebSocketChatServlet.class, "/chat");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例3: main
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(PUBLIC_HTML);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
context.addServlet(AdminServlet.class, "/admin");
context.addServlet(TimerServlet.class, "/timer");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例4: main
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static void main(String[] args) {
int port = Configuration.INSTANCE.getInt("port", 8080);
Server server = new Server(port);
ServletContextHandler contextHandler
= new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
ServletHolder sh = new ServletHolder(new VaadinServlet());
contextHandler.addServlet(sh, "/*");
contextHandler.setInitParameter("ui", CrawlerAdminUI.class.getCanonicalName());
contextHandler.setInitParameter("productionMode", String.valueOf(PRODUCTION_MODE));
server.setHandler(contextHandler);
try {
server.start();
server.join();
} catch (Exception e) {
LOG.error("Failed to start application", e);
}
}
示例5: reverseProxy
import org.eclipse.jetty.server.Server; //導入依賴的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();
}
示例6: init
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public @NotNull CollectorServer init(@NotNull InetSocketAddress address, @NotNull ExpositionFormat format) {
try {
Log.setLog(new Slf4jLog());
final Server serverInstance = new Server(address);
format.handler(serverInstance);
serverInstance.start();
server = serverInstance;
Logger.instance.info("Prometheus server with JMX metrics started at " + address);
} catch (Exception e) {
Logger.instance.error("Failed to start server at " + address, e);
}
return this;
}
示例7: start
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
private void start() throws Exception {
resourcesExample();
ResourceHandler resourceHandler = new ResourceHandler();
Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
resourceHandler.setBaseResource(resource);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new TimerServlet()), "/timer");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例8: main
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static void main(String[] args) {
try {
MergedLogSource src = new MergedLogSource(args);
System.out.println(src);
Server server = new Server(8182);
server.setHandler(new LogServer(src));
server.start();
server.join();
} catch (Exception e) {
// Something is wrong.
e.printStackTrace();
}
}
示例9: addWebApplication
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static Server addWebApplication(final Server jetty, final String webAppContext,
final String warFilePath) {
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(webAppContext);
webapp.setWar(warFilePath);
webapp.setParentLoaderPriority(false);
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
tmpPath.mkdirs();
webapp.setTempDirectory(tmpPath);
((HandlerCollection) jetty.getHandler()).addHandler(webapp);
return jetty;
}
示例10: configureSpnego
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
/**
* Configures the <code>connector</code> given the <code>config</code> for using SPNEGO.
*
* @param connector The connector to configure
* @param config The configuration
*/
protected ConstraintSecurityHandler configureSpnego(Server server, ServerConnector connector,
AvaticaServerConfiguration config) {
final String realm = Objects.requireNonNull(config.getKerberosRealm());
final String principal = Objects.requireNonNull(config.getKerberosPrincipal());
// A customization of SpnegoLoginService to explicitly set the server's principal, otherwise
// we would have to require a custom file to set the server's principal.
PropertyBasedSpnegoLoginService spnegoLoginService =
new PropertyBasedSpnegoLoginService(realm, principal);
// Roles are "realms" for Kerberos/SPNEGO
final String[] allowedRealms = getAllowedRealms(realm, config);
return configureCommonAuthentication(server, connector, config, Constraint.__SPNEGO_AUTH,
allowedRealms, new AvaticaSpnegoAuthenticator(), realm, spnegoLoginService);
}
示例11: isRunning
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
@Override
public boolean isRunning(final int port) {
if (!isValidPort(port)) {
return false;
}
final Server server = serverCache.getIfPresent(port);
if (null == server) {
return false;
}
if (!server.isStarted()) {
return false;
}
return isPortInUse(port);
}
示例12: startServer
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
/**
* startUAVServer
*/
public void startServer(Object... args) {
Server server = (Server) args[0];
// integrate Tomcat log
UAVServer.instance().setLog(new JettyLog("MonitorServer"));
// start Monitor Server when server starts
UAVServer.instance().start(new Object[] { UAVServer.ServerVendor.JETTY });
// get server port
if (UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT) == null) {
// set port
ServerConnector sc = (ServerConnector) server.getConnectors()[0];
String protocol = sc.getDefaultProtocol();
if (protocol.toLowerCase().indexOf("http") >= 0) {
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT, sc.getPort());
}
}
}
示例13: main
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public static void main(final String... args) throws Exception {
if (args.length > 1) {
System.out.printf("Temporary Directory @ ($1%s)%n", USER_DIR);
final Server jetty = JettyHelper.initJetty(null, 8090, new SSLConfig());
for (int index = 0; index < args.length; index += 2) {
final String webAppContext = args[index];
final String webAppArchivePath = args[index + 1];
JettyHelper.addWebApplication(jetty, normalizeWebAppContext(webAppContext),
normalizeWebAppArchivePath(webAppArchivePath));
}
JettyHelper.startJetty(jetty);
latch.await();
} else {
System.out.printf(
"usage:%n>java org.apache.geode.management.internal.TomcatHelper <web-app-context> <war-file-path> [<web-app-context> <war-file-path>]*");
}
}
示例14: createDevServer
import org.eclipse.jetty.server.Server; //導入依賴的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;
}
示例15: start
import org.eclipse.jetty.server.Server; //導入依賴的package包/類
public void start() {
// TODO: remove redundant fields from config and move this check to XRE Redirector
if (! config.getEnableCommunicationEndpoint()) {
log.warn("skipping Jetty endpoint due to configuration");
return;
}
if (started) {
log.warn("Jetty is already started");
}
started = true;
Integer port = config.getCommunicationEndpointPort();
log.info("Starting embedded jetty server (XRERedirector Gateway) on port: {}", port);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setConfigurations(new Configuration[]{new AnnotationConfiguration() {
@Override
public void preConfigure(WebAppContext context) {
ClassInheritanceMap map = new ClassInheritanceMap();
map.put(WebApplicationInitializer.class.getName(), new ConcurrentHashSet<String>() {{
add(WebAppInitializer.class.getName());
}});
context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
}});
server = new Server(port);
server.setHandler(webAppContext);
try {
server.start();
} catch (Exception e) {
log.error("Failed to start embedded jetty server (XRERedirector communication endpoint) on port: " + port, e);
}
log.info("Started embedded jetty server (Redirector Gateway) on port: {}", port);
}