本文整理汇总了Java中org.mortbay.jetty.servlet.ServletHolder类的典型用法代码示例。如果您正苦于以下问题:Java ServletHolder类的具体用法?Java ServletHolder怎么用?Java ServletHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletHolder类属于org.mortbay.jetty.servlet包,在下文中一共展示了ServletHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupServer
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
private void setupServer() throws Exception
{
this.server = new HttpServer();
SocketListener listener = new SocketListener();
listener.setPort(PORT);
this.server.addListener(listener);
HttpContext context = new HttpContext();
context.setContextPath("/");
ServletHandler servletHandler = new ServletHandler();
context.addHandler(servletHandler);
// Map a servlet onto the container
ServletHolder holder =
servletHandler.addServlet("JrpipServlet", "/JrpipServlet", "com.gs.jrpip.server.JrpipServlet");
holder.put("serviceInterface.Echo", "com.gs.jrpip.Echo");
holder.put("vmBoundServiceClass.Echo", "com.gs.jrpip.EchoImpl");
holder.setInitOrder(10);
this.server.addContext(context);
this.server.start();
this.servlet = (JrpipServlet) holder.getServlet();
}
示例2: filters
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
+ * servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
webAppContext.addServlet(holder, pathSpec);
if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(Handler.ALL);
handler.addFilterMapping(fmap);
}
}
示例3: createWebAppContext
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的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;
}
示例4: filters
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
+ * servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
webAppContext.addServlet(holder, pathSpec);
if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(Handler.ALL);
handler.addFilterMapping(fmap);
}
}
示例5: start
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
Context context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
server.getConnectors()[0].setHost("localhost");
server.start();
originalPort = server.getConnectors()[0].getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:"
+ originalPort);
}
示例6: start
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
Context context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
server.getConnectors()[0].setHost("localhost");
server.start();
originalPort = server.getConnectors()[0].getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:"
+ originalPort);
// This property needs to be set otherwise CORS Headers will be dropped
// by HttpUrlConnection
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
示例7: setupPspMithraService
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
protected void setupPspMithraService()
{
server = new Server(this.getApplicationPort1());
Context context = new Context (server,"/",Context.SESSIONS);
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheService");
holder.setInitParameter("serviceClass.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheServiceImpl");
holder.setInitOrder(10);
// System.out.println(holder.getServlet().getClass().getName());
try
{
server.start();
}
catch (Exception e)
{
throw new RuntimeException("could not start server", e);
}
finally
{
}
}
示例8: setupServerWithHandler
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
protected void setupServerWithHandler(
Handler handler) throws Exception
{
this.port = (int) (Math.random() * 10000.0 + 10000.0);
this.pspUrl = "http://localhost:" + this.port + "/PspServlet";
this.server = new Server(this.port);
Context context = new Context(server, "/", Context.SESSIONS);
if (handler != null)
{
context.addHandler(handler);
}
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo");
holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl");
holder.setInitOrder(10);
this.server.start();
this.servlet = (PspServlet) holder.getServlet();
}
示例9: setupPspMithraService
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
protected void setupPspMithraService()
{
server = new Server(this.getApplicationPort1());
Context context = new Context (server,"/",Context.SESSIONS);
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraService");
holder.setInitParameter("serviceClass.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraServiceImpl");
holder.setInitOrder(10);
try
{
server.start();
}
catch (Exception e)
{
throw new RuntimeException("could not start server", e);
}
finally
{
}
}
示例10: setup
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
try {
JobCallbackRequestMaker.initialize(new Props());
jobCBMaker = JobCallbackRequestMaker.getInstance();
contextInfo = new HashMap<String, String>();
contextInfo.put(CONTEXT_SERVER_TOKEN, SERVER_NAME);
contextInfo.put(CONTEXT_PROJECT_TOKEN, PROJECT_NANE);
contextInfo.put(CONTEXT_FLOW_TOKEN, FLOW_NANE);
contextInfo.put(CONTEXT_EXECUTION_ID_TOKEN, EXECUTION_ID);
contextInfo.put(CONTEXT_JOB_TOKEN, JOB_NANE);
contextInfo.put(CONTEXT_JOB_STATUS_TOKEN, JobCallbackStatusEnum.STARTED.name());
embeddedJettyServer = new Server(PORT_NUMBER);
Context context = new Context(embeddedJettyServer, "/", Context.SESSIONS);
context.addServlet(new ServletHolder(new DelayServlet()), "/delay");
System.out.println("Start server");
embeddedJettyServer.start();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
示例11: createHandler
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的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;
}
示例12: create
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
/**
* Creates a servlet holder for this servlet so it can be used with Jetty.
*
* @param prefix servlet path starting with a slash and ending with {@code "/*"} if {@code root}
* is a directory
* @param root file or root directory to serve
*/
public static ServletHolder create(String prefix, Path root) {
root = root.toAbsolutePath();
checkArgument(Files.exists(root), "Root must exist: %s", root);
checkArgument(prefix.startsWith("/"), "Prefix must start with a slash: %s", prefix);
ServletHolder holder = new ServletHolder(StaticResourceServlet.class);
holder.setInitParameter("root", root.toString());
if (Files.isDirectory(root)) {
checkArgument(prefix.endsWith("/*"),
"Prefix (%s) must end with /* since root (%s) is a directory", prefix, root);
holder.setInitParameter("prefix", prefix.substring(0, prefix.length() - 1));
} else {
holder.setInitParameter("prefix", prefix);
}
return holder;
}
示例13: main
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
public static void main( String[] args )
throws Exception
{
Server server = new Server( 8080 );
WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" );
ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );
server.setHandler( handlers );
// JSP Servlet + Context
Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS );
jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" );
server.start();
server.join();
}
示例14: startHttpServer
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
private void startHttpServer() throws Exception {
// Create the webServer
if (webServer != null) {
webServer.stop();
webServer = null;
}
webServer = new Server(0);
Context context = new Context(webServer, contextPath);
// create servlet handler
context.addServlet(new ServletHolder(new NotificationServlet()),
servletPath);
// Start webServer
webServer.start();
port = webServer.getConnectors()[0].getLocalPort();
}
示例15: start
import org.mortbay.jetty.servlet.ServletHolder; //导入依赖的package包/类
protected void start() throws Exception {
server = new Server(0);
context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
host = "localhost";
ServerSocket ss = new ServerSocket(0);
port = ss.getLocalPort();
ss.close();
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
server.start();
System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}