Commit 24890a47 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

use reflections to iterate over registered resources

parent e3772e66
package com.telephoners.krakyournet.ctf;
import com.bazaarvoice.dropwizard.webjars.WebJarBundle;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.telephoners.krakyournet.ctf.auth.ExampleAuthenticator;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.commands.PurgeDatabaseCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTasksCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTeamsCommand;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.logging.LoggingFilter;
import com.telephoners.krakyournet.ctf.modules.ApplicationModule;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.repositories.UsersRepository;
import com.telephoners.krakyournet.ctf.resources.*;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.auth.AuthDynamicFeature;
......@@ -24,6 +25,7 @@ import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import java.io.IOException;
import java.util.stream.Stream;
public class CTFApplication extends Application<ApplicationConfiguration>
......@@ -42,16 +44,13 @@ public class CTFApplication extends Application<ApplicationConfiguration>
.forEach(bootstrap::addBundle);
}
private void registerResources(Environment environment)
private void registerResources(Environment environment) throws IOException
{
//todo: use reflections to iterate over resources
JerseyEnvironment jersey = environment.jersey();
jersey.register(injector.getInstance(TeamsResource.class));
jersey.register(injector.getInstance(TasksResource.class));
jersey.register(injector.getInstance(ProxyResource.class));
jersey.register(injector.getInstance(SolutionsResource.class));
jersey.register(injector.getInstance(TaskResource.class));
jersey.register(injector.getInstance(UtilResource.class));
final ClassPath classPath = ClassPath.from(this.getClass().getClassLoader());
ImmutableSet<ClassPath.ClassInfo> resourceClasses = classPath.getTopLevelClasses("com.telephoners.krakyournet.ctf.resources");
resourceClasses.stream()
.forEach(classInfo -> jersey.register(injector.getInstance(classInfo.load())));
}
private void registerAuthFeatures(Environment environment)
......
......@@ -9,9 +9,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@Singleton
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment