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

Java HttpServer类代码示例

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

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



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

示例1: getDefaultServer

import org.apache.http.impl.bootstrap.HttpServer; //导入依赖的package包/类
private static HttpServer getDefaultServer(Path folderRoot) {
    return ServerBootstrap.bootstrap()
            .setListenerPort(PhotatoConfig.serverPort)
            .setServerInfo(serverName)
            .setSocketConfig(getSocketConfig())
            .setExceptionLogger(new StdErrorExceptionLogger())
            .registerHandler("*", new LoadingHandler(folderRoot))
            .create();
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:10,代码来源:Photato.java


示例2: main

import org.apache.http.impl.bootstrap.HttpServer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Usage: <picturesRootFolder> [cacheFolder] [configFolder]");
        System.exit(-1);
    }

    FileSystem fileSystem = FileSystems.getDefault();
    Path rootFolder = getRootFolder(fileSystem, args[0]);
    String cacheRootFolder = (args.length >= 2 ? args[1] : "cache");
    String thumbnailCacheFolder = cacheRootFolder + "/thumbnails";
    String fullscreenCacheFolder = cacheRootFolder + "/fullscreen";
    String extractedPicturesCacheFolder = cacheRootFolder + "/extracted";
    String configFile = (args.length >= 3 ? args[2] : ".") + "/photato.ini";

    PhotatoConfig.init(configFile);

    System.out.println("Starting photato");
    System.out.println("-- Config file: " + configFile);
    System.out.println("-- Cache folder: " + cacheRootFolder);
    System.out.println("-- Pictures folder: " + rootFolder);

    HttpServer server = getDefaultServer(fileSystem.getPath("www"));
    server.start();

    if (!Files.exists(fileSystem.getPath("cache"))) {
        Files.createDirectory(fileSystem.getPath("cache"));
    }

    HttpClient httpClient = HttpClientBuilder.create().setUserAgent(serverName).build();

    ExifToolDownloader.run(httpClient, fileSystem, PhotatoConfig.forceFfmpegToolsDownload);
    FfmpegDownloader.run(httpClient, fileSystem, PhotatoConfig.forceExifToolsDownload);

    ThumbnailGenerator thumbnailGenerator = new ThumbnailGenerator(fileSystem, rootFolder, thumbnailCacheFolder, extractedPicturesCacheFolder, PhotatoConfig.thumbnailHeight, PhotatoConfig.thumbnailQuality);
    IGpsCoordinatesDescriptionGetter gpsCoordinatesDescriptionGetter = new OSMGpsCoordinatesDescriptionGetter(httpClient, PhotatoConfig.addressElementsCount);
    MetadataAggregator metadataGetter = new MetadataAggregator(fileSystem, "cache/metadata.cache", gpsCoordinatesDescriptionGetter);
    FullScreenImageGetter fullScreenImageGetter = new FullScreenImageGetter(fileSystem, rootFolder, fullscreenCacheFolder, extractedPicturesCacheFolder, PhotatoConfig.fullScreenPictureQuality, PhotatoConfig.maxFullScreenPictureWitdh, PhotatoConfig.maxFullScreenPictureHeight);

    PhotatoFilesManager photatoFilesManager = new PhotatoFilesManager(rootFolder, fileSystem, metadataGetter, thumbnailGenerator, fullScreenImageGetter, PhotatoConfig.prefixModeOnly, PhotatoConfig.indexFolderName, PhotatoConfig.useParallelPicturesGeneration);

    // Closing tmp server
    server.shutdown(5, TimeUnit.SECONDS);

    while (true) {
        try {
            server = ServerBootstrap.bootstrap()
                    .setListenerPort(PhotatoConfig.serverPort)
                    .setServerInfo(serverName)
                    .setSocketConfig(getSocketConfig())
                    .setExceptionLogger(new StdErrorExceptionLogger())
                    .registerHandler(Routes.rawVideosRootUrl + "/*", new VideoHandler(rootFolder, Routes.rawVideosRootUrl))
                    .registerHandler(Routes.rawPicturesRootUrl + "/*", new ImageHandler(rootFolder, Routes.rawPicturesRootUrl))
                    .registerHandler(Routes.fullScreenPicturesRootUrl + "/*", new ImageHandler(fileSystem.getPath(fullscreenCacheFolder), Routes.fullScreenPicturesRootUrl))
                    .registerHandler(Routes.thumbnailRootUrl + "/*", new ImageHandler(fileSystem.getPath(thumbnailCacheFolder), Routes.thumbnailRootUrl))
                    .registerHandler(Routes.listItemsApiUrl, new FolderListHandler(Routes.listItemsApiUrl, photatoFilesManager))
                    .registerHandler("/img/*", new ImageHandler(fileSystem.getPath("www/img"), "/img"))
                    .registerHandler("/js/*", new JsHandler(fileSystem.getPath("www/js"), "/js"))
                    .registerHandler("/css/*", new CssHandler(fileSystem.getPath("www/css"), "/css"))
                    .registerHandler("*", new DefaultHandler(fileSystem.getPath("www")))
                    .create();
            server.start();
            System.out.println("Server started on port " + server.getLocalPort() + " (http://" + getLocalIp() + ":" + server.getLocalPort() + ")");
            server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        } catch (IOException | InterruptedException ex) {
            // In case of port already binded
            System.err.println("Could not start the server ...");
            Thread.sleep(1000);
        }
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:71,代码来源:Photato.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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