本文整理汇总了Java中org.eclipse.jetty.servlet.ServletContextHandler.setContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextHandler.setContextPath方法的具体用法?Java ServletContextHandler.setContextPath怎么用?Java ServletContextHandler.setContextPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.servlet.ServletContextHandler
的用法示例。
在下文中一共展示了ServletContextHandler.setContextPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: initApi
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private void initApi() {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
servletHandler.getSessionHandler().setSessionManager(sessionManager);
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);
}
示例3: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876)
.maxConcurrentCallsPerConnection(12).maxMessageSize(16777216)
.addService(new MockApplicationRegisterService())
.addService(new MockInstanceDiscoveryService())
.addService(new MockJVMMetricsService())
.addService(new MockServiceNameDiscoveryService())
.addService(new MockTraceSegmentService()).build().start();
Server jettyServer = new Server(new InetSocketAddress("0.0.0.0",
Integer.valueOf(12800)));
String contextPath = "/";
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servletContextHandler.setContextPath(contextPath);
servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH);
servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH);
servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH);
jettyServer.setHandler(servletContextHandler);
jettyServer.start();
}
示例4: run
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void run(final int port) {
try {
final Server server = createServer();
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
for (final MinijaxApplication application : applications) {
addApplication(context, application);
}
final ServerConnector connector = createConnector(server);
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
server.start();
server.join();
} catch (final Exception ex) {
throw new MinijaxException(ex);
}
}
示例5: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
Initiator.init();
Server server = new Server(PORT);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(CONTEXT_PATH);
server.setHandler(context);
server.setStopAtShutdown(true);
context.addServlet(new ServletHolder(new GetAllLang()), "/get_all_lang");
context.addServlet(new ServletHolder(new Compile()), "/compile");
context.addServlet(new ServletHolder(new Run()), "/run");
server.join();
server.start();
LOGGER.info("Avalon-Executive server is now running at http://127.0.0.1:" + PORT + CONTEXT_PATH);
}
示例6: createRestService
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private Handler createRestService() {
ResourceConfig rc = new ResourceConfig();
localRestResources.forEach(rc::register);
rc.register(JacksonFeature.class);
rc.register(CORSFilter.class);
rc.addProperties(new HashMap<String,Object>() {{
// Turn off buffering so results can be streamed
put(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
}});
ServletHolder holder = new ServletHolder(new ServletContainer(rc));
ServletContextHandler sch = new ServletContextHandler();
sch.setContextPath("/api/v1");
sch.addServlet(holder, "/*");
return sch;
}
示例7: 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.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);
new Thread(new Console(getPinto(),port,build, () -> {
try {
server.stop();
} catch (Exception e) {
e.printStackTrace();
}
}), "console_thread").start();
server.start();
server.join();
}
示例8: JSMServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public JSMServer(int port) {
this.statsBroadcaster = new StatsBroadcaster();
this.server = new Server(port);
try {
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/");
handler.addServlet(new ServletHolder(new StatsServlet()), "/stats");
handler.addServlet(new ServletHolder(new SinkServlet()), "/sinks");
this.server.setHandler(handler);
} catch (Exception e) {
logger.error("Exception in configuring servlet handlers", e);
}
}
示例9: createRestService
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private Handler createRestService() {
ResourceConfig rc = new ResourceConfig();
rc.register(systemResource);
rc.register(appResource);
rc.register(JacksonFeature.class);
rc.register(CORSFilter.class);
SwaggerDocs.registerSwaggerJsonResource(rc);
rc.addProperties(new HashMap<String,Object>() {{
// Turn off buffering so results can be streamed
put(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
}});
ServletHolder holder = new ServletHolder(new ServletContainer(rc));
ServletContextHandler sch = new ServletContextHandler();
sch.setContextPath("/api/v1");
sch.addServlet(holder, "/*");
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(sch);
return gzipHandler;
}
示例10: start
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void start(Controller controller) throws Exception {
this.controller = controller;
Server server = new Server(REST_SERVICE_PORT);
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("");
servletContextHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig(controller))), "/*");
server.setHandler(servletContextHandler);
try {
server.start();
server.join();
} finally {
server.destroy();
}
}
示例11: createComputeRealtimeServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
/**
* Creates a new {@link ComputeRealtimeServer}
*
* @param config
* The chatalytics config
* @return A newly created {@link ComputeRealtimeServer}
*/
public ComputeRealtimeServer createComputeRealtimeServer() {
Server server = new Server(config.computeConfig.rtComputePort);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
StatusResource.class.getPackage().toString());
server.setHandler(context);
ServerContainer wscontainer;
try {
wscontainer = WebSocketServerContainerInitializer.configureContext(context);
wscontainer.addEndpoint(RealtimeResource.class);
} catch (ServletException | DeploymentException e) {
throw new RuntimeException("Can't instantiate websocket. Reason: " + e.getMessage());
}
return new ComputeRealtimeServer(server);
}
示例12: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public static void main( String[] args ) throws Exception {
Server server = new Server(1234);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
// Expose our example servlet.
context.addServlet(new ServletHolder(new ExampleServlet()), "/");
// Expose Promtheus metrics.
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
// Add metrics about CPU, JVM memory etc.
DefaultExports.initialize();
// Start the webserver.
server.start();
server.join();
}
示例13: setUp
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
server = new Server(PORT);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
servletHolder = new ServletHolder(new CamelWebSocketServlet());
servletHolder.setName("CamelWsServlet");
context.addServlet(servletHolder, "/*");
server.start();
if (startCamelContext) {
super.setUp();
}
}
示例14: startServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void startServer() {
server = new Server(PORT);
port = PORT;
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setSecurityHandler(basicAuth("camel", "camelPass", "Private!"));
servletContext.setContextPath("/");
server.setHandler(servletContext);
servletContext.addServlet(new ServletHolder(new MyHttpServlet()), "/*");
try {
server.start();
} catch (Exception ex) {
LOG.error("Could not start Server!", ex);
fail(ex.getLocalizedMessage());
}
}
示例15: initContext
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private ServletContextHandler initContext(final String contextPath, final Set<Class<?>> classes) {
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(contextPath);
context.setAttribute(ATTR_CLASSES, classes);
context.setAttribute(ATTR_DI, dependencyInjection);
return context;
}