本文整理了Java中org.eclipse.jetty.server.Server.<init>()
方法的一些代码示例,展示了Server.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.<init>()
方法的具体详情如下:
包路径:org.eclipse.jetty.server.Server
类名称:Server
方法名:<init>
[英]Convenience constructor Creates server and a ServerConnector at the passed port.
[中]
代码示例来源:origin: zhegexiaohuozi/SeimiCrawler
private void startJetty(int port, SeimiHttpHandler seimiHttpHandler) {
Server server = new Server(port);
server.setHandler(seimiHttpHandler);
try {
server.start();
server.join();
} catch (Exception e) {
logger.error("http service start error,{}", e.getMessage(), e);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
public TestJettyWebSocketServer(final WebSocketHandler webSocketHandler) {
this.server = new Server();
ServerConnector connector = new ServerConnector(this.server);
connector.setPort(0);
this.server.addConnector(connector);
this.server.setHandler(new org.eclipse.jetty.websocket.server.WebSocketHandler() {
@Override
public void configure(WebSocketServletFactory factory) {
factory.setCreator(new WebSocketCreator() {
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
if (!CollectionUtils.isEmpty(req.getSubProtocols())) {
resp.setAcceptedSubProtocol(req.getSubProtocols().get(0));
}
JettyWebSocketSession session = new JettyWebSocketSession(null, null);
return new JettyWebSocketHandlerAdapter(webSocketHandler, session);
}
});
}
});
}
代码示例来源:origin: apache/incubator-gobblin
@Override
protected void startUp() throws Exception {
LOGGER.info("Starting the admin web server");
this.server = new Server(new InetSocketAddress(this.serverUri.getHost(), this.serverUri.getPort()));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(buildSettingsHandler());
handlerCollection.addHandler(buildStaticResourceHandler());
this.server.setHandler(handlerCollection);
this.server.start();
}
代码示例来源:origin: apache/avro
public StatsServer(StatsPlugin plugin, int port) throws Exception {
this.httpServer = new Server(port);
this.plugin = plugin;
ServletHandler handler = new ServletHandler();
httpServer.setHandler(handler);
handler.addServletWithMapping(new ServletHolder(new StaticServlet()), "/");
handler.addServletWithMapping(new ServletHolder(new StatsServlet(plugin)), "/");
httpServer.start();
}
代码示例来源:origin: Netflix/conductor
@BeforeClass
public static void init() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("key", "value1");
map.put("num", 42);
JSON_RESPONSE = objectMapper.writeValueAsString(map);
server = new Server(7009);
ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
servletContextHandler.setHandler(new EchoHandler());
server.start();
}
代码示例来源:origin: stackoverflow.com
Server server = new Server(8080);
WebSocketHandler wsHandler = new WebSocketHandler()
{
@Override
public void configure(WebSocketServletFactory factory)
{
factory.register(MyEchoSocket.class);
}
};
server.addHandler(wsHandler);
server.start();
server.join();
代码示例来源:origin: Alluxio/alluxio
threadPool.setMaxThreads(webThreadCount * 2 + 100);
mServer = new Server(threadPool);
mServletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
mServletContextHandler.setContextPath(AlluxioURI.SEPARATOR);
mServer.setHandler(handlers);
代码示例来源:origin: AsyncHttpClient/async-http-client
@BeforeClass(alwaysRun = true)
@Override
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
addDigestAuthHandler(server, configureHandler());
server.start();
port1 = connector.getLocalPort();
logger.info("Local HTTP server started successfully");
}
代码示例来源:origin: apache/incubator-druid
private static Server makeTestDeleteServer(int port, final CountDownLatch latch)
{
Server server = new Server(port);
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(new HttpServlet()
{
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
{
latch.countDown();
resp.setStatus(200);
}
}), "/default/*");
server.setHandler(handler);
return server;
}
代码示例来源:origin: ninjaframework/ninja
jetty = new Server();
this.contextHandler = new ServletContextHandler(jetty, getContextPath());
this.contextHandler.addServlet(DefaultServlet.class, "/");
代码示例来源:origin: stackoverflow.com
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
context.addFilter(AppFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,DispatcherType.REQUEST));
server.setHandler(context);
server.start();
server.join();
代码示例来源:origin: Netflix/eureka
private static void startServer() throws Exception {
File warFile = findWar();
server = new Server(8080);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(warFile.getAbsolutePath());
server.setHandler(webapp);
server.start();
eurekaServiceUrl = "http://localhost:8080/v2";
}
代码示例来源:origin: apache/incubator-dubbo
threadPool.setMinThreads(threads);
server = new Server(threadPool);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.setServletHandler(servletHandler);
ServletManager.getInstance().addServletContext(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), context.getServletContext());
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
代码示例来源:origin: stackoverflow.com
Server server = new Server(8080);
WebSocketHandler wsHandler = new WebSocketHandler()
{
@Override
public void configure(WebSocketServletFactory factory)
{
factory.register(MyEchoSocket.class);
}
};
ContextHandler context = new ContextHandler();
context.setContextPath("/echo");
context.setHandler(wsHandler);
server.addHandler(context);
server.start();
server.join();
代码示例来源:origin: AsyncHttpClient/async-http-client
@BeforeClass(alwaysRun = true)
@Override
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector1 = addHttpConnector(server);
addBasicAuthHandler(server, configureHandler());
server.start();
port1 = connector1.getLocalPort();
logger.info("Local HTTP server started successfully");
}
代码示例来源:origin: apache/nifi
private void createServer(final Map<String, String> sslProperties) {
jetty = new Server();
// create the unsecure connector
createConnector();
// create the secure connector if sslProperties are specified
if (sslProperties != null) {
createSecureConnector(sslProperties);
}
jetty.setHandler(new HandlerCollection(true));
}
代码示例来源:origin: apache/storm
/**
* Start the server.
* @param port the port it shuld listen on, or null/<= 0 to pick a free ephemeral port.
*/
public void serve(Integer port) {
try {
if (server != null) {
throw new RuntimeException("The server is already running");
}
if (port == null || port <= 0) {
ServerSocket s = new ServerSocket(0);
port = s.getLocalPort();
s.close();
}
server = new Server(port);
this.port = port;
url = "http://" + InetAddress.getLocalHost().getHostName() + ":" + this.port + "/";
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsCollectionServlet()),"/*");
server.start();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
server.setHandler(new IdleStateHandler());
server.start();
port1 = connector.getLocalPort();
logger.info("Local HTTP server started successfully");
}
代码示例来源:origin: apache/incubator-dubbo
threadPool.setMinThreads(threads);
server = new Server(threadPool);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.setServletHandler(servletHandler);
ServletManager.getInstance().addServletContext(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), context.getServletContext());
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
代码示例来源:origin: stackoverflow.com
Server server = new Server();
SocketConnector connector = new SocketConnector();
server.start();
while (System.in.available() == 0) {
Thread.sleep(5000);
server.join();
} catch (Exception e) {
e.printStackTrace();
内容来源于网络,如有侵权,请联系作者删除!