本文整理汇总了Java中org.eclipse.jetty.servlet.ServletContextHandler类的典型用法代码示例。如果您正苦于以下问题:Java ServletContextHandler类的具体用法?Java ServletContextHandler怎么用?Java ServletContextHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletContextHandler类属于org.eclipse.jetty.servlet包,在下文中一共展示了ServletContextHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(8067);
jettyServer.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter(
"jersey.config.server.provider.classnames",
EntryPointTestHandler.class.getCanonicalName());
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
示例2: JettyAdminServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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 + "/*");
}
示例3: testStarted
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
public void testStarted() {
// update the configuration
this.reconfigure();
this.server = new Server(this.getSaveConfig().getPort());
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
try {
server.start();
} catch (Exception e) {
log.error("Couldn't start http server", e);
}
}
示例4: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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", AnalysisUI.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: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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();
}
示例6: run
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
public void run() throws Exception {
org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setWelcomeFiles(new String[]{ "demo.html" });
context.setResourceBase(httpPath);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
HashSessionManager manager = new HashSessionManager();
SessionHandler sessions = new SessionHandler(manager);
sessions.setHandler(context);
context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
context.addServlet(holderPwd,"/*");
server.setHandler(sessions);
server.start();
server.join();
}
示例7: initClientProxy
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
private void initClientProxy() {
int port = Context.getConfig().getInteger("osmand.port");
if (port != 0) {
ServletContextHandler servletHandler = new ServletContextHandler() {
@Override
public void doScope(
String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) {
super.doScope(target, baseRequest, request, response);
}
}
};
ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent());
servletHolder.setInitParameter("proxyTo", "http://localhost:" + port);
servletHandler.addServlet(servletHolder, "/");
handlers.addHandler(servletHandler);
}
}
示例8: startWebSocket
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
/**
* start server
*
* @param port
* @param path
* @param handlerClass
*/
public static void startWebSocket(int port, String path, String handlerClass) {
try {
Server server = new Server(port);
HandlerList handlerList = new HandlerList();
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(new ServletHolder(new Jwservlet(handlerClass)),
path);
handlerList.addHandler(context);
handlerList.addHandler(new DefaultHandler());
server.setHandler(handlerList);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
LogUtil.LOG("start websocket server error:" + e.getMessage(),
LogLev.ERROR, WebSocketServer.class);
System.exit(1);
}
}
示例9: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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);
}
}
示例10: reverseProxy
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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();
}
示例11: addApplication
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
// (0) Sort the resource methods by literal length
application.sortResourceMethods();
// (1) Add Minijax filter (must come before websocket!)
context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));
// (2) WebSocket endpoints
if (OptionalClasses.WEB_SOCKET_UTILS != null) {
OptionalClasses.WEB_SOCKET_UTILS
.getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
.invoke(null, context, application);
}
// (3) Dynamic JAX-RS content
final MinijaxServlet servlet = new MinijaxServlet(application);
final ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
context.addServlet(servletHolder, "/*");
}
示例12: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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();
}
示例13: start
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的package包/类
public void start() throws Exception {
server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(AuthenticationFilter.class, "/*", null);
context.setServer(server);
// Add static files handler
context.setBaseResource(Resource.newResource(JettyServer.class.getResource("/webapp")));
context.addServlet(DefaultServlet.class,"/");
context.setWelcomeFiles(new String[]{"index.html"});
ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
wsContainer.addEndpoint(createEndpointConfig(EchoEndpoint.class));
server.setHandler(context);
server.start();
}
示例14: jettyServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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;
}
示例15: start
import org.eclipse.jetty.servlet.ServletContextHandler; //导入依赖的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();
}