com.yammer.dropwizard.config.Environment Java Examples

The following examples show how to use com.yammer.dropwizard.config.Environment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocialiteService.java    From socialite with Apache License 2.0 6 votes vote down vote up
@Override
public void run(SocialiteConfiguration config, Environment environment) throws Exception {
  	        
   	// Get the configured default MongoDB URI
    MongoClientURI default_uri = config.mongodb.default_database_uri;
    
    // Initialize the services as per configuration
    ServiceManager services = new ServiceManager(config.services, default_uri);
    environment.manage(services);
           
    // Register the custom ExceptionMapper to handle ServiceExceptions
    environment.addProvider(new ServiceExceptionMapper());
    
    environment.addResource( new UserResource( services.getContentService(),
            services.getFeedService(), services.getUserGraphService() ) );
}
 
Example #2
Source File: DataService.java    From cognition with Apache License 2.0 5 votes vote down vote up
/**
 * Establishes an environment and configures resources need to
 * execute service. Optional service health checks.
 */
@Override
public void run(DataConfiguration configuration, Environment environment) {
  final LensEndpoint restResource = new LensEndpoint();
  environment.addResource(restResource);
  /*final JsonLensEndpoint jsonResource = new JsonLensEndpoint();
  environment.addResource(jsonResource);*/

  // Application complains if health check not included. Can add more robust
  // service tests later for more complete code base.
  environment.addHealthCheck(new ServiceHealthCheck());
}
 
Example #3
Source File: SampleApplication.java    From cukes with Apache License 2.0 5 votes vote down vote up
@Override
public void run(SampleConfiguration configuration, Environment environment) {
    overrideLogging();
    Injector injector = Guice.createInjector();
    environment.addResource(injector.getInstance(GadgetResource.class));
    environment.addResource(injector.getInstance(StaticTypesResource.class));
    environment.addResource(injector.getInstance(CustomHeadersResource.class));
    environment.addResource(injector.getInstance(MultipartResource.class));
    environment.addResource(injector.getInstance(BinaryStreamResource.class));
    environment.addHealthCheck(injector.getInstance(SampleHealthCheck.class));
}
 
Example #4
Source File: HVDFService.java    From hvdf with Apache License 2.0 5 votes vote down vote up
@Override
public void run(HVDFConfiguration config, Environment environment) throws Exception {
  	        
   	// Get the configured default MongoDB URI
    MongoClientURI default_uri = config.mongodb.default_database_uri;
    
    // Initialize the services as per configuration
    ServiceManager services = new ServiceManager(config.services, default_uri);
    environment.manage(services);
           
    // Register the custom ExceptionMapper to handle ServiceExceptions
    environment.addProvider(new ServiceExceptionMapper());
    
    environment.addResource( new FeedResource( services.getChannelService()) );
}
 
Example #5
Source File: ExampleService.java    From rack-servlet with Apache License 2.0 5 votes vote down vote up
@Override public void run(Configuration config, Environment environment) {
  // Suppress the "THIS SERVICE HAS NO HEALTHCHECKS" warning.
  // A real service would have proper health checks.
  environment.addHealthCheck(new FakeHealthCheck());

  // Suppress the "ResourceConfig instance does not contain any root resource classes" error.
  // A real service would probably provide a Jersey resource or two.
  environment.addResource(EmptyResource.class);

  // Here's the interesting part:
  // Mount the Rack application defined in the config.ru file on the classpath at /rack.
  environment.addServlet(createRackServlet(), "/rack/*");
}
 
Example #6
Source File: PizzaService.java    From jersey-hmac-auth with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
    environment.addResource(new PizzaResource());
    environment.addHealthCheck(new PizzaHealthCheck());
    environment.addProvider(new HmacAuthProvider<>(new DefaultRequestHandler<>(new PizzaAuthenticator())));
}
 
Example #7
Source File: WarAssetsBundle.java    From wiztowar with MIT License 4 votes vote down vote up
@Override
public void run(Environment environment) {
    environment.addServlet(createServlet(), uriPath + '*');
}
 
Example #8
Source File: ChanceryService.java    From chancery with Apache License 2.0 4 votes vote down vote up
private Client buildGithubHttpClient(final ChanceryConfig config,
                                     final Environment env) {
    return new JerseyClientBuilder().
            using(config.getGithubHttpConfig()).
            using(env).build();
}
 
