http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/SearchModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/SearchModule.java b/src/org/waveprotocol/box/server/SearchModule.java index 9848a7f..4422155 100644 --- a/src/org/waveprotocol/box/server/SearchModule.java +++ b/src/org/waveprotocol/box/server/SearchModule.java @@ -22,24 +22,11 @@ package org.waveprotocol.box.server; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.name.Named; - +import com.typesafe.config.Config; import org.waveprotocol.box.server.persistence.file.FileUtils; import org.waveprotocol.box.server.persistence.lucene.FSIndexDirectory; import org.waveprotocol.box.server.persistence.lucene.IndexDirectory; -import org.waveprotocol.box.server.waveserver.LucenePerUserWaveViewHandlerImpl; -import org.waveprotocol.box.server.waveserver.LuceneWaveIndexerImpl; -import org.waveprotocol.box.server.waveserver.MemoryPerUserWaveViewHandlerImpl; -import org.waveprotocol.box.server.waveserver.MemoryWaveIndexerImpl; -import org.waveprotocol.box.server.waveserver.NoOpWaveIndexerImpl; -import org.waveprotocol.box.server.waveserver.PerUserWaveViewBus; -import org.waveprotocol.box.server.waveserver.PerUserWaveViewHandler; -import org.waveprotocol.box.server.waveserver.PerUserWaveViewProvider; -import org.waveprotocol.box.server.waveserver.SearchProvider; -import org.waveprotocol.box.server.waveserver.SimpleSearchProviderImpl; -import org.waveprotocol.box.server.waveserver.SolrSearchProviderImpl; -import org.waveprotocol.box.server.waveserver.SolrWaveIndexerImpl; -import org.waveprotocol.box.server.waveserver.WaveIndexer; +import org.waveprotocol.box.server.waveserver.*; /** * @author [email protected] (Yuri Zelikov) @@ -50,10 +37,9 @@ public class SearchModule extends AbstractModule { private final String indexDirectory; @Inject - public SearchModule(@Named(CoreSettings.SEARCH_TYPE) String searchType, - @Named(CoreSettings.INDEX_DIRECTORY) String indexDirectory) { - this.searchType = searchType; - this.indexDirectory = indexDirectory; + public SearchModule(Config config) { + this.searchType = config.getString("core.search_type"); + this.indexDirectory = config.getString("core.index_directory"); } @Override
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/ServerMain.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/ServerMain.java b/src/org/waveprotocol/box/server/ServerMain.java index 94ee5ae..50a8b7c 100644 --- a/src/org/waveprotocol/box/server/ServerMain.java +++ b/src/org/waveprotocol/box/server/ServerMain.java @@ -19,22 +19,18 @@ package org.waveprotocol.box.server; -import org.waveprotocol.box.server.executor.ExecutorsModule; import cc.kune.initials.InitialsAvatarsServlet; - import com.google.gwt.logging.server.RemoteLoggingServiceImpl; -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.Singleton; -import com.google.inject.name.Named; +import com.google.inject.*; import com.google.inject.name.Names; - +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; import org.apache.commons.configuration.ConfigurationException; +import org.eclipse.jetty.proxy.ProxyServlet; +import org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveClientRpc; import org.waveprotocol.box.server.authentication.AccountStoreHolder; import org.waveprotocol.box.server.authentication.SessionManager; +import org.waveprotocol.box.server.executor.ExecutorsModule; import org.waveprotocol.box.server.frontend.ClientFrontend; import org.waveprotocol.box.server.frontend.ClientFrontendImpl; import org.waveprotocol.box.server.frontend.WaveClientRpcImpl; @@ -54,64 +50,35 @@ import org.waveprotocol.box.server.robots.agent.welcome.WelcomeRobot; import org.waveprotocol.box.server.robots.dataapi.DataApiOAuthServlet; import org.waveprotocol.box.server.robots.dataapi.DataApiServlet; import org.waveprotocol.box.server.robots.passive.RobotsGateway; -import org.waveprotocol.box.server.rpc.AttachmentInfoServlet; -import org.waveprotocol.box.server.rpc.AttachmentServlet; -import org.waveprotocol.box.server.rpc.AuthenticationServlet; -import org.waveprotocol.box.server.rpc.FetchProfilesServlet; -import org.waveprotocol.box.server.rpc.FetchServlet; -import org.waveprotocol.box.server.rpc.GadgetProviderServlet; -import org.waveprotocol.box.server.rpc.LocaleServlet; -import org.waveprotocol.box.server.rpc.NotificationServlet; -import org.waveprotocol.box.server.rpc.SearchServlet; -import org.waveprotocol.box.server.rpc.ServerRpcProvider; -import org.waveprotocol.box.server.rpc.SignOutServlet; -import org.waveprotocol.box.server.rpc.UserRegistrationServlet; -import org.waveprotocol.box.server.rpc.WaveClientServlet; -import org.waveprotocol.box.server.rpc.WaveRefServlet; -import org.waveprotocol.box.server.waveserver.PerUserWaveViewBus; -import org.waveprotocol.box.server.waveserver.PerUserWaveViewDistpatcher; -import org.waveprotocol.box.server.waveserver.WaveBus; -import org.waveprotocol.box.server.waveserver.WaveIndexer; -import org.waveprotocol.box.server.waveserver.WaveServerException; -import org.waveprotocol.box.server.waveserver.WaveletProvider; -import org.waveprotocol.box.server.waveserver.WaveletStateException; +import org.waveprotocol.box.server.rpc.*; +import org.waveprotocol.box.server.stat.RequestScopeFilter; +import org.waveprotocol.box.server.stat.StatuszServlet; +import org.waveprotocol.box.server.stat.TimingFilter; +import org.waveprotocol.box.server.waveserver.*; +import org.waveprotocol.box.stat.StatService; import org.waveprotocol.wave.crypto.CertPathStore; -import org.waveprotocol.wave.federation.FederationSettings; import org.waveprotocol.wave.federation.FederationTransport; import org.waveprotocol.wave.federation.noop.NoOpFederationModule; import org.waveprotocol.wave.federation.xmpp.XmppFederationModule; import org.waveprotocol.wave.model.version.HashedVersionFactory; import org.waveprotocol.wave.model.wave.ParticipantIdUtil; import org.waveprotocol.wave.util.logging.Log; -import org.waveprotocol.wave.util.settings.SettingsBinder; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; - -import org.eclipse.jetty.proxy.ProxyServlet; -import org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveClientRpc; -import org.waveprotocol.box.server.stat.RequestScopeFilter; -import org.waveprotocol.box.server.stat.StatuszServlet; -import org.waveprotocol.box.server.stat.TimingFilter; -import org.waveprotocol.box.stat.StatService; +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; /** * Wave Server entrypoint. */ public class ServerMain { - /** - * This is the name of the system property used to find the server config file. - */ - private static final String PROPERTIES_FILE_KEY = "wave.server.config"; - private static final Log LOG = Log.get(ServerMain.class); @SuppressWarnings("serial") @@ -121,9 +88,9 @@ public class ServerMain { ProxyServlet.Transparent proxyServlet; @Inject - public GadgetProxyServlet(@Named(CoreSettings.GADGET_SERVER_HOSTNAME) String gadgetServerHostname, - @Named(CoreSettings.GADGET_SERVER_PORT) int gadgetServerPort){ - + public GadgetProxyServlet(Config config) { + String gadgetServerHostname = config.getString("core.gadget_server_hostname"); + int gadgetServerPort = config.getInt("core.gadget_server_port"); LOG.info("Starting GadgetProxyServlet for " + gadgetServerHostname + ":" + gadgetServerPort); proxyServlet = new ProxyServlet.Transparent( "http://" + gadgetServerHostname + ":" + gadgetServerPort + "/gadgets", @@ -143,9 +110,20 @@ public class ServerMain { public static void main(String... args) { try { - Module coreSettings = SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, CoreSettings.class); + Module coreSettings = new AbstractModule() { + + @Override + protected void configure() { + Config config = + ConfigFactory.load().withFallback( + ConfigFactory.parseFile(new File("application.conf")).withFallback( + ConfigFactory.parseFile(new File("reference.conf")))); + bind(Config.class).toInstance(config); + bind(Key.get(String.class, Names.named(CoreSettingsNames.WAVE_SERVER_DOMAIN))) + .toInstance(config.getString("core.wave_server_domain")); + } + }; run(coreSettings); - return; } catch (PersistenceException e) { LOG.severe("PersistenceException when running server:", e); } catch (ConfigurationException e) { @@ -162,14 +140,8 @@ public class ServerMain { ExecutorsModule executorsModule = injector.getInstance(ExecutorsModule.class); injector = injector.createChildInjector(profilingModule, executorsModule); - boolean enableFederation = injector.getInstance(Key.get(Boolean.class, - Names.named(CoreSettings.ENABLE_FEDERATION))); - if (enableFederation) { - Module federationSettings = - SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, FederationSettings.class); - // This MUST happen first, or bindings will fail if federation is enabled. - injector = injector.createChildInjector(federationSettings); - } + Config config = injector.getInstance(Config.class); + boolean enableFederation = config.getBoolean("federation.enable_federation"); Module serverModule = injector.getInstance(ServerModule.class); Module federationModule = buildFederationModule(injector, enableFederation); @@ -183,15 +155,14 @@ public class ServerMain { ServerRpcProvider server = injector.getInstance(ServerRpcProvider.class); WaveBus waveBus = injector.getInstance(WaveBus.class); - String domain = - injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WAVE_SERVER_DOMAIN))); + String domain = config.getString("core.wave_server_domain"); if (!ParticipantIdUtil.isDomainAddress(ParticipantIdUtil.makeDomainAddress(domain))) { throw new WaveServerException("Invalid wave domain: " + domain); } initializeServer(injector, domain); - initializeServlets(injector, server); - initializeRobotAgents(injector, server); + initializeServlets(server, config); + initializeRobotAgents(server); initializeRobots(injector, waveBus); initializeFrontend(injector, server, waveBus); initializeFederation(injector); @@ -229,7 +200,7 @@ public class ServerMain { waveServer.initialize(); } - private static void initializeServlets(Injector injector, ServerRpcProvider server) { + private static void initializeServlets(ServerRpcProvider server, Config config) { server.addServlet("/gadget/gadgetlist", GadgetProviderServlet.class); server.addServlet(AttachmentServlet.ATTACHMENT_URL + "/*", AttachmentServlet.class); @@ -255,11 +226,8 @@ public class ServerMain { server.addServlet("/iniavatars/*", InitialsAvatarsServlet.class); server.addServlet("/waveref/*", WaveRefServlet.class); - String gadgetHostName = - injector - .getInstance(Key.get(String.class, Names.named(CoreSettings.GADGET_SERVER_HOSTNAME))); - int port = - injector.getInstance(Key.get(Integer.class, Names.named(CoreSettings.GADGET_SERVER_PORT))); + String gadgetHostName = config.getString("core.gadget_server_hostname"); + int port = config.getInt("core.gadget_server_port"); Map<String, String> initParams = Collections.singletonMap("hostHeader", gadgetHostName + ":" + port); server.addServlet("/gadgets/*", GadgetProxyServlet.class, initParams); @@ -268,8 +236,7 @@ public class ServerMain { // Profiling server.addFilter("/*", RequestScopeFilter.class); - boolean enableProfiling = - injector.getInstance(Key.get(Boolean.class, Names.named(CoreSettings.ENABLE_PROFILING))); + boolean enableProfiling = config.getBoolean("core.enable_profiling"); if (enableProfiling) { server.addFilter("/*", TimingFilter.class); server.addServlet(StatService.STAT_URL, StatuszServlet.class); @@ -281,7 +248,7 @@ public class ServerMain { waveBus.subscribe(robotsGateway); } - private static void initializeRobotAgents(Injector injector, ServerRpcProvider server) { + private static void initializeRobotAgents(ServerRpcProvider server) { server.addServlet(PasswordRobot.ROBOT_URI + "/*", PasswordRobot.class); server.addServlet(PasswordAdminRobot.ROBOT_URI + "/*", PasswordAdminRobot.class); server.addServlet(WelcomeRobot.ROBOT_URI + "/*", WelcomeRobot.class); @@ -307,7 +274,7 @@ public class ServerMain { } private static void initializeSearch(Injector injector, WaveBus waveBus) - throws WaveletStateException, WaveServerException { + throws WaveServerException { PerUserWaveViewDistpatcher waveViewDistpatcher = injector.getInstance(PerUserWaveViewDistpatcher.class); PerUserWaveViewBus.Listener listener = injector.getInstance(PerUserWaveViewBus.Listener.class); http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/ServerModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/ServerModule.java b/src/org/waveprotocol/box/server/ServerModule.java index 0266942..c96ab1c 100644 --- a/src/org/waveprotocol/box/server/ServerModule.java +++ b/src/org/waveprotocol/box/server/ServerModule.java @@ -27,6 +27,7 @@ import com.google.inject.TypeLiteral; import com.google.inject.name.Named; import com.google.inject.name.Names; +import com.typesafe.config.Config; import org.eclipse.jetty.server.session.HashSessionManager; import org.waveprotocol.box.server.authentication.SessionManager; import org.waveprotocol.box.server.authentication.SessionManagerImpl; @@ -96,7 +97,7 @@ public class ServerModule extends AbstractModule { @Provides @Singleton - public IdGenerator provideIdGenerator(@Named(CoreSettings.WAVE_SERVER_DOMAIN) String domain, + public IdGenerator provideIdGenerator(@Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) String domain, Seed seed) { return new IdGeneratorImpl(domain, seed); } @@ -126,10 +127,9 @@ public class ServerModule extends AbstractModule { @Provides @Singleton - public org.eclipse.jetty.server.SessionManager provideSessionManager( - @Named(CoreSettings.SESSION_COOKIE_MAX_AGE) int sessionCookieMaxAge) { + public org.eclipse.jetty.server.SessionManager provideSessionManager(Config config) { HashSessionManager sessionManager = new HashSessionManager(); - sessionManager.getSessionCookieConfig().setMaxAge(sessionCookieMaxAge); + sessionManager.getSessionCookieConfig().setMaxAge(config.getInt("network.session_cookie_max_age")); return sessionManager; } } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/StatModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/StatModule.java b/src/org/waveprotocol/box/server/StatModule.java index 6c5af5e..bcd0e0f 100644 --- a/src/org/waveprotocol/box/server/StatModule.java +++ b/src/org/waveprotocol/box/server/StatModule.java @@ -23,6 +23,7 @@ import com.google.inject.Inject; import static com.google.inject.matcher.Matchers.annotatedWith; import static com.google.inject.matcher.Matchers.any; import com.google.inject.name.Named; +import com.typesafe.config.Config; import org.waveprotocol.box.server.stat.MultiThreadedRequestScope; import org.waveprotocol.box.server.stat.TimingInterceptor; @@ -38,8 +39,8 @@ public class StatModule extends AbstractModule { private final boolean enableProfiling; @Inject - public StatModule(@Named(CoreSettings.ENABLE_PROFILING) boolean enableProfiling) { - this.enableProfiling = enableProfiling; + public StatModule(Config config) { + this.enableProfiling = config.getBoolean("core.enable_profiling"); } @Override http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/executor/ExecutorsModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/executor/ExecutorsModule.java b/src/org/waveprotocol/box/server/executor/ExecutorsModule.java index ca0d365..bfcd345 100644 --- a/src/org/waveprotocol/box/server/executor/ExecutorsModule.java +++ b/src/org/waveprotocol/box/server/executor/ExecutorsModule.java @@ -21,32 +21,11 @@ package org.waveprotocol.box.server.executor; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.name.Named; - -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; - -import org.waveprotocol.box.server.CoreSettings; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.ClientServerExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.ContactExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.DeltaPersistExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.SolrExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.XmppExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.IndexExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.ListenerExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.LookupExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.RobotConnectionExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.RobotGatewayExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.StorageContinuationExecutor; -import org.waveprotocol.box.server.executor.ExecutorAnnotations.WaveletLoadExecutor; +import com.google.inject.*; +import com.typesafe.config.Config; +import org.waveprotocol.box.server.executor.ExecutorAnnotations.*; + +import java.util.concurrent.*; /** * Module with executors. @@ -69,15 +48,18 @@ public class ExecutorsModule extends AbstractModule { @Singleton @ClientServerExecutor protected Executor provideClientServerExecutor(Provider<RequestScopeExecutor> executorProvider) { - return provideThreadPoolExecutor(executorProvider, -1, ClientServerExecutor.class.getSimpleName()); + return provideThreadPoolExecutor(executorProvider, -1, ClientServerExecutor.class + .getSimpleName()); } @Provides @Singleton @DeltaPersistExecutor protected Executor provideDeltaPersistExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.DELTA_PERSIST_EXECUTOR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, DeltaPersistExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.delta_persist_executor_thread_count"), DeltaPersistExecutor.class + .getSimpleName()); } @Provides @@ -91,72 +73,86 @@ public class ExecutorsModule extends AbstractModule { @Singleton @ListenerExecutor protected Executor provideListenerExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.LISTENER_EXECUTOR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, ListenerExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.listener_executor_thread_count"), ListenerExecutor.class.getSimpleName()); } @Provides @Singleton @LookupExecutor protected Executor provideLookupExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.LOOKUP_EXECUTOR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, LookupExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.lookup_executor_thread_count"), LookupExecutor.class.getSimpleName()); } @Provides @Singleton @StorageContinuationExecutor - protected Executor provideStorageContinuationExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.STORAGE_CONTINUATION_EXECUTOR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, StorageContinuationExecutor.class.getSimpleName()); + protected Executor provideStorageContinuationExecutor( + Provider<RequestScopeExecutor> executorProvider, Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.storage_continuation_executor_thread_count"), + StorageContinuationExecutor.class.getSimpleName()); } @Provides @Singleton @WaveletLoadExecutor protected Executor provideWaveletLoadExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.WAVELET_LOAD_EXECUTOR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, WaveletLoadExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.wavelet_load_executor_thread_count"), WaveletLoadExecutor.class + .getSimpleName()); } @Provides @Singleton @ContactExecutor - protected ScheduledExecutorService provideContactExecutor(Provider<ScheduledRequestScopeExecutor> executorProvider) { - return provideScheduledThreadPoolExecutor(executorProvider, 1, ContactExecutor.class.getSimpleName()); + protected ScheduledExecutorService provideContactExecutor( + Provider<ScheduledRequestScopeExecutor> executorProvider, Config config) { + return provideScheduledThreadPoolExecutor(executorProvider, config + .getInt("threads.contact_executor_thread_count"), ContactExecutor.class.getSimpleName()); } @Provides @Singleton @RobotConnectionExecutor - protected ScheduledExecutorService provideRobotConnectionExecutor(Provider<ScheduledRequestScopeExecutor> executorProvider, - @Named(CoreSettings.ROBOT_CONNECTION_THREAD_COUNT) int threadCount) { - return provideScheduledThreadPoolExecutor(executorProvider, threadCount, RobotConnectionExecutor.class.getSimpleName()); + protected ScheduledExecutorService provideRobotConnectionExecutor( + Provider<ScheduledRequestScopeExecutor> executorProvider, Config config) { + return provideScheduledThreadPoolExecutor(executorProvider, config + .getInt("threads.robot_connection_thread_count"), RobotConnectionExecutor.class + .getSimpleName()); } @Provides @Singleton @RobotGatewayExecutor protected Executor provideRobotGatewayExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.ROBOT_GATEWAY_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, RobotGatewayExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config + .getInt("threads.robot_gateway_thread_count"), RobotGatewayExecutor.class.getSimpleName()); } @Provides @Singleton @XmppExecutor - protected ScheduledExecutorService provideXmppExecutor(Provider<ScheduledRequestScopeExecutor> executorProvider) { - return provideScheduledThreadPoolExecutor(executorProvider, 1, XmppExecutor.class.getSimpleName()); + protected ScheduledExecutorService provideXmppExecutor( + Provider<ScheduledRequestScopeExecutor> executorProvider) { + return provideScheduledThreadPoolExecutor(executorProvider, 1, XmppExecutor.class + .getSimpleName()); } - + @Provides @Singleton @SolrExecutor protected Executor provideSolrExecutor(Provider<RequestScopeExecutor> executorProvider, - @Named(CoreSettings.SOLR_THREAD_COUNT) int threadCount) { - return provideThreadPoolExecutor(executorProvider, threadCount, SolrExecutor.class.getSimpleName()); + Config config) { + return provideThreadPoolExecutor(executorProvider, config.getInt("threads.solr_thread_count"), + SolrExecutor.class.getSimpleName()); } - + private Executor provideThreadPoolExecutor(Provider<RequestScopeExecutor> executorProvider, int threadCount, String name) { if (threadCount == 0) { http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/PersistenceModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/PersistenceModule.java b/src/org/waveprotocol/box/server/persistence/PersistenceModule.java index 3016671..2ce3a32 100644 --- a/src/org/waveprotocol/box/server/persistence/PersistenceModule.java +++ b/src/org/waveprotocol/box/server/persistence/PersistenceModule.java @@ -22,9 +22,7 @@ package org.waveprotocol.box.server.persistence; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.name.Named; - -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; import org.waveprotocol.box.server.persistence.file.FileAccountStore; import org.waveprotocol.box.server.persistence.file.FileAttachmentStore; import org.waveprotocol.box.server.persistence.file.FileDeltaStore; @@ -69,20 +67,14 @@ public class PersistenceModule extends AbstractModule { @Inject - public PersistenceModule(@Named(CoreSettings.SIGNER_INFO_STORE_TYPE) String signerInfoStoreType, - @Named(CoreSettings.ATTACHMENT_STORE_TYPE) String attachmentStoreType, - @Named(CoreSettings.ACCOUNT_STORE_TYPE) String accountStoreType, - @Named(CoreSettings.DELTA_STORE_TYPE) String deltaStoreType, - @Named(CoreSettings.MONGODB_HOST) String mongoDBHost, - @Named(CoreSettings.MONGODB_PORT) String mongoDBPort, - @Named(CoreSettings.MONGODB_DATABASE) String mongoDBdatabase) { - this.signerInfoStoreType = signerInfoStoreType; - this.attachmentStoreType = attachmentStoreType; - this.accountStoreType = accountStoreType; - this.deltaStoreType = deltaStoreType; - this.mongoDBHost = mongoDBHost; - this.mongoDBPort = mongoDBPort; - this.mongoDBdatabase = mongoDBdatabase; + public PersistenceModule(Config config) { + this.signerInfoStoreType = config.getString("core.signer_info_store_type"); + this.attachmentStoreType = config.getString("core.attachment_store_type"); + this.accountStoreType = config.getString("core.account_store_type"); + this.deltaStoreType = config.getString("core.delta_store_type"); + this.mongoDBHost = config.getString("core.mongodb_host"); + this.mongoDBPort = config.getString("core.mongodb_port"); + this.mongoDBdatabase = config.getString("core.mongodb_database"); } /** http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/file/FileAccountStore.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/file/FileAccountStore.java b/src/org/waveprotocol/box/server/persistence/file/FileAccountStore.java index d4608dc..1e8b41c 100644 --- a/src/org/waveprotocol/box/server/persistence/file/FileAccountStore.java +++ b/src/org/waveprotocol/box/server/persistence/file/FileAccountStore.java @@ -1,30 +1,28 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.waveprotocol.box.server.persistence.file; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.inject.Inject; -import com.google.inject.name.Named; - -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; import org.waveprotocol.box.server.account.AccountData; import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.persistence.PersistenceException; @@ -33,11 +31,7 @@ import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.Prot import org.waveprotocol.wave.model.wave.ParticipantId; import org.waveprotocol.wave.util.logging.Log; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.util.Map; /** @@ -53,9 +47,8 @@ public class FileAccountStore implements AccountStore { private static final Log LOG = Log.get(FileAccountStore.class); @Inject - public FileAccountStore(@Named(CoreSettings.ACCOUNT_STORE_DIRECTORY) String accountStoreBasePath) { - Preconditions.checkNotNull(accountStoreBasePath, "Requested path is null"); - this.accountStoreBasePath = accountStoreBasePath; + public FileAccountStore(Config config) { + this.accountStoreBasePath = config.getString("core.account_store_directory"); } @Override http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/file/FileAttachmentStore.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/file/FileAttachmentStore.java b/src/org/waveprotocol/box/server/persistence/file/FileAttachmentStore.java index 96b23a3..64097ea 100644 --- a/src/org/waveprotocol/box/server/persistence/file/FileAttachmentStore.java +++ b/src/org/waveprotocol/box/server/persistence/file/FileAttachmentStore.java @@ -20,23 +20,15 @@ package org.waveprotocol.box.server.persistence.file; import com.google.inject.Inject; -import com.google.inject.name.Named; - -import org.waveprotocol.box.server.CoreSettings; -import org.waveprotocol.box.server.persistence.AttachmentStore; -import org.waveprotocol.wave.model.util.CharBase64; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; +import com.typesafe.config.Config; import org.waveprotocol.box.attachment.AttachmentMetadata; import org.waveprotocol.box.attachment.AttachmentProto; import org.waveprotocol.box.attachment.proto.AttachmentMetadataProtoImpl; +import org.waveprotocol.box.server.persistence.AttachmentStore; import org.waveprotocol.wave.media.model.AttachmentId; +import org.waveprotocol.wave.model.util.CharBase64; + +import java.io.*; /** * An implementation of AttachmentStore which uses files on disk @@ -46,8 +38,8 @@ import org.waveprotocol.wave.media.model.AttachmentId; */ public class FileAttachmentStore implements AttachmentStore { - private final String META_EXT = ".meta"; - private final String THUMBNAIL_EXT = ".thumbnail"; + private final static String META_EXT = ".meta"; + private final static String THUMBNAIL_EXT = ".thumbnail"; /** * The directory in which the attachments are stored. @@ -55,8 +47,8 @@ public class FileAttachmentStore implements AttachmentStore { private final String basePath; @Inject - public FileAttachmentStore(@Named(CoreSettings.ATTACHMENT_STORE_DIRECTORY) String basePath) { - this.basePath = basePath; + public FileAttachmentStore(Config config) { + this.basePath = config.getString("core.attachment_store_directory"); new File(basePath).mkdirs(); } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/file/FileDeltaStore.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/file/FileDeltaStore.java b/src/org/waveprotocol/box/server/persistence/file/FileDeltaStore.java index a615693..2677391 100644 --- a/src/org/waveprotocol/box/server/persistence/file/FileDeltaStore.java +++ b/src/org/waveprotocol/box/server/persistence/file/FileDeltaStore.java @@ -19,15 +19,13 @@ package org.waveprotocol.box.server.persistence.file; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; -import com.google.inject.name.Named; - +import com.typesafe.config.Config; import org.waveprotocol.box.common.ExceptionalIterator; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.waveserver.DeltaStore; +import org.waveprotocol.box.stat.Timed; import org.waveprotocol.wave.model.id.WaveId; import org.waveprotocol.wave.model.id.WaveletId; import org.waveprotocol.wave.model.id.WaveletName; @@ -39,7 +37,6 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; -import org.waveprotocol.box.stat.Timed; /** * A flat file based implementation of DeltaStore. @@ -62,9 +59,8 @@ public class FileDeltaStore implements DeltaStore { final private String basePath; @Inject - public FileDeltaStore(@Named(CoreSettings.DELTA_STORE_DIRECTORY) String basePath) { - Preconditions.checkNotNull(basePath, "Requested path is null"); - this.basePath = basePath; + public FileDeltaStore(Config config) { + this.basePath = config.getString("core.delta_store_directory"); } @Timed http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/file/FileSignerInfoStore.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/file/FileSignerInfoStore.java b/src/org/waveprotocol/box/server/persistence/file/FileSignerInfoStore.java index e8686f4..8dd53ac 100644 --- a/src/org/waveprotocol/box/server/persistence/file/FileSignerInfoStore.java +++ b/src/org/waveprotocol/box/server/persistence/file/FileSignerInfoStore.java @@ -1,30 +1,27 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.waveprotocol.box.server.persistence.file; -import com.google.common.base.Preconditions; import com.google.inject.Inject; -import com.google.inject.name.Named; - +import com.typesafe.config.Config; import org.apache.commons.codec.binary.Hex; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.persistence.SignerInfoStore; import org.waveprotocol.wave.crypto.CertPathStore; @@ -52,9 +49,8 @@ public class FileSignerInfoStore implements SignerInfoStore { private static final Log LOG = Log.get(FileSignerInfoStore.class); @Inject - public FileSignerInfoStore(@Named(CoreSettings.SIGNER_INFO_STORE_DIRECTORY) String signerInfoStoreBasePath) { - Preconditions.checkNotNull(signerInfoStoreBasePath, "Requested path is null"); - this.signerInfoStoreBasePath = signerInfoStoreBasePath; + public FileSignerInfoStore(Config config) { + this.signerInfoStoreBasePath = config.getString("core.signer_info_store_directory"); } private String signerIdToFileName(byte[] id) { @@ -80,10 +76,7 @@ public class FileSignerInfoStore implements SignerInfoStore { file = new FileInputStream(signerFile); ProtocolSignerInfo data = ProtocolSignerInfo.newBuilder().mergeFrom(file).build(); signerInfo = new SignerInfo(data); - } catch (SignatureException e) { - throw new SignatureException("Failed to parse signer info from file: " - + signerFile.getAbsolutePath(), e); - } catch (IOException e) { + } catch (SignatureException | IOException e) { throw new SignatureException("Failed to parse signer info from file: " + signerFile.getAbsolutePath(), e); } finally { http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/persistence/lucene/FSIndexDirectory.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/persistence/lucene/FSIndexDirectory.java b/src/org/waveprotocol/box/server/persistence/lucene/FSIndexDirectory.java index 4badd7c..eaaab39 100644 --- a/src/org/waveprotocol/box/server/persistence/lucene/FSIndexDirectory.java +++ b/src/org/waveprotocol/box/server/persistence/lucene/FSIndexDirectory.java @@ -19,11 +19,9 @@ package org.waveprotocol.box.server.persistence.lucene; import com.google.inject.Inject; -import com.google.inject.name.Named; - +import com.typesafe.config.Config; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.persistence.file.FileUtils; import org.waveprotocol.box.server.waveserver.IndexException; @@ -41,7 +39,8 @@ public class FSIndexDirectory implements IndexDirectory { private Directory directory; @Inject - public FSIndexDirectory(@Named(CoreSettings.INDEX_DIRECTORY) String directoryName) { + public FSIndexDirectory(Config config) { + String directoryName = config.getString("core.index_directory"); if (directory == null) { File file; try { http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/ProfileFetcherModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/ProfileFetcherModule.java b/src/org/waveprotocol/box/server/robots/ProfileFetcherModule.java index be8f7ea..7374bfc 100644 --- a/src/org/waveprotocol/box/server/robots/ProfileFetcherModule.java +++ b/src/org/waveprotocol/box/server/robots/ProfileFetcherModule.java @@ -22,9 +22,7 @@ package org.waveprotocol.box.server.robots; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.name.Named; - -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; import org.waveprotocol.box.server.robots.operations.FetchProfilesService.ProfilesFetcher; import org.waveprotocol.box.server.robots.operations.GravatarProfilesFetcher; import org.waveprotocol.box.server.robots.operations.InitialsProfilesFetcher; @@ -40,8 +38,8 @@ public class ProfileFetcherModule extends AbstractModule { private String profileFetcherType; @Inject - public ProfileFetcherModule(@Named(CoreSettings.PROFILE_FETCHER_TYPE) String profilerType) { - this.profileFetcherType = profilerType; + public ProfileFetcherModule(Config config) { + this.profileFetcherType = config.getString("core.profile_fetcher_type"); } @Override http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/RobotApiModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/RobotApiModule.java b/src/org/waveprotocol/box/server/robots/RobotApiModule.java index 6bcaadb..e757080 100644 --- a/src/org/waveprotocol/box/server/robots/RobotApiModule.java +++ b/src/org/waveprotocol/box/server/robots/RobotApiModule.java @@ -32,13 +32,13 @@ import com.google.wave.api.data.converter.EventDataConverterModule; import com.google.wave.api.robot.HttpRobotConnection; import com.google.wave.api.robot.RobotConnection; +import com.typesafe.config.Config; import net.oauth.OAuthServiceProvider; import net.oauth.OAuthValidator; import net.oauth.SimpleOAuthValidator; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.robots.active.ActiveApiOperationServiceRegistry; import org.waveprotocol.box.server.robots.dataapi.DataApiOAuthServlet; import org.waveprotocol.box.server.robots.dataapi.DataApiOperationServiceRegistry; @@ -131,8 +131,8 @@ public class RobotApiModule extends AbstractModule { @Provides @Singleton - protected OAuthServiceProvider provideOAuthServiceProvider( - @Named(CoreSettings.HTTP_FRONTEND_PUBLIC_ADDRESS) String publicAddress) { + protected OAuthServiceProvider provideOAuthServiceProvider(Config config) { + String publicAddress = config.getString("core.http_frontend_public_address"); // Three urls, first is to get an unauthorized request token, second is to // authorize the request token, third is to exchange the authorized request // token with an access token. http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/RobotRegistrationServlet.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/RobotRegistrationServlet.java b/src/org/waveprotocol/box/server/robots/RobotRegistrationServlet.java index b99d274..32f7bc9 100644 --- a/src/org/waveprotocol/box/server/robots/RobotRegistrationServlet.java +++ b/src/org/waveprotocol/box/server/robots/RobotRegistrationServlet.java @@ -25,7 +25,8 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.inject.name.Named; -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; +import org.waveprotocol.box.server.CoreSettingsNames; import org.waveprotocol.box.server.account.RobotAccountData; import org.waveprotocol.box.server.gxp.RobotRegistrationPage; import org.waveprotocol.box.server.gxp.RobotRegistrationSuccessPage; @@ -60,12 +61,12 @@ public class RobotRegistrationServlet extends HttpServlet { private final String analyticsAccount; @Inject - private RobotRegistrationServlet(@Named(CoreSettings.WAVE_SERVER_DOMAIN) String domain, + private RobotRegistrationServlet(@Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) String domain, RobotRegistrar robotRegistrar, - @Named(CoreSettings.ANALYTICS_ACCOUNT) String analyticsAccount) { + Config config) { this.robotRegistrar = robotRegistrar; this.domain = domain; - this.analyticsAccount = analyticsAccount; + this.analyticsAccount = config.getString("administration.analytics_account"); } @Override @@ -121,7 +122,7 @@ public class RobotRegistrationServlet extends HttpServlet { return; } - RobotAccountData robotAccount = null; + RobotAccountData robotAccount; try{ robotAccount = robotRegistrar.registerNew(id, location); } catch (RobotRegistrationException e) { http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/agent/AbstractBaseRobotAgent.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/agent/AbstractBaseRobotAgent.java b/src/org/waveprotocol/box/server/robots/agent/AbstractBaseRobotAgent.java index a549cc0..2e72c00 100755 --- a/src/org/waveprotocol/box/server/robots/agent/AbstractBaseRobotAgent.java +++ b/src/org/waveprotocol/box/server/robots/agent/AbstractBaseRobotAgent.java @@ -21,17 +21,12 @@ package org.waveprotocol.box.server.robots.agent; import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.name.Named; -import com.google.inject.name.Names; import com.google.wave.api.AbstractRobot; - -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.robots.register.RobotRegistrar; import org.waveprotocol.box.server.robots.util.RobotsUtil.RobotRegistrationException; -import org.waveprotocol.wave.model.id.TokenGenerator; import org.waveprotocol.wave.model.wave.InvalidParticipantAddress; import org.waveprotocol.wave.model.wave.ParticipantId; @@ -52,9 +47,8 @@ public abstract class AbstractBaseRobotAgent extends AbstractRobot { private final List<String> addresses; @Inject - ServerFrontendAddressHolder( - @Named(CoreSettings.HTTP_FRONTEND_ADDRESSES) List<String> addresses) { - this.addresses = addresses; + ServerFrontendAddressHolder(Config config) { + this.addresses = config.getStringList("core.http_frontend_addresses"); } public List<String> getAddresses() { @@ -87,11 +81,13 @@ public abstract class AbstractBaseRobotAgent extends AbstractRobot { * @param injector the injector instance. */ public AbstractBaseRobotAgent(Injector injector) { - this(injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WAVE_SERVER_DOMAIN))), - injector.getInstance(TokenGenerator.class), injector - .getInstance(ServerFrontendAddressHolder.class), injector - .getInstance(AccountStore.class), injector.getInstance(RobotRegistrar.class), - injector.getInstance(Key.get(Boolean.class, Names.named(CoreSettings.ENABLE_SSL)))); + Config config = injector.getInstance(Config.class); + this.waveDomain = config.getString("core.wave_server_domain"); + this.frontendAddressHolder = injector.getInstance(ServerFrontendAddressHolder.class); + this.robotRegistrar = injector.getInstance(RobotRegistrar.class); + this.accountStore = injector.getInstance(AccountStore.class); + this.isSSLEnabled = config.getBoolean("security.enable_ssl"); + ensureRegistered(getFrontEndAddress()); } /** @@ -99,22 +95,22 @@ public abstract class AbstractBaseRobotAgent extends AbstractRobot { * {@link #getRobotUri()} and ensures that the agent is registered in the * Account store. */ - AbstractBaseRobotAgent(String waveDomain, TokenGenerator tokenGenerator, - ServerFrontendAddressHolder frontendAddressHolder, AccountStore accountStore, - RobotRegistrar robotRegistator, Boolean sslEnabled) { + AbstractBaseRobotAgent(String waveDomain, + ServerFrontendAddressHolder frontendAddressHolder, AccountStore accountStore, + RobotRegistrar robotRegistator, Boolean sslEnabled) { this.waveDomain = waveDomain; this.frontendAddressHolder = frontendAddressHolder; this.robotRegistrar = robotRegistator; this.accountStore = accountStore; this.isSSLEnabled = sslEnabled; - ensureRegistered(tokenGenerator, getFrontEndAddress()); + ensureRegistered(getFrontEndAddress()); } /** * Ensures that the robot agent is registered in the {@link AccountStore}. */ - private void ensureRegistered(TokenGenerator tokenGenerator, String serverFrontendAddress) { - ParticipantId robotId = null; + private void ensureRegistered(String serverFrontendAddress) { + ParticipantId robotId; try { robotId = ParticipantId.of(getRobotId() + "@" + waveDomain); } catch (InvalidParticipantAddress e) { @@ -126,9 +122,7 @@ public abstract class AbstractBaseRobotAgent extends AbstractRobot { // In order to re-register the agents if the server frontend address has changed. robotRegistrar.registerOrUpdate(robotId, location); - } catch (RobotRegistrationException e) { - LOG.log(Level.SEVERE, "Failed to register the agent:" + getRobotId(), e); - } catch (PersistenceException e) { + } catch (RobotRegistrationException | PersistenceException e) { LOG.log(Level.SEVERE, "Failed to register the agent:" + getRobotId(), e); } } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/agent/AbstractCliRobotAgent.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/agent/AbstractCliRobotAgent.java b/src/org/waveprotocol/box/server/robots/agent/AbstractCliRobotAgent.java index dd878bc..f784595 100755 --- a/src/org/waveprotocol/box/server/robots/agent/AbstractCliRobotAgent.java +++ b/src/org/waveprotocol/box/server/robots/agent/AbstractCliRobotAgent.java @@ -29,6 +29,7 @@ import com.google.wave.api.Blip; import com.google.wave.api.event.DocumentChangedEvent; import com.google.wave.api.event.WaveletSelfAddedEvent; +import com.typesafe.config.Config; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.HelpFormatter; @@ -37,11 +38,10 @@ import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; -import org.waveprotocol.box.server.CoreSettings; +import org.waveprotocol.box.server.CoreSettingsNames; import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.robots.register.RobotRegistrar; import org.waveprotocol.box.server.robots.register.RobotRegistrarImpl; -import org.waveprotocol.wave.model.id.TokenGenerator; import java.io.PrintWriter; import java.io.StringWriter; @@ -68,11 +68,12 @@ public abstract class AbstractCliRobotAgent extends AbstractBaseRobotAgent { * @param injector the injector instance. */ public AbstractCliRobotAgent(Injector injector) { - this(injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WAVE_SERVER_DOMAIN))), - injector.getInstance(TokenGenerator.class), injector + this(injector.getInstance(Key.get(String.class, Names.named(CoreSettingsNames.WAVE_SERVER_DOMAIN))), + + injector .getInstance(ServerFrontendAddressHolder.class), injector .getInstance(AccountStore.class), injector.getInstance(RobotRegistrarImpl.class), - injector.getInstance(Key.get(Boolean.class, Names.named(CoreSettings.ENABLE_SSL)))); + injector.getInstance(Config.class).getBoolean("security.enable_ssl")); } /** @@ -80,10 +81,10 @@ public abstract class AbstractCliRobotAgent extends AbstractBaseRobotAgent { * {@link #getRobotUri()} and ensures that the agent is registered in the * Account store. */ - AbstractCliRobotAgent(String waveDomain, TokenGenerator tokenGenerator, - ServerFrontendAddressHolder frontendAddressHolder, AccountStore accountStore, - RobotRegistrar robotRegistrar, Boolean sslEnabled) { - super(waveDomain, tokenGenerator, frontendAddressHolder, accountStore, robotRegistrar, sslEnabled); + AbstractCliRobotAgent(String waveDomain, + ServerFrontendAddressHolder frontendAddressHolder, AccountStore accountStore, + RobotRegistrar robotRegistrar, Boolean sslEnabled) { + super(waveDomain, frontendAddressHolder, accountStore, robotRegistrar, sslEnabled); parser = new PosixParser(); helpFormatter = new HelpFormatter(); options = initOptions(); @@ -151,7 +152,7 @@ public abstract class AbstractCliRobotAgent extends AbstractBaseRobotAgent { // have to display usage anyway. if ((argsNum > 0) && (argsNum < getMinNumOfArguments() || argsNum > getMaxNumOfArguments())) { - String message = null; + String message; if (getMinNumOfArguments() == getMaxNumOfArguments()) { message = String.format("Invalid number of arguments. Expected: %d , actual: %d %s", @@ -187,8 +188,7 @@ public abstract class AbstractCliRobotAgent extends AbstractBaseRobotAgent { + getCmdLineSyntax() + " \n", null, options, helpFormatter.defaultLeftPad, helpFormatter.defaultDescPad, "", false); pw.flush(); - String usageStr = stringWriter.toString(); - return usageStr; + return stringWriter.toString(); } /** http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/agent/passwd/PasswordAdminRobot.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/agent/passwd/PasswordAdminRobot.java b/src/org/waveprotocol/box/server/robots/agent/passwd/PasswordAdminRobot.java index 49dbbf2..9dc0720 100644 --- a/src/org/waveprotocol/box/server/robots/agent/passwd/PasswordAdminRobot.java +++ b/src/org/waveprotocol/box/server/robots/agent/passwd/PasswordAdminRobot.java @@ -1,35 +1,29 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.waveprotocol.box.server.robots.agent.passwd; -import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.CANNOT_CHANGE_PASSWORD_FOR_USER; -import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.changeUserPassword; - import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Singleton; -import com.google.inject.name.Names; - +import com.typesafe.config.Config; import org.apache.commons.cli.CommandLine; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.robots.agent.AbstractCliRobotAgent; @@ -39,6 +33,9 @@ import org.waveprotocol.wave.model.wave.ParticipantId; import java.util.logging.Level; import java.util.logging.Logger; +import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.CANNOT_CHANGE_PASSWORD_FOR_USER; +import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.changeUserPassword; + /** * Robot agent that handles the password reset for users by admin. * @@ -61,18 +58,17 @@ public final class PasswordAdminRobot extends AbstractCliRobotAgent { public PasswordAdminRobot(Injector injector) { super(injector); serverAdminId = - injector.getInstance(Key.get(String.class, Names.named(CoreSettings.ADMIN_USER))); + injector.getInstance(Config.class).getString("administration.admin_user"); accountStore = injector.getInstance(AccountStore.class); } @Override protected String maybeExecuteCommand(CommandLine commandLine, String modifiedBy) { - String robotMessage = null; - String adminId = modifiedBy; + String robotMessage; // Verify that the user that attempts to change the password has admin privileges. - if (!adminId.equals(serverAdminId)) { + if (!modifiedBy.equals(serverAdminId)) { robotMessage = - "User " + adminId + " is not authorized to use " + getCommandName() + " command."; + "User " + modifiedBy + " is not authorized to use " + getCommandName() + " command."; } else { String userId = null; try { @@ -86,14 +82,11 @@ public final class PasswordAdminRobot extends AbstractCliRobotAgent { robotMessage = String.format("Changed password for user %s, the new password is: %s\n", userId, newPassword); - LOG.log(Level.INFO, "Password changed for user " + userId + " by " + adminId); + LOG.log(Level.INFO, "Password changed for user " + userId + " by " + modifiedBy); } catch (IllegalArgumentException e) { LOG.log(Level.SEVERE, userId, e); robotMessage = e.getMessage(); - } catch (PersistenceException e) { - robotMessage = CANNOT_CHANGE_PASSWORD_FOR_USER + userId; - LOG.log(Level.SEVERE, "userId: " + userId, e); - } catch (InvalidParticipantAddress e) { + } catch (PersistenceException | InvalidParticipantAddress e) { robotMessage = CANNOT_CHANGE_PASSWORD_FOR_USER + userId; LOG.log(Level.SEVERE, "userId: " + userId, e); } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/agent/registration/RegistrationRobot.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/agent/registration/RegistrationRobot.java b/src/org/waveprotocol/box/server/robots/agent/registration/RegistrationRobot.java index 11fad95..cbf3332 100644 --- a/src/org/waveprotocol/box/server/robots/agent/registration/RegistrationRobot.java +++ b/src/org/waveprotocol/box/server/robots/agent/registration/RegistrationRobot.java @@ -19,17 +19,11 @@ package org.waveprotocol.box.server.robots.agent.registration; -import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.CANNOT_CREATE_USER; -import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.createUser; - import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Singleton; -import com.google.inject.name.Names; - +import com.typesafe.config.Config; import org.apache.commons.cli.CommandLine; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.robots.agent.AbstractCliRobotAgent; @@ -39,6 +33,9 @@ import org.waveprotocol.wave.model.wave.ParticipantId; import java.util.logging.Level; import java.util.logging.Logger; +import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.CANNOT_CREATE_USER; +import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.createUser; + /** * Robot agent that handles the user registration by an admin * @@ -61,18 +58,17 @@ public final class RegistrationRobot extends AbstractCliRobotAgent { public RegistrationRobot(Injector injector) { super(injector); serverAdminId = - injector.getInstance(Key.get(String.class, Names.named(CoreSettings.ADMIN_USER))); + injector.getInstance(Config.class).getString("administration.admin_user"); accountStore = injector.getInstance(AccountStore.class); } @Override protected String maybeExecuteCommand(CommandLine commandLine, String modifiedBy) { - String robotMessage = null; - String adminId = modifiedBy; + String robotMessage; // Verify that the user that attempts to create a user has admin privileges. - if (!adminId.equals(serverAdminId)) { + if (!modifiedBy.equals(serverAdminId)) { robotMessage = - "User " + adminId + " is not authorized to use " + getCommandName() + " command."; + "User " + modifiedBy + " is not authorized to use " + getCommandName() + " command."; } else { String userId = null; try { @@ -84,14 +80,11 @@ public final class RegistrationRobot extends AbstractCliRobotAgent { ParticipantId participantId = ParticipantId.of(userId); createUser(accountStore, participantId, password); robotMessage = String.format("Created user %s, the password is: %s\n", userId, password); - LOG.log(Level.INFO, "Created user " + userId + " by " + adminId); + LOG.log(Level.INFO, "Created user " + userId + " by " + modifiedBy); } catch (IllegalArgumentException e) { LOG.log(Level.SEVERE, userId, e); robotMessage = e.getMessage(); - } catch (PersistenceException e) { - robotMessage = CANNOT_CREATE_USER + userId; - LOG.log(Level.SEVERE, "userId: " + userId, e); - } catch (InvalidParticipantAddress e) { + } catch (PersistenceException | InvalidParticipantAddress e) { robotMessage = CANNOT_CREATE_USER + userId; LOG.log(Level.SEVERE, "userId: " + userId, e); } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/agent/welcome/WelcomeRobot.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/agent/welcome/WelcomeRobot.java b/src/org/waveprotocol/box/server/robots/agent/welcome/WelcomeRobot.java index ba041cd..fddab5a 100755 --- a/src/org/waveprotocol/box/server/robots/agent/welcome/WelcomeRobot.java +++ b/src/org/waveprotocol/box/server/robots/agent/welcome/WelcomeRobot.java @@ -19,22 +19,16 @@ package org.waveprotocol.box.server.robots.agent.welcome; -import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.appendLine; - import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Singleton; -import com.google.inject.name.Names; import com.google.wave.api.Wavelet; - -import org.waveprotocol.box.server.CoreSettings; +import com.typesafe.config.Config; import org.waveprotocol.box.server.account.RobotAccountData; import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.robots.agent.AbstractBaseRobotAgent; -import org.waveprotocol.box.server.robots.agent.passwd.PasswordRobot; import org.waveprotocol.box.server.robots.util.RobotsUtil; import org.waveprotocol.wave.model.id.InvalidIdException; import org.waveprotocol.wave.model.id.WaveId; @@ -45,6 +39,8 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import static org.waveprotocol.box.server.robots.agent.RobotAgentUtil.appendLine; + /** * The robot that adds a "Welcome" wave to the inbox of new users. @@ -66,7 +62,7 @@ public class WelcomeRobot extends AbstractBaseRobotAgent { public WelcomeRobot(Injector injector) { super(injector); String welcomeWaveIdStr = - injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WELCOME_WAVE_ID))); + injector.getInstance(Config.class).getString("administration.welcome_wave_id"); if (!"".equals(welcomeWaveIdStr)) { try { welcomeWaveId = WaveId.ofChecked(getWaveDomain(), welcomeWaveIdStr); http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/operations/GravatarProfilesFetcher.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/operations/GravatarProfilesFetcher.java b/src/org/waveprotocol/box/server/robots/operations/GravatarProfilesFetcher.java index 75501a7..c698e2d 100644 --- a/src/org/waveprotocol/box/server/robots/operations/GravatarProfilesFetcher.java +++ b/src/org/waveprotocol/box/server/robots/operations/GravatarProfilesFetcher.java @@ -20,11 +20,9 @@ package org.waveprotocol.box.server.robots.operations; import com.google.inject.Inject; -import com.google.inject.name.Named; import com.google.wave.api.ParticipantProfile; - +import com.typesafe.config.Config; import org.apache.commons.codec.digest.DigestUtils; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.robots.operations.FetchProfilesService.ProfilesFetcher; /** @@ -38,14 +36,14 @@ import org.waveprotocol.box.server.robots.operations.FetchProfilesService.Profil */ public class GravatarProfilesFetcher implements ProfilesFetcher { - private final String SECURE_GRAVATAR_URL = "https://secure.gravatar.com/avatar/"; - private final String NON_SECURE_GRAVATAR_URL = "http://gravatar.com/avatar/"; + private final static String SECURE_GRAVATAR_URL = "https://secure.gravatar.com/avatar/"; + private final static String NON_SECURE_GRAVATAR_URL = "http://gravatar.com/avatar/"; private final String gravatarUrl; @Inject - public GravatarProfilesFetcher(@Named(CoreSettings.ENABLE_SSL) boolean enableSsl) { - if (enableSsl) { + public GravatarProfilesFetcher(Config config) { + if (config.getBoolean("security.enable_ssl")) { gravatarUrl = SECURE_GRAVATAR_URL; } else { gravatarUrl = NON_SECURE_GRAVATAR_URL; @@ -64,10 +62,8 @@ public class GravatarProfilesFetcher implements ProfilesFetcher { @Override public ParticipantProfile fetchProfile(String email) { - ParticipantProfile pTemp = null; + ParticipantProfile pTemp; pTemp = ProfilesFetcher.SIMPLE_PROFILES_FETCHER.fetchProfile(email); - ParticipantProfile profile = - new ParticipantProfile(email, pTemp.getName(), getImageUrl(email), pTemp.getProfileUrl()); - return profile; + return new ParticipantProfile(email, pTemp.getName(), getImageUrl(email), pTemp.getProfileUrl()); } } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/robots/operations/ImportDeltasService.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/robots/operations/ImportDeltasService.java b/src/org/waveprotocol/box/server/robots/operations/ImportDeltasService.java index c313f12..e9024c1 100644 --- a/src/org/waveprotocol/box/server/robots/operations/ImportDeltasService.java +++ b/src/org/waveprotocol/box/server/robots/operations/ImportDeltasService.java @@ -28,8 +28,8 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.google.wave.api.ApiIdSerializer; import com.google.wave.api.JsonRpcConstant.ParamsProperty; +import org.waveprotocol.box.server.CoreSettingsNames; import org.waveprotocol.box.server.robots.OperationContext; -import org.waveprotocol.box.server.CoreSettings; import org.waveprotocol.box.server.frontend.CommittedWaveletSnapshot; import org.waveprotocol.box.server.waveserver.WaveServerException; import org.waveprotocol.box.server.waveserver.WaveletProvider; @@ -61,7 +61,7 @@ public class ImportDeltasService implements OperationService { @Inject public ImportDeltasService(WaveletProvider waveletProvider, - @Named(CoreSettings.WAVE_SERVER_DOMAIN) final String waveDomain) { + @Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) final String waveDomain) { this.waveletProvider = waveletProvider; this.waveDomain = waveDomain; } http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/rpc/AttachmentServlet.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/rpc/AttachmentServlet.java b/src/org/waveprotocol/box/server/rpc/AttachmentServlet.java index ce30ac0..e0d99bf 100644 --- a/src/org/waveprotocol/box/server/rpc/AttachmentServlet.java +++ b/src/org/waveprotocol/box/server/rpc/AttachmentServlet.java @@ -21,41 +21,34 @@ package org.waveprotocol.box.server.rpc; import com.google.inject.Inject; import com.google.inject.Singleton; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.logging.Level; +import com.typesafe.config.Config; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; +import org.waveprotocol.box.attachment.AttachmentMetadata; +import org.waveprotocol.box.server.attachment.AttachmentService; import org.waveprotocol.box.server.authentication.SessionManager; +import org.waveprotocol.box.server.persistence.AttachmentStore.AttachmentData; +import org.waveprotocol.box.server.persistence.AttachmentUtil; +import org.waveprotocol.box.server.waveserver.WaveServerException; import org.waveprotocol.box.server.waveserver.WaveletProvider; +import org.waveprotocol.wave.media.model.AttachmentId; import org.waveprotocol.wave.model.id.InvalidIdException; import org.waveprotocol.wave.model.id.WaveletName; import org.waveprotocol.wave.model.wave.ParticipantId; import org.waveprotocol.wave.util.logging.Log; -import com.google.inject.name.Named; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Calendar; -import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.waveprotocol.box.attachment.AttachmentMetadata; -import org.waveprotocol.box.server.CoreSettings; -import org.waveprotocol.box.server.attachment.AttachmentService; -import org.waveprotocol.box.server.persistence.AttachmentStore.AttachmentData; -import org.waveprotocol.box.server.persistence.AttachmentUtil; -import org.waveprotocol.box.server.waveserver.WaveServerException; -import org.waveprotocol.wave.media.model.AttachmentId; +import java.io.*; +import java.net.URLDecoder; +import java.util.Calendar; +import java.util.List; +import java.util.logging.Level; /** * Serves attachments from a provided store. @@ -82,12 +75,11 @@ public class AttachmentServlet extends HttpServlet { @Inject private AttachmentServlet(AttachmentService service, WaveletProvider waveletProvider, - SessionManager sessionManager, - @Named(CoreSettings.THUMBNAIL_PATTERNS_DIRECTORY) String thumbnailPatternsDirectory) { + SessionManager sessionManager, Config config) { this.service = service; this.waveletProvider = waveletProvider; this.sessionManager = sessionManager; - this.thumbnailPattternsDirectory = thumbnailPatternsDirectory; + this.thumbnailPattternsDirectory = config.getString("core.thumbnail_patterns_directory"); } @Override @@ -222,10 +214,9 @@ public class AttachmentServlet extends HttpServlet { return; } - String fileName = fileItem.getName(); // Get only the file name not whole path. - if (fileName != null) { - fileName = FilenameUtils.getName(fileName); + if (fileItem != null && fileItem.getName() != null) { + String fileName = FilenameUtils.getName(fileItem.getName()); service.storeAttachment(id, fileItem.getInputStream(), waveletName, fileName, user); response.setStatus(HttpServletResponse.SC_CREATED); String msg = http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/80369760/src/org/waveprotocol/box/server/rpc/AuthenticationServlet.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/rpc/AuthenticationServlet.java b/src/org/waveprotocol/box/server/rpc/AuthenticationServlet.java index 49d5964..b282576 100644 --- a/src/org/waveprotocol/box/server/rpc/AuthenticationServlet.java +++ b/src/org/waveprotocol/box/server/rpc/AuthenticationServlet.java @@ -24,17 +24,15 @@ import com.google.common.base.Strings; import com.google.gxp.base.GxpContext; import com.google.inject.Inject; import com.google.inject.name.Named; - +import com.typesafe.config.Config; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.UrlEncoded; -import org.waveprotocol.box.server.CoreSettings; -import org.waveprotocol.box.server.account.HumanAccountDataImpl; +import org.waveprotocol.box.server.CoreSettingsNames; import org.waveprotocol.box.server.authentication.HttpRequestBasedCallbackHandler; import org.waveprotocol.box.server.authentication.ParticipantPrincipal; import org.waveprotocol.box.server.authentication.SessionManager; -import org.waveprotocol.box.server.persistence.AccountStore; -import org.waveprotocol.box.server.persistence.PersistenceException; import org.waveprotocol.box.server.gxp.AuthenticationPage; +import org.waveprotocol.box.server.persistence.AccountStore; import org.waveprotocol.box.server.robots.agent.welcome.WelcomeRobot; import org.waveprotocol.box.server.util.RegistrationUtil; import org.waveprotocol.wave.model.id.WaveIdentifiers; @@ -42,25 +40,10 @@ import org.waveprotocol.wave.model.wave.InvalidParticipantAddress; import org.waveprotocol.wave.model.wave.ParticipantId; import org.waveprotocol.wave.util.logging.Log; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CodingErrorAction; -import java.security.cert.X509Certificate; -import java.security.Principal; - import javax.inject.Singleton; import javax.naming.InvalidNameException; -import javax.naming.ldap.Rdn; import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.Configuration; @@ -71,6 +54,20 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import java.security.Principal; +import java.security.cert.X509Certificate; /** * A servlet for authenticating a user's password and giving them a token via a @@ -105,27 +102,25 @@ private final WelcomeRobot welcomeBot; @Inject public AuthenticationServlet(AccountStore accountStore, - Configuration configuration, SessionManager sessionManager, - @Named(CoreSettings.WAVE_SERVER_DOMAIN) String domain, - @Named(CoreSettings.ENABLE_CLIENTAUTH) boolean isClientAuthEnabled, - @Named(CoreSettings.CLIENTAUTH_CERT_DOMAIN) String clientAuthCertDomain, - @Named(CoreSettings.DISABLE_REGISTRATION) boolean isRegistrationDisabled, - @Named(CoreSettings.DISABLE_LOGINPAGE) boolean isLoginPageDisabled, - WelcomeRobot welcomeBot, - @Named(CoreSettings.ANALYTICS_ACCOUNT) String analyticsAccount) { + Configuration configuration, + SessionManager sessionManager, + @Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) String domain, + Config config, + WelcomeRobot welcomeBot) { Preconditions.checkNotNull(accountStore, "AccountStore is null"); Preconditions.checkNotNull(configuration, "Configuration is null"); Preconditions.checkNotNull(sessionManager, "Session manager is null"); + this.accountStore = accountStore; this.configuration = configuration; this.sessionManager = sessionManager; this.domain = domain.toLowerCase(); - this.isClientAuthEnabled = isClientAuthEnabled; - this.clientAuthCertDomain = clientAuthCertDomain.toLowerCase(); - this.isRegistrationDisabled = isRegistrationDisabled; - this.isLoginPageDisabled = isLoginPageDisabled; + this.isClientAuthEnabled = config.getBoolean("security.enable_clientauth"); + this.clientAuthCertDomain = config.getString("security.clientauth_cert_domain").toLowerCase(); + this.isRegistrationDisabled = config.getBoolean("administration.disable_registration"); + this.isLoginPageDisabled = config.getBoolean("administration.disable_loginpage"); this.welcomeBot = welcomeBot; - this.analyticsAccount = analyticsAccount; + this.analyticsAccount = config.getString("administration.analytics_account"); } @SuppressWarnings("unchecked")
