10

I have a Spring Boot project, built using Maven, where I intend to use embedded mongo db. I am using Eclipse on Windows 7.

I am behind a proxy that uses automatic configuration script, as I have observed in the Connection tab of Internet Options. I am getting the following exception when I try to run the application.

java.io.IOException: Could not open inputStream for https://downloads.mongodb.org/win32/mongodb-win32-i386-3.2.2.zip at de.flapdoodle.embed.process.store.Downloader.downloadInputStream(Downloader.java:131) ~[de.flapdoodle.embed.process-2.0.1.jar:na] at de.flapdoodle.embed.process.store.Downloader.download(Downloader.java:69) ~[de.flapdoodle.embed.process-2.0.1.jar:na] ....

MongoDB gets downloaded just fine, when I hit the following URL in my web browser:

https://downloads.mongodb.org/win32/mongodb-win32-i386-3.2.2.zip

This leads me to believe that probably I'm missing some configuration in my Eclipse or may be the maven project itself. Please help me to find the right configuration.

de_xtr
  • 882
  • 2
  • 10
  • 21
  • 1
    Using [`de.flapdoodle.embed.mongo`](https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo)? Bit surprised people are still using it if so. All it does in downloads and runs a mongodb installation. Seems a large number of "spring boot" users are under the misconception this is an "embedded database", but that simply is not true. – Neil Lunn May 29 '18 at 08:53
  • I want to use it for dev testing. – de_xtr May 29 '18 at 09:09
  • use cntlm for your issue that will solve everything. Use this [guide](https://stackoverflow.com/a/24540105/1802348) – positivecrux Jun 06 '18 at 07:11

6 Answers6

9

What worked for me on a windows machine:

Download the zip file (https://downloads.mongodb.org/win32/mongodb-win32-i386-3.2.2.zip) manually and put it (not unpack) into this folder:

C:\Users\<Username>\.embedmongo\win32\
d2k2
  • 726
  • 8
  • 16
2

Indeed the problem is about your proxy (a corporate one I guess).

If the proxy do not require authentication, you can solve your problem easily just by adding the appropriate -Dhttp.proxyHost=... and -Dhttp.proxyPort=... (or/and the same with "https.[...]") as JVM arguments in your eclipse junit Runner, as suggested here : https://github.com/learning-spring-boot/learning-spring-boot-2nd-edition-code/issues/2

Michael Zilbermann
  • 1,398
  • 9
  • 19
1

One solution to your problem is to do the following.

  1. Download MongoDB and place it on a ftp server which is inside your corporate network (for which you would not need proxy).

  2. Then write a configuration in your project like this

    @Bean
    @ConditionalOnProperty("mongo.proxy")
    public IRuntimeConfig embeddedMongoRuntimeConfig() {
        final Command command = Command.MongoD;
        final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaults(command)
            .artifactStore(new ExtractedArtifactStoreBuilder()
                .defaults(command)
                .download(new DownloadConfigBuilder()
                    .defaultsForCommand(command)
                    .downloadPath("your-ftp-path")
                    .build())
                .build())
            .build();
        return runtimeConfig;
    }
    

With the property mongo.proxy you can control whether Spring Boot downloads MongoDB from your ftp server or from outside. If it is set to true then it downloads from the ftp server. If not then it tries to download from the internet.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
pvpkiran
  • 25,582
  • 8
  • 87
  • 134
1

The easiest way seems to me to customize the default configuration:

@Bean
DownloadConfigBuilderCustomizer mongoProxyCustomizer() {
    return configBuilder -> {
        configBuilder.proxyFactory(new HttpProxyFactory(host, port));
    };
}
mibollma
  • 14,959
  • 6
  • 52
  • 69
0

Got the same issue (with Spring Boot 2.6.1 the spring.mongodb.embedded.version property is mandatory).

To configure the proxy, I've added the configuration bean by myself:


    @Value("${spring.mongodb.embedded.proxy.domain}")
    private String proxyDomain;

    @Value("${spring.mongodb.embedded.proxy.port}")
    private Integer proxyPort;

    @Bean
    RuntimeConfig embeddedMongoRuntimeConfig(ObjectProvider<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
        Logger logger = LoggerFactory.getLogger(this.getClass().getPackage().getName() + ".EmbeddedMongo");
        ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.INFO), Processors.logTo(logger, Slf4jLevel.ERROR), Processors.named("[console>]", Processors.logTo(logger, Slf4jLevel.DEBUG)));
        return Defaults.runtimeConfigFor(Command.MongoD, logger).processOutput(processOutput).artifactStore(this.getArtifactStore(logger, downloadConfigBuilderCustomizers.orderedStream())).isDaemonProcess(false).build();
    }

    private ExtractedArtifactStore getArtifactStore(Logger logger, Stream<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
        de.flapdoodle.embed.process.config.store.ImmutableDownloadConfig.Builder downloadConfigBuilder = Defaults.downloadConfigFor(Command.MongoD);
        downloadConfigBuilder.progressListener(new Slf4jProgressListener(logger));
        downloadConfigBuilderCustomizers.forEach((customizer) -> {
            customizer.customize(downloadConfigBuilder);
        });
        DownloadConfig downloadConfig = downloadConfigBuilder
                .proxyFactory(new HttpProxyFactory(proxyDomain, proxyPort))  // <--- HERE
                .build();
        return Defaults.extractedArtifactStoreFor(Command.MongoD).withDownloadConfig(downloadConfig);
    }
Nicolas
  • 1,812
  • 3
  • 19
  • 43
0

In my case, I had to add the HTTPS corporate proxy to Intellij Run Configuration.

Https because it was trying to download:

https://downloads.mongodb.org/win32/mongodb-win32-x86_64-4.0.2.zip

application.properties:

spring.data.mongodb.database=test
spring.data.mongodb.port=27017
spring.mongodb.embedded.version=4.0.2

Please keep in mind this is a (DEV) setup.

enter image description here

JCompetence
  • 6,997
  • 3
  • 19
  • 26