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


Java HttpHandler类代码示例

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


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

示例1: service

import com.alibaba.dubbo.remoting.http.HttpHandler; //导入依赖的package包/类
protected void service(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException {
    HttpHandler handler = handlers.get(request.getLocalPort());
    if( handler == null ) {// service not found.
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Service not found.");
    } else {
        handler.handle(request, response);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:DispatcherServlet.java

示例2: AbstractHttpServer

import com.alibaba.dubbo.remoting.http.HttpHandler; //导入依赖的package包/类
public AbstractHttpServer(URL url, HttpHandler handler){
    if (url == null) {
        throw new IllegalArgumentException("url == null");
    }
    if (handler == null) {
        throw new IllegalArgumentException("handler == null");
    }
    this.url = url;
    this.handler = handler;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:AbstractHttpServer.java

示例3: JettyHttpServer

import com.alibaba.dubbo.remoting.http.HttpHandler; //导入依赖的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);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:JettyHttpServer.java

示例4: TomcatHttpServer

import com.alibaba.dubbo.remoting.http.HttpHandler; //导入依赖的package包/类
public TomcatHttpServer(URL url, final HttpHandler handler) {
        super(url, handler);

        this.url = url;
        DispatcherServlet.addHttpHandler(url.getPort(), handler);
        String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
        tomcat = new Tomcat();
        tomcat.setBaseDir(baseDir);
        tomcat.setPort(url.getPort());
        tomcat.getConnector().setProperty(
                "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));
//        tomcat.getConnector().setProperty(
//                "minSpareThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));

        tomcat.getConnector().setProperty(
                "maxConnections", String.valueOf(url.getParameter(Constants.ACCEPTS_KEY, -1)));

        tomcat.getConnector().setProperty("URIEncoding", "UTF-8");
        tomcat.getConnector().setProperty("connectionTimeout", "60000");

        tomcat.getConnector().setProperty("maxKeepAliveRequests", "-1");
        tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");

        Context context = tomcat.addContext("/", baseDir);
        Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
        context.addServletMapping("/*", "dispatcher");
        ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

        try {
            tomcat.start();
        } catch (LifecycleException e) {
            throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
        }
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:35,代码来源:TomcatHttpServer.java

示例5: service

import com.alibaba.dubbo.remoting.http.HttpHandler; //导入依赖的package包/类
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	HttpHandler handler = handlers.get(request.getLocalPort());

	request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
	AsyncContext asyncCtx = request.startAsync();
	asyncCtx.setTimeout(-1);
	AsyncThread asyncThread = new AsyncThread();
	asyncThread.setRequest(request);
	asyncThread.setResponse(response);
	asyncThread.setHandler(handler);
	asyncThread.setAsyncCtx(asyncCtx);
	ExecutorService executor = (ExecutorService) request.getServletContext().getAttribute("executor");
	executor.execute(asyncThread);
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:16,代码来源:DispatcherServlet.java


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