Example #9
Source File: ChanceryService.java    From chancery with Apache License 2.0 4 votes vote down vote up
@Override
public void run(final ChanceryConfig config, final Environment env)
        throws Exception {
    final EventBus callbackBus = buildCallbackBus(config);

    final GithubClient ghClient = new GithubClient(
            buildGithubHttpClient(config, env),
            config.getGithubOauth2Token()
    );

    final String githubSecret = config.getGithubSecret();
    final GithubAuthChecker ghAuthChecker =
            (githubSecret == null) ? null :
                    new GithubAuthChecker(githubSecret);

    env.addHealthCheck(new GithubClientHealthCheck(ghClient));

    final List<RefLoggerConfig> refLoggerConfigs = config.getRefLogs();
    if (refLoggerConfigs != null)
        for (RefLoggerConfig refLoggerConfig : refLoggerConfigs) {
            log.info("Creating ref logger for {}", refLoggerConfig);
            final RefLogger refLogger = new RefLogger(refLoggerConfig, ghClient);
            callbackBus.register(refLogger);
        }

    final List<S3ArchiverConfig> s3ArchiverConfigs = config.getS3Archives();
    if (s3ArchiverConfigs != null) {
        final AmazonS3Client s3Client = buildS3Client(config);
        final HashSet<String> buckets = new HashSet<>();

        for (S3ArchiverConfig s3ArchiverConfig : s3ArchiverConfigs) {
            log.info("Creating S3 archiver for {}", s3ArchiverConfig);
            callbackBus.register(new S3Archiver(s3ArchiverConfig, s3Client, ghClient));
            buckets.add(s3ArchiverConfig.getBucketName());
        }

        for (String bucketName : buckets)
            env.addHealthCheck(new S3ClientHealthCheck(s3Client, bucketName));
    }

    final CallbackResource resource = new CallbackResource(ghAuthChecker, callbackBus);
    env.addResource(resource);
}
 
Example #10
Source File: SimulatorService.java    From tr069-simulator with MIT License 4 votes vote down vote up
@Override
public void run(SimulatorConfiguration configuration, final Environment environment) {

	String currentDir = System.getProperty("user.dir");
	String filepath = currentDir + File.separator + "agent.csv"; 
	//System.out.println("Current Filepath Checking >>>> " + filepath );
	File userfile = new File (filepath);
	if (!userfile.exists()) {
		filepath = "/conf/agent.csv";
	}
	//System.out.println(" Loaded Agent Filepath:  " + filepath);
	CPEUtil util = new CPEUtil();
	ArrayList<String> csvlist = util.parseFile(filepath);
	int csvlen = csvlist.size();
	int threadcnt = 1;
	String ipadr = "";
	for (int f = 0; f < csvlen; f++ ) {
		String csvline 	= csvlist.get(f);			
		//System.out.println("CSV Line   >>>>>>>>>   " + csvline);
		String[] tokens = csvline.split(",");
		if(tokens.length >= 7) { 
			String 	startip 	= tokens[0].trim();
			String 	endip   	= tokens[1].trim();
			String 	acsurl 		= tokens[2].trim();
			String 	requrl 		= tokens[3].trim();
			String 	httpport	= tokens[4].trim();
			String 	infmperiod	= tokens[5].trim();
			String 	dumploc		= tokens[6].trim();
			String 	username	= null;
			String 	passwd		= null;
			String 	authtype	= null;
			
			if(tokens.length >= 10) { 
				username	= tokens[7].trim();
				passwd		= tokens[8].trim();
				authtype	= tokens[9].trim();	
			}
			ArrayList<String> iplist = new ArrayList<String>();
			if (!util.isValidIPAddress(startip)) {
				continue;
			}
			if (!util.isValidIPAddress(endip)) {
				iplist.add(startip);
			} else {
				iplist = util.range2iplist(startip, endip);
			}
			int port  		= Integer.parseInt(httpport);
			int infmprd		= Integer.parseInt(infmperiod);
			int ipsize 		= iplist.size();
			for (int i = 0; i < ipsize; i++) {
				ipadr 				= iplist.get(i);
				CPEWorker worker 	= new CPEWorker(ipadr, port + threadcnt, acsurl, requrl, infmprd, dumploc, username, passwd, authtype, threadcnt++);
				Thread cpthread 	= new Thread(worker, "WorkerThread_" + threadcnt);
				cpthread.start();
			}
		}
	}
}
 
Example #11
Source File: SpringSecurityProvider.java    From osiris with Apache License 2.0 3 votes vote down vote up
protected void registerSpringSecurityFilters(Environment environment) {

		SecurityFilterChain filterChain = context.getBean(SecurityFilterChain.class);

		for (Filter filter : filterChain.getFilters()) {

			environment.addFilter(filter, "/*");
		}
		
		
	}
 
Example #12
Source File: SpringSecurityProvider.java    From osiris with Apache License 2.0 2 votes vote down vote up
public void registerProvider(Environment environment) {

		registerSpringSecurityFilters(environment);

		environment.addProvider(this);
	}