本文整理汇总了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();
}
示例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);
}
}
}