• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ServletManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: doStart

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的package包/类
protected void doStart(URL url) {
    // TODO jetty will by default enable keepAlive so the xml config has no effect now
    httpServer = httpBinder.bind(url, new RestHandler());

    ServletContext servletContext = ServletManager.getInstance().getServletContext(url.getPort());
    if (servletContext == null) {
        servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
    }
    if (servletContext == null) {
        throw new RpcException("No servlet context found. If you are using server='servlet', " +
                "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
    }

    servletContext.setAttribute(ResteasyDeployment.class.getName(), deployment);

    try {
        dispatcher.init(new SimpleServletConfig(servletContext));
    } catch (ServletException e) {
        throw new RpcException(e);
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:DubboHttpServer.java


示例2: doExport

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:45,代码来源:RestProtocol.java


示例3: TomcatHttpServer

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的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


示例4: close

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的package包/类
public void close() {
    super.close();

    ServletManager.getInstance().removeServletContext(url.getPort());

    try {
        tomcat.stop();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:12,代码来源:TomcatHttpServer.java


示例5: close

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的package包/类
public void close() {
    super.close();

    // modified by lishen
    ServletManager.getInstance().removeServletContext(url.getPort());

    if (server != null) {
        try {
            server.stop();
        } catch (Exception e) {
            logger.warn(e.getMessage(), e);
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:15,代码来源:JettyHttpServer.java


示例6: TomcatHttpServer

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

        this.url = url;
        DispatcherServlet.addHttpHandler(url.getPort(), handler);
        tomcat = new Tomcat();
        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");


        File baseDir = new File(System.getProperty("java.io.tmpdir"));
        Context context = tomcat.addContext("/", baseDir.getAbsolutePath());
        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:lsjiguang,项目名称:dangdangdotcom,代码行数:35,代码来源:TomcatHttpServer.java


示例7: JettyHttpServer

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

        // modified by lishen
        this.url = url;
        // TODO we should leave this setting to slf4j
        Log.setLog(new StdErrLog());
        Log.getLog().setDebugEnabled(false);

        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);

        // modified by lishen
        // dubbo's original impl can't support the use of ServletContext
//        server.addHandler(servletHandler);
        // TODO Context.SESSIONS is the best option here?
        Context context = new Context(server, "/", Context.SESSIONS);
        context.setServletHandler(servletHandler);
        ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

        try {
            server.start();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                            + e.getMessage(), e);
        }
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:47,代码来源:JettyHttpServer.java


示例8: doExport

import com.alibaba.dubbo.remoting.http.servlet.ServletManager; //导入依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    // dubbo 服务多版本
    String version = url.getParameter(Constants.VERSION_KEY);
    if (StringUtils.isNotEmpty(version)) {
        contextPath = version + "/" + contextPath;
    }
    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
开发者ID:sdcuike,项目名称:dubbo-rpc-rest,代码行数:50,代码来源:RestProtocol.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UntargettedBinding类代码示例发布时间:2022-05-23
下一篇:
Java WebSocketListener类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap