本文整理汇总了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);
}