当前位置: 首页>>代码示例>>Java>>正文


Java ContextHandler类代码示例

本文整理汇总了Java中org.mortbay.jetty.handler.ContextHandler的典型用法代码示例。如果您正苦于以下问题:Java ContextHandler类的具体用法?Java ContextHandler怎么用?Java ContextHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ContextHandler类属于org.mortbay.jetty.handler包,在下文中一共展示了ContextHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的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);
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:22,代码来源:TestProtocolHttpClient.java

示例2: setUp

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的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);
  }
 
开发者ID:yahoo,项目名称:anthelion,代码行数:21,代码来源:TestProtocolHttpClient.java

示例3: init

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
public void init() {
  server = new Server(PORT);

  activeHandlers = new HandlerList();
  server.setHandler(activeHandlers);

  ContextHandler contextHandler = new ContextHandler();
  contextHandler.setContextPath("/rpc");
  contextHandler.setHandler(servletHandler);
  contextHandler.setServer(server);
  addHandler(contextHandler, "/rpc");    

  try {
    server.start();
  } catch (Exception e) {
    throw new RuntimeException("Can't start jetty server", e);
  }
}
 
开发者ID:code-orchestra,项目名称:colt-core,代码行数:19,代码来源:CodeOrchestraRPCHttpServer.java

示例4: main

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(PORT);
    server.addConnector(connector);
    server.setStopAtShutdown(true);

    // the orders of handlers is very important!
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setContextPath("/reports");
    contextHandler.setResourceBase("./reports/");
    contextHandler.addHandler(new ResourceHandler());
    server.addHandler(contextHandler);

    server.addHandler(new WebAppContext("webapp", "/nextreports-server"));

    long t = System.currentTimeMillis();
    server.start();
    t = System.currentTimeMillis() - t;
    String version = server.getClass().getPackage().getImplementationVersion();
    System.out.println("Started Jetty Server " + version + " on port " + PORT + " in " + t / 1000 + "s");
    
    server.join();
}
 
开发者ID:nextreports,项目名称:nextreports-server,代码行数:26,代码来源:JettyLauncher.java

