本文整理汇总了Java中org.mortbay.jetty.servlet.ServletHandler类的典型用法代码示例。如果您正苦于以下问题:Java ServletHandler类的具体用法?Java ServletHandler怎么用?Java ServletHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletHandler类属于org.mortbay.jetty.servlet包,在下文中一共展示了ServletHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupServer
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的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.ServletHandler; //导入依赖的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: filters
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的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);
}
}
示例4: setUp
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setResourceBase(RES_DIR);
ServletHandler sh = new ServletHandler();
sh.addServletWithMapping("org.apache.jasper.servlet.JspServlet", "*.jsp");
context.addHandler(sh);
context.addHandler(new SessionHandler());
server = new Server();
server.addHandler(context);
conf = new Configuration();
conf.addResource("nutch-default.xml");
conf.addResource("nutch-site-test.xml");
http = new Http();
http.setConf(conf);
}
示例5: removeServlet
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
/**
* Remove a servlet in the server.
* @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
*/
public void removeServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz) {
if(clazz == null) {
return;
}
//remove the filters from filterPathMapping
ServletHandler servletHandler = webAppContext.getServletHandler();
List<FilterMapping> newFilterMappings = new ArrayList<FilterMapping>();
//only add the filter whose pathSpec is not the to-be-removed servlet
for(FilterMapping mapping: servletHandler.getFilterMappings()) {
for(String mappingPathSpec: mapping.getPathSpecs()) {
if(!mappingPathSpec.equals(pathSpec)){
newFilterMappings.add(mapping);
}
}
}
servletHandler.setFilterMappings(newFilterMappings.toArray(new FilterMapping[newFilterMappings.size()]));
removeInternalServlet(name, pathSpec, clazz);
}
示例6: setUp
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
protected void setUp() throws Exception {
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setResourceBase(RES_DIR);
ServletHandler sh = new ServletHandler();
sh.addServlet("org.apache.jasper.servlet.JspServlet", "*.jsp");
context.addHandler(sh);
context.addHandler(new SessionHandler());
server = new Server();
server.addHandler(context);
conf = new Configuration();
conf.addResource("nutch-default.xml");
conf.addResource("nutch-site-test.xml");
http = new Http();
http.setConf(conf);
}
示例7: beforeClass
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
DummyProvider patientProvider = new DummyProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
servlet.setResourceProviders(patientProvider, new DummyBinaryProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler);
ourServer.start();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
ourClient = builder.build();
}
示例8: start
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的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();
}
示例9: startHTTPServer
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
private void startHTTPServer(){
int httpPort = settings.getInt(Settings.HTTP_PORT, -1);
Server server = new Server(httpPort);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
//handler.addServletWithMapping("org.http.channel.server.servlet.CommandServlet", "/~/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.ImageProxyServlet", "/img/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.RouterServlet", "/route/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.SessionStatusServlet", "/ss/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.ApiServlet", "/api/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.StatusServlet", "/status/*");
handler.addServletWithMapping("org.emop.weixin.router.servlet.IndexServlet", "/*");
try {
log.info("Start http server at " + httpPort);
server.start();
server.join();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
示例10: addInternalServlet
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的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);
}
}
示例11: startHttpServer
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
protected void startHttpServer(Object servlet){
int httpPort = settings.getInt(HTTP_PORT, 8083);
Server server = new Server(httpPort);
System.out.println("Listening HTTP port:" + httpPort);
ServletHandler handler=new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping("org.socialnet.servlet.StatusServlet", "/*");
try {
server.start();
server.join();
System.out.println("Shutdown HTTP service..");
} catch (Exception e) {
System.err.println("Stop HTTP service, with error:" + e.toString());
}
}
示例12: setUpClass
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
@Before
public void setUpClass() throws Exception {
LOG.info("---------------------------------------------");
LOG.info("Starting Jetty");
LOG.info("---------------------------------------------");
setupServer();
final HttpContext context = createContext();
final ServletHandler servlets = createServletHandler();
context.addHandler(servlets);
server.addContext(context);
server.start();
service = AtomClientFactory.getAtomService(getEndpoint(), new BasicAuthStrategy(getUsername(), getPassword()));
}
示例13: addFilterPathMapping
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
/**
* Add the path spec to the filter path mapping.
* @param pathSpec The path spec
* @param webAppCtx The WebApplicationContext to add to
*/
protected void addFilterPathMapping(String pathSpec,
Context webAppCtx) {
ServletHandler handler = webAppCtx.getServletHandler();
for(String name : filterNames) {
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(name);
fmap.setDispatches(Handler.ALL);
handler.addFilterMapping(fmap);
}
}
示例14: JettyHttpServer
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
public JettyHttpServer(URL url, final HttpHandler handler){
super(url, handler);
DispatcherServlet.addHttpHandler(url.getPort(), handler);
int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setDaemon(true);
threadPool.setMaxThreads(threads);
threadPool.setMinThreads(threads);
SelectChannelConnector connector = new SelectChannelConnector();
if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
connector.setHost(url.getHost());
}
connector.setPort(url.getPort());
server = new Server();
server.setThreadPool(threadPool);
server.addConnector(connector);
ServletHandler servletHandler = new ServletHandler();
ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
servletHolder.setInitOrder(2);
server.addHandler(servletHandler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
+ e.getMessage(), e);
}
}
示例15: start
import org.mortbay.jetty.servlet.ServletHandler; //导入依赖的package包/类
public void start() {
String serverPort = ConfigUtils.getProperty(JETTY_PORT);
int port;
if (serverPort == null || serverPort.length() == 0) {
port = DEFAULT_JETTY_PORT;
} else {
port = Integer.parseInt(serverPort);
}
connector = new SelectChannelConnector();
connector.setPort(port);
ServletHandler handler = new ServletHandler();
String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
if (resources != null && resources.length() > 0) {
FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
resourceHolder.setInitParameter("resources", resources);
}
ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
pageHolder.setInitOrder(2);
Server server = new Server();
server.addConnector(connector);
server.addHandler(handler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
}
}