package at.ac.univie.isc.asio;

import at.ac.univie.isc.asio.munin.Pigeon;
import at.ac.univie.isc.asio.security.AllowAllVerifier;
import at.ac.univie.isc.asio.security.NoopTrustManager;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import javax.net.ssl.SSLContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import java.security.GeneralSecurityException;

@SpringBootApplication
@EnableConfigurationProperties(MuninSettings.class)
public class Munin {

  @Autowired
  private MuninSettings config;

  public static void main(String[] args) {
    new SpringApplicationBuilder(Munin.class)
        .web(false)
        .logStartupInfo(false)
        .showBanner(false)
        .run(args);
  }

  @Bean
  public Appendable console() {
    return System.out;
  }

  @Bean
  public Pigeon pigeon(final Client client) {
    return Pigeon.connectTo(client.target(config.getServerAddress()));
  }

  @Bean
  public Client httpClient() throws GeneralSecurityException {
    final Client client;
    if (config.isInsecureConnection()) {
      final SSLContext ssl = SSLContext.getInstance("TLS");
      ssl.init(null, NoopTrustManager.asArray(), null);
      client = ClientBuilder.newBuilder()
          .hostnameVerifier(AllowAllVerifier.instance())
          .sslContext(ssl)
          .build();
    } else {
      client = ClientBuilder.newClient();
    }
    final HttpAuthenticationFeature authentication =
        HttpAuthenticationFeature.basic(config.getUsername(), config.getPassword());
    client.register(authentication);
    return client;
  }
}

@@ -366,32 +366,127 @@
 nfigure.
-SpringBootApplic
+PropertyPlaceholderAutoConfiguration;%0Aimport org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigur
 ation;%0Ai
@@ -688,238 +688,538 @@
 an;%0A
-%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.ws.rs.client.Client;%0Aimport javax.ws.rs.client.ClientBuilder;%0Aimport java.security.GeneralSecurityException;%0A%0A@SpringBootApplication%0A@EnableConfigurationProperties(MuninSettings.class
+import org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.context.annotation.Import;%0A%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.ws.rs.client.Client;%0Aimport javax.ws.rs.client.ClientBuilder;%0Aimport java.security.GeneralSecurityException;%0A%0A@Configuration%0A@ComponentScan(%22at.ac.univie.isc.asio.munin%22)%0A@EnableConfigurationProperties(MuninSettings.class)%0A@Import(%7BPropertyPlaceholderAutoConfiguration.class, JacksonAutoConfiguration.class%7D
 )%0Apu

Improve spring startup in Munin