示例5: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    //echo X-* headers back in response body
    ContextHandler echoHeadersHandler = new ContextHandler("/" + ECHO_HEADERS) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            response.setStatus(200);
            PrintWriter rw = response.getWriter();
            rw.write(HEADERS + "\n");
            @SuppressWarnings("unchecked")
            Enumeration<String> headerNames = (Enumeration<String>)request.getHeaderNames();
            while (headerNames.hasMoreElements()) {
                String name = headerNames.nextElement();
                if (name.startsWith("X-")) {
                    rw.write(String.format("  %s: %s\n", name, request.getHeader(name)));
                }
            }
            rw.close();
        }
    };
    return new Handler[] { echoHeadersHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:25,代码来源:HeadersTest.java

示例6: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler lastModifiedHandler = new ContextHandler("/" + LAST_MODIFIED) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            response.setStatus(200);
            if (lastModified != null) {
                response.setHeader("Last-Modified", lastModified);
            }
            PrintWriter rw = response.getWriter();
            rw.write("lm: " + String.valueOf(lastModified));
            rw.close();
        }
    };
    return new Handler[] { lastModifiedHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:19,代码来源:OnlyIfModifiedTest.java

示例7: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentEncodingHandler = new ContextHandler("/" + CONTENT_ENCODING) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            response.setStatus(200);
            if (contentEncoding != null) {
                response.setHeader("Content-Encoding", contentEncoding);
            }
            PrintWriter rw = response.getWriter();
            rw.write("ce: " + String.valueOf(contentEncoding));
            rw.close();
        }
    };
    return new Handler[] { contentEncodingHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:19,代码来源:ContentEncodingTest.java

示例8: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler echoHeadersHandler = new ContextHandler("/" + TIMEOUT) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            // wait longer than the configured timeout
            try {
                Thread.sleep(TIMEOUT_MS * 10);
            } catch (InterruptedException e) {
                // fall through
            }
        }
    };
    return new Handler[] { echoHeadersHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:18,代码来源:TimeoutTest.java

示例9: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentLengthHandler = new ContextHandler("/" + CONTENT_LENGTH) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            response.setStatus(200);
            if (contentLength != null) {
                response.setHeader("Content-Length", contentLength);
            }
            PrintWriter rw = response.getWriter();
            rw.write("cl: " + String.valueOf(contentLength));
            rw.close();
        }
    };
    return new Handler[] { contentLengthHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:19,代码来源:ContentLengthTest.java

示例10: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentLengthHandler = new ContextHandler("/" + INTERCEPTOR) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            response.setStatus(200);
            
            String message = UNINTERCEPTED;
            String addValue = request.getHeader(ADDITIONAL_REQUEST_HEADER_KEY);
            if (addValue != null) {
                message += ":" + addValue;
            }
            
            PrintWriter rw = response.getWriter();
            rw.write(message);
            rw.close();
        }
    };
    return new Handler[] { contentLengthHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:23,代码来源:InterceptorTest.java

示例11: makeHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler redirectHandler = new ContextHandler("/" + REDIRECT) {
        @Override
        public void handle(String target, HttpServletRequest request,
                HttpServletResponse response, int dispatch)
                        throws IOException, ServletException {
            if (redirects > 0) {
                redirects--;
                if (circular) {
                    response.sendRedirect("/" + REDIRECT);
                } else {
                    response.sendRedirect("/" + REDIRECT + "?r=" + redirects);
                }
            } else {
                response.setStatus(200);
                PrintWriter rw = response.getWriter();
                rw.write("r: " + redirects);
                rw.close();
            }
        }
    };
    return new Handler[] { redirectHandler };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:25,代码来源:RedirectTest.java

示例12: inferMimeType

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
/**
 * Infer the mime type for the response based on the extension of the request
 * URI. Returns null if unknown.
 */
private String inferMimeType(ServletRequest request) {
  String path = ((HttpServletRequest)request).getRequestURI();
  ContextHandler.SContext sContext = (ContextHandler.SContext)config.getServletContext();
  MimeTypes mimes = sContext.getContextHandler().getMimeTypes();
  Buffer mimeBuffer = mimes.getMimeByExtension(path);
  return (mimeBuffer == null) ? null : mimeBuffer.toString();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:12,代码来源:HttpServer2.java

示例13: getServer

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port
 *          port to listen to
 * @param staticContent
 *          folder where static content lives
 * @throws UnknownHostException
 */
public static Server getServer(int port, String staticContent)
    throws UnknownHostException {
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:24,代码来源:CrawlDBTestUtil.java

示例14: configureHandlers

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
private void configureHandlers(ContextHandlerCollection contexts)
{
    // adding extra context handlers
    Iterator handlersIterator = contextHandlers.iterator();
    while (handlersIterator.hasNext())
    {
        ContextHandler contextHandler = (ContextHandler) handlersIterator.next();
        contexts.addHandler(contextHandler);
    }
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:11,代码来源:WebApplicationProxyImpl.java

示例15: getVirtualHost

import org.mortbay.jetty.handler.ContextHandler; //导入依赖的package包/类
/**
 * Get the first virtual host for the context.
 * 
 * Used to help identify the exact session/contextPath.
 * 
 * @return 0.0.0.0 if no virtual host is defined
 */
private String getVirtualHost (ContextHandler.SContext context)
{
    String vhost = "0.0.0.0";
    
    if (context==null)
        return vhost;
    
    String [] vhosts = context.getContextHandler().getVirtualHosts();
    if (vhosts==null || vhosts.length==0 || vhosts[0]==null)
        return vhost;
    
    return vhosts[0];
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:21,代码来源:GigaSessionManager.java


注:本文中的org.mortbay.jetty.handler.ContextHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。