Server.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:geosummly 作者:
/**
 * Starts Grizzly HTTP server exposing static content, JAX-RS resources
 * and web sockets defined in this application.
 *
 * @param webRootPath static content root path.
 * @return Grizzly HTTP server.
 */
public static HttpServer startServer(String webRootPath) 
{
    final HttpServer server = new HttpServer();
    final NetworkListener listener = new NetworkListener("grizzly", BASE_URI, PORT);

    server.addListener(listener);

    final ServerConfiguration config = server.getServerConfiguration();
    // add handler for serving static content
    config.addHttpHandler(new StaticContentHandler(webRootPath), APP_PATH);

    // add handler for serving JAX-RS resources
    config.addHttpHandler(  RuntimeDelegate
                            .getInstance()
                            .createEndpoint(new ResourceConfig().packages("it.unito.geosummly.api"),
                                            GrizzlyHttpContainer.class),
                                            API_PATH
                          );

    try {
        // Start the server.
        server.start();
    } catch (Exception ex) {
        throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
    }

    return server;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号