本文整理汇总了Java中org.eclipse.jetty.servlet.ServletHolder类的典型用法代码示例。如果您正苦于以下问题:Java ServletHolder类的具体用法?Java ServletHolder怎么用?Java ServletHolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletHolder类属于org.eclipse.jetty.servlet包,在下文中一共展示了ServletHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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: onServletStop
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* onServletStop
*
* @param args
*/
public void onServletStop(Object... args) {
ServletHolder sh = (ServletHolder) args[0];
Servlet servlet;
try {
servlet = sh.getServlet();
}
catch (ServletException e) {
// ignore
return;
}
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.BEFORE_SERVLET_DESTROY);
context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
context.put(InterceptConstants.CONTEXTPATH, sh.getContextPath());
iSupport.doIntercept(context);
}
示例3: JettyAdminServer
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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 + "/*");
}
示例4: onServletStart
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* onServletStart
*
* @param args
*/
public void onServletStart(Object... args) {
ServletHolder sh = (ServletHolder) args[0];
Servlet servlet;
try {
servlet = sh.getServlet();
}
catch (ServletException e) {
// ignore
return;
}
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.AFTER_SERVET_INIT);
context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
context.put(InterceptConstants.CONTEXTPATH, sh.getContextPath());
iSupport.doIntercept(context);
}
示例5: testStarted
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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);
}
}
示例6: run
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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);
}
}
示例8: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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();
}
示例9: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
initWeixin();
Server server = new Server(8080);
ServletHandler servletHandler = new ServletHandler();
server.setHandler(servletHandler);
ServletHolder endpointServletHolder = new ServletHolder(new WxCpEndpointServlet(wxCpConfigStorage, wxCpService, wxCpMessageRouter));
servletHandler.addServletWithMapping(endpointServletHolder, "/*");
ServletHolder oauthServletHolder = new ServletHolder(new WxCpOAuth2Servlet(wxCpService));
servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");
server.start();
server.join();
}
示例10: initClientProxy
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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);
}
}
示例11: startWebSocket
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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);
}
}
示例12: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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);
}
}
示例13: reverseProxy
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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();
}
示例14: addApplication
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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, "/*");
}
示例15: main
import org.eclipse.jetty.servlet.ServletHolder; //导入依赖的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();
}