本文整理汇总了Java中org.mortbay.jetty.servlet.Context.addServlet方法的典型用法代码示例。如果您正苦于以下问题:Java Context.addServlet方法的具体用法?Java Context.addServlet怎么用?Java Context.addServlet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.servlet.Context
的用法示例。
在下文中一共展示了Context.addServlet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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: start
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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);
}
示例3: testJetty
import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
@TestJetty
public void testJetty() throws Exception {
Context context = new Context();
context.setContextPath("/");
context.addServlet(MyServlet.class, "/bar");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
assertEquals(reader.readLine(), "foo");
reader.close();
}
示例4: createHandler
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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;
}
示例5: setupPspMithraService
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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
{
}
}
示例6: setupPspMithraService
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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
{
}
}
示例7: main
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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();
}
示例8: setup
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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;
}
}
示例9: start
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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);
}
示例10: initServletDefinitions
import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
/**
* @param servletDefinitions
* the servletDefinitions to set
* @throws ClassNotFoundException
*/
private void initServletDefinitions() {
try {
Context context = getContext();
int order = isLazy() ? -1 : 0;
for (ServletDefinition sd : m_servletDefinitions) {
ServletHolder holder = new ServletHolder(sd.getServletClass());
if (order >= 0)
order++;
holder.setInitOrder(order);
Map<String, String> initParams = sd.getInitParams();
if (initParams != null)
holder.setInitParameters(initParams);
context.addServlet(holder, sd.getUrlPath());
}
}
catch (Exception e) {
LOGGER.error( e.getMessage(), e);
}
}
示例11: addFilters
import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
protected void addFilters(Context context) throws ClassNotFoundException, NoSuchMethodException,
InstantiationException, IllegalAccessException, InvocationTargetException {
context.addFilter(XdServletFilter.class, "/*", Handler.DEFAULT);
context.addFilter(MethodOverrideServletFilter.class, "/*", Handler.DEFAULT);
if (FlagConfig.enableAuth_FLAG.equalsIgnoreCase("true")) {
ServletHolder servletHolder2 = new ServletHolder(new GetAuthTokenServlet());
context.addServlet(servletHolder2, "/accounts/ClientLogin");
context.addFilter(SignedRequestFilter.class, "/*", org.mortbay.jetty.Handler.DEFAULT);
EventListener listener = new GuiceServletContextListener();
context.addEventListener(listener);
logger.info("FeedServer to accept signed requests");
} else if (!FlagConfig.enableOAuthSignedFetch_FLAG.equalsIgnoreCase("false")) {
// Register the OAuth filter
SimpleKeyMananger sKeyManager = new SimpleKeyMananger();
Filter oauthFilter =
createOAuthFilter(FlagConfig.enableOAuthSignedFetch_FLAG.equalsIgnoreCase("true") ?
FlagConfig.OAUTH_SIGNED_FETCH_FILTER_CLASS_NAME :
FlagConfig.enableOAuthSignedFetch_FLAG, sKeyManager);
context.addFilter(new FilterHolder(oauthFilter), "/*", org.mortbay.jetty.Handler.DEFAULT);
logger.info("FeedServer to accept OAuth signed requests");
}
}
示例12: startHttpServer
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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();
}
示例13: testJetty
import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@Test
@TestJetty
public void testJetty() throws Exception {
Context context = new Context();
context.setContextPath("/");
context.addServlet(MyServlet.class, "/bar");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
assertEquals(reader.readLine(), "foo");
reader.close();
}
示例14: addDefaultApps
import org.mortbay.jetty.servlet.Context; //导入方法依赖的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);
}
示例15: setup
import org.mortbay.jetty.servlet.Context; //导入方法依赖的package包/类
@BeforeMethod
public void setup() throws Exception
{
RestEasyApplication.singletonsRef.set(new RestEasySingletons());
ResteasyProviderFactory.setInstance(new ResteasyProviderFactory());
HttpServletDispatcher dispatcher = new HttpServletDispatcher();
port = InstanceSpec.getRandomPort();
server = new Server(port);
Context root = new Context(server, "/", Context.SESSIONS);
root.getInitParams().put("javax.ws.rs.Application", RestEasyApplication.class.getName());
root.addServlet(new ServletHolder(dispatcher), "/*");
root.addEventListener(new ResteasyBootstrap());
server.start();
}