Search in sources :

Example 1 with DownloadConfiguration

use of de.herrlock.manga.util.configuration.DownloadConfiguration in project Manga by herrlock.

the class TestUtils method testCreateHttpGet.

@Test
public void testCreateHttpGet() throws MalformedURLException {
    URL url = new URL("http", "localhost", 1337, "/");
    Properties p = new Properties();
    p.setProperty(Configuration.URL, url.toExternalForm());
    DownloadConfiguration conf = DownloadConfiguration.create(p);
    HttpGet httpGet = Utils.createHttpGet(url, conf);
    URI uri = httpGet.getURI();
    Assert.assertEquals("http://localhost:1337/", uri.toString());
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Properties(java.util.Properties) URI(java.net.URI) URL(java.net.URL) DownloadConfiguration(de.herrlock.manga.util.configuration.DownloadConfiguration) Test(org.junit.Test)

Example 2 with DownloadConfiguration

use of de.herrlock.manga.util.configuration.DownloadConfiguration in project Manga by herrlock.

the class TestUtils method testExecuteHttpGet.

@Test
public void testExecuteHttpGet() throws ClientProtocolException, IOException {
    final String MAGIC_SUPER_SECRET_STRING = "somethingRandom";
    HttpRequestHandler requestHandler = new SetStringHttpRequestHandler(MAGIC_SUPER_SECRET_STRING);
    HttpServer server = ServerBootstrap.bootstrap().setListenerPort(1337).registerHandler("/", requestHandler).create();
    URL url = new URL("http", "localhost", 1337, "/");
    Properties p = new Properties();
    p.setProperty(Configuration.URL, url.toExternalForm());
    DownloadConfiguration conf = DownloadConfiguration.create(p);
    ResponseHandler<Boolean> responseHandler = new ResponseEqualsStringResponseHandler(MAGIC_SUPER_SECRET_STRING);
    server.start();
    Utils.getDataAndExecuteResponseHandler(url, conf, responseHandler);
    server.stop();
}
Also used : HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpServer(org.apache.http.impl.bootstrap.HttpServer) Properties(java.util.Properties) URL(java.net.URL) DownloadConfiguration(de.herrlock.manga.util.configuration.DownloadConfiguration) Test(org.junit.Test)

Example 3 with DownloadConfiguration

use of de.herrlock.manga.util.configuration.DownloadConfiguration in project Manga by herrlock.

the class Main method startCliDownloader.

private static void startCliDownloader(final CommandLine commandline) {
    logger.traceEntry("Commandline: {}", commandline);
    if (commandline.hasOption("hoster")) {
        logger.info("Printing all Hoster:");
        PrintAllHoster.printHoster(System.out);
    } else {
        Properties properties = // 
        Utils.newPropertiesBuilder().setProperty(Configuration.URL, // 
        commandline.getOptionValue("url")).setProperty(Configuration.PROXY, // 
        commandline.getOptionValue("proxy")).setProperty(Configuration.PATTERN, // 
        commandline.getOptionValue("pattern")).setProperty(Configuration.TIMEOUT, // 
        commandline.getOptionValue("timeout")).setProperty(Configuration.HEADLESS, // 
        String.valueOf(commandline.hasOption('i'))).build();
        if (commandline.hasOption("list")) {
            logger.info("Creating index");
            IndexerConfiguration conf = IndexerConfiguration.create(properties);
            logger.info(conf);
            IndexerMain.writeIndex(conf);
        } else {
            logger.info("Starting Commandline-Downloader:");
            DownloadConfiguration conf = DownloadConfiguration.create(properties);
            logger.info(conf);
            ConsoleDownloader downloader = new ConsoleDownloader(conf, conf.isHeadless());
            DownloadProcessor.getInstance().addDownload(downloader);
        }
    }
}
Also used : IndexerConfiguration(de.herrlock.manga.util.configuration.IndexerConfiguration) ConsoleDownloader(de.herrlock.manga.downloader.ConsoleDownloader) Properties(java.util.Properties) DownloadConfiguration(de.herrlock.manga.util.configuration.DownloadConfiguration)

Example 4 with DownloadConfiguration

use of de.herrlock.manga.util.configuration.DownloadConfiguration in project Manga by herrlock.

the class SettingsFileDownloader method execute.

public static void execute() {
    logger.traceEntry();
    Properties p = new Properties();
    // load properties
    try (InputStream fIn = new FileInputStream(Constants.SETTINGS_FILE)) {
        p.load(fIn);
    } catch (IOException ex) {
        throw new MDRuntimeException(ex);
    }
    // properties loaded successful
    DownloadConfiguration conf = DownloadConfiguration.create(p);
    SettingsFileDownloader dlImpl = new SettingsFileDownloader(conf);
    DownloadProcessor.getInstance().addDownload(dlImpl);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) DownloadConfiguration(de.herrlock.manga.util.configuration.DownloadConfiguration)

Aggregations

DownloadConfiguration (de.herrlock.manga.util.configuration.DownloadConfiguration)4 Properties (java.util.Properties)4 URL (java.net.URL)2 Test (org.junit.Test)2 ConsoleDownloader (de.herrlock.manga.downloader.ConsoleDownloader)1 MDRuntimeException (de.herrlock.manga.exceptions.MDRuntimeException)1 IndexerConfiguration (de.herrlock.manga.util.configuration.IndexerConfiguration)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpServer (org.apache.http.impl.bootstrap.HttpServer)1 HttpRequestHandler (org.apache.http.protocol.HttpRequestHandler)1