コード例 #1
0
 @Inject
 private TestProvider(
     @HttpServerConfigurations Configurations configurations1,
     @Named("foobar") Map<String, Integer> map,
     Configurations configurations2) {
   /* This will be constructed up at initialization of the app, before any request is done */
   Assert.assertFalse(
       configurations1.extract("listeners").isEmpty()); /* HTTP configs have listeners */
   Assert.assertTrue(configurations2.containsKey("conf")); /* All applications have a "conf" key */
   Assert.assertSame(map, ServerBuilderTest.DEPENDENCY); /* Check we got the *SAME* map */
 }
コード例 #2
0
  @BeforeClass
  public void prepare() throws IOException {
    final Configurations configurations = new JsonConfigurations(IO.resource("test.js"));

    Guice.createInjector(
            (binder) ->
                new MongoBuilder(binder)
                    .configure(configurations.strip("mongo"))
                    .store(ValidatedBean.class, collection)
                    .withValidation())
        .injectMembers(this);
  }
コード例 #3
0
  public AccessLogProvider(Configurations configurations) {
    accessLog = configurations.requireFile("file");

    /* Start building our access log */
    final AccessLogBuilder accessLogBuilder = new AccessLogBuilder(accessLog);

    /* Configure log rotation, if necessary */
    final String rotate = configurations.getString("rotate", null);
    if (rotate != null)
      switch (rotate.toLowerCase()) {
        case "daily":
          accessLogBuilder.rotatedDaily();
          break;
        case "hourly":
          accessLogBuilder.rotatedHourly();
          break;
        default:
          throw new IllegalStateException(
              "Unsupported value \"" + rotate + "\" for parameter \"rotate\"");
      }
    else {
      final String rotationPattern = configurations.getString("rotationPattern");
      if (rotationPattern != null) accessLogBuilder.rotationPattern(rotationPattern);
    }

    /* Synchronous log? (not by default) */
    accessLogBuilder.synchronous(configurations.get("synchronous", false));

    /* Set the format, if we have to */
    final String format = configurations.getString("format", null);
    if (format != null) accessLogBuilder.format(format);

    /* Finally configure time zone, if we need to... */
    final String timezone = configurations.getString("timezone", null);
    if (timezone != null) accessLogBuilder.timeZone(timezone);

    /* Great! Instrument our server configurations */
    probe = accessLogBuilder.build();
  }