本文整理匯總了Java中org.mortbay.jetty.servlet.DefaultServlet類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultServlet類的具體用法?Java DefaultServlet怎麽用?Java DefaultServlet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultServlet類屬於org.mortbay.jetty.servlet包,在下文中一共展示了DefaultServlet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startServer
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private static void startServer() throws Exception, InterruptedException {
Server server = new Server(port);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(DefaultServlet.class, "/*");
context.addEventListener(new ContextLoaderListener(getContext()));
context.addEventListener(new RequestContextListener());
WicketFilter filter = new WicketFilter();
filter.setFilterPath("/");
FilterHolder holder = new FilterHolder(filter);
holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
context.addFilter(holder, "/*", Handler.DEFAULT);
server.setHandler(context);
server.start();
server.join();
}
示例2: createWebAppContext
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private static WebAppContext createWebAppContext(String name,
Configuration conf, AccessControlList adminsAcl, final String appDir) {
WebAppContext ctx = new WebAppContext();
ctx.setDefaultsDescriptor(null);
ServletHolder holder = new ServletHolder(new DefaultServlet());
Map<String, String> params = ImmutableMap. <String, String> builder()
.put("acceptRanges", "true")
.put("dirAllowed", "false")
.put("gzip", "true")
.put("useFileMappedBuffer", "true")
.build();
holder.setInitParameters(params);
ctx.setWelcomeFiles(new String[] {"index.html"});
ctx.addServlet(holder, "/");
ctx.setDisplayName(name);
ctx.setContextPath("/");
ctx.setWar(appDir + "/" + name);
ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
addNoCacheFilter(ctx);
return ctx;
}
示例3: createHandler
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private Context createHandler(
Map<String, Path> runfiles,
ImmutableList<Route> routes,
ImmutableList<Class<? extends Filter>> filters) {
Context context = new Context(server, CONTEXT_PATH, Context.SESSIONS);
context.addServlet(new ServletHolder(HealthzServlet.class), "/healthz");
for (Map.Entry<String, Path> runfile : runfiles.entrySet()) {
context.addServlet(
StaticResourceServlet.create(runfile.getKey(), runfile.getValue()),
runfile.getKey());
}
for (Route route : routes) {
context.addServlet(
new ServletHolder(wrapServlet(route.servletClass(), filters)), route.path());
}
ServletHolder holder = new ServletHolder(DefaultServlet.class);
holder.setInitParameter("aliases", "1");
context.addServlet(holder, "/*");
return context;
}
示例4: start
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public void start() throws Exception {
this.jetty.addConnector(connector);
ServletHandler servletHandler = new ServletHandler();
String filterName = "MyriadGuiceFilter";
FilterHolder holder = new FilterHolder(filter);
holder.setName(filterName);
FilterMapping filterMapping = new FilterMapping();
filterMapping.setPathSpec("/*");
filterMapping.setDispatches(Handler.ALL);
filterMapping.setFilterName(filterName);
servletHandler.addFilter(holder, filterMapping);
Context context = new Context();
context.setServletHandler(servletHandler);
context.addServlet(DefaultServlet.class, "/");
String staticDir = this.getClass().getClassLoader().getResource("webapp/public").toExternalForm();
context.setResourceBase(staticDir);
this.jetty.addHandler(context);
this.jetty.start();
}
示例5: addDefaultApps
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent,
final String appDir) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = System.getProperty("hadoop.log.dir");
if (logDir != null) {
Context logContext = new Context(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/");
logContext.setDisplayName("logs");
setContextAttributes(logContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Context staticContext = new Context(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
setContextAttributes(staticContext);
defaultContexts.put(staticContext, true);
}
示例6: addDefaultApps
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent,
final String appDir) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = System.getProperty("hadoop.log.dir");
if (logDir != null) {
Context logContext = new Context(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(DefaultServlet.class, "/");
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Context staticContext = new Context(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
defaultContexts.put(staticContext, true);
}
示例7: addDefaultApps
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent,
final String appDir, Configuration conf) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = System.getProperty("hadoop.log.dir");
if (logDir != null) {
Context logContext = new Context(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
if (conf.getBoolean(
CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES,
CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
logContext.getInitParams().put(
"org.mortbay.jetty.servlet.Default.aliases", "true");
}
logContext.setDisplayName("logs");
setContextAttributes(logContext, conf);
addNoCacheFilter(webAppContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Context staticContext = new Context(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
示例8: addDefaultApps
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent,
final String appDir, Configuration conf) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = System.getProperty("hadoop.log.dir");
if (logDir != null) {
Context logContext = new Context(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
if (conf.getBoolean(
CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES,
CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
@SuppressWarnings("unchecked")
Map<String, String> params = logContext.getInitParams();
params.put(
"org.mortbay.jetty.servlet.Default.aliases", "true");
}
logContext.setDisplayName("logs");
setContextAttributes(logContext, conf);
addNoCacheFilter(webAppContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Context staticContext = new Context(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
示例9: addDefaultApps
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent,
final String appDir, Configuration conf) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = this.logDir;
if (logDir == null) {
logDir = System.getProperty("hadoop.log.dir");
}
if (logDir != null) {
Context logContext = new Context(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
if (conf.getBoolean(
ServerConfigurationKeys.HBASE_JETTY_LOGS_SERVE_ALIASES,
ServerConfigurationKeys.DEFAULT_HBASE_JETTY_LOGS_SERVE_ALIASES)) {
@SuppressWarnings("unchecked")
Map<String, String> params = logContext.getInitParams();
params.put(
"org.mortbay.jetty.servlet.Default.aliases", "true");
}
logContext.setDisplayName("logs");
setContextAttributes(logContext, conf);
addNoCacheFilter(webAppContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Context staticContext = new Context(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
示例10: fixupLogsServletLocation
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Fixup where the logs app points, make it point at hbase logs rather than
* hadoop logs.
*/
private void fixupLogsServletLocation() {
// Must be same as up in hadoop.
final String logsContextPath = "/logs";
// Now, put my logs in place of hadoops... disable old one first.
Context oldLogsContext = null;
for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) {
if (e.getKey().getContextPath().equals(logsContextPath)) {
oldLogsContext = e.getKey();
break;
}
}
if (oldLogsContext != null) {
this.defaultContexts.put(oldLogsContext, Boolean.FALSE);
}
// Now do my logs.
// Set up the context for "/logs/" if "hbase.log.dir" property is defined.
String logDir = System.getProperty("hbase.log.dir");
if (logDir != null) {
// This is a little presumptious but seems to work.
Context logContext =
new Context((ContextHandlerCollection)this.webServer.getHandler(),
logsContextPath);
logContext.setResourceBase(logDir);
logContext.addServlet(DefaultServlet.class, "/");
defaultContexts.put(logContext, true);
}
}
示例11: MyPetStoreServer
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public MyPetStoreServer(int portNumber) {
this.portNumber = portNumber;
server = new Server(portNumber);
Context root = new Context(server, "/", Context.SESSIONS);
root.addFilter(GuiceFilter.class, "/*", 0);
root.addServlet(DefaultServlet.class, "/");
}
示例12: PetStoreServer
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
@Inject
public PetStoreServer(int portNumber) {
server = new Server(portNumber);
Context root = new Context(server, "/", Context.SESSIONS);
root.addFilter(GuiceFilter.class, "/*", 0);
root.addServlet(DefaultServlet.class, "/");
}
示例13: fixupLogsServletLocation
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
/**
* Fixup where the logs app points, make it point at hbase logs rather than
* hadoop logs.
*/
private void fixupLogsServletLocation() {
// Must be same as up in hadoop.
final String logsContextPath = "/logs";
// Now, put my logs in place of hadoops... disable old one first.
Context oldLogsContext = null;
for (Map.Entry<Context, Boolean> e : defaultContexts.entrySet()) {
if (e.getKey().getContextPath().equals(logsContextPath)) {
oldLogsContext = e.getKey();
break;
}
}
if (oldLogsContext != null) {
this.defaultContexts.put(oldLogsContext, Boolean.FALSE);
}
// Now do my logs.
// Set up the context for "/logs/" if "hbase.log.dir" property is defined.
String logDir = System.getProperty("hbase.log.dir");
if (logDir != null) {
// This is a little presumptious but seems to work.
Context logContext =
new Context((ContextHandlerCollection)this.webServer.getHandler(),
logsContextPath);
logContext.setResourceBase(logDir);
logContext.addServlet(DefaultServlet.class, "/");
HttpServerUtil.constrainHttpMethods(logContext);
defaultContexts.put(logContext, true);
}
}
示例14: getJettyServer
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public static Server getJettyServer() {
Server server = new Server();
ServletHandler context = new ServletHandler();
ServletHolder holder = new ServletHolder(DefaultServlet.class);
holder.setInitParameter("resourceBase", System.getProperty("user.dir"));
holder.setInitParameter("dirAllowed", "true");
context.setServer(server);
context.addServlet(holder);
server.setHandler(context);
return server;
}
示例15: go
import org.mortbay.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public void go() {
QueuedThreadPool pool = new QueuedThreadPool();
pool.setMinThreads(2); // debug server doesn't need many threads.
pool.setMaxThreads(10);
pool.setName("DebugServer(port" + port + ")");
pool.setDaemon(true);
server.setThreadPool(pool);
SocketConnector connector = new SocketConnector();
connector.setPort(port);
connector.setHost(host);
connector.setMaxIdleTime(60000); // 1 min
server.addConnector(connector);
context.setContextPath("/");
context.setBaseResource(Resource.newClassPathResource("/org/cloudera/stethoscope"));
server.setHandler(context);
addServlet(new DefaultServlet(), "/");
addServlet(new DataServlet(), "/json/*");
addServlet(new TracerServlet(inst), "/tracer/*");
addServlet(new EvaluateServlet(), "/evaluate");
addServlet(new PoorMansProfileServlet(), "/poorMansProfiler");
addServlet(new JMXJsonServlet(), "/jmx");
// addServlet(new LoggerServlet(), "/logging");
try {
server.start();
} catch (Exception e) {
// avoiding logging in this context.
e.printStackTrace(System.err);
}
}