Author: norman
Date: Mon Nov 2 13:38:23 2009
New Revision: 831895
URL: http://svn.apache.org/viewvc?rev=831895&view=rev
Log:
Move NNTPServer components to guice injection (JAMES-893)
Added:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/AvalonNNTPRepository.java
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/AvalonNNTPServer.xinfo
- copied unchanged from r829709,
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/NNTPServer.xinfo
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/repository/AvalonNNTPRepository.xinfo
- copied unchanged from r829709,
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.xinfo
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/AvalonNNTPServerTest.java
Removed:
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/NNTPServer.xinfo
james/server/trunk/nntpserver-function/src/main/resources/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.xinfo
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPException.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
Added:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java?rev=831895&view=auto
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
(added)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
Mon Nov 2 13:38:23 2009
@@ -0,0 +1,168 @@
+/****************************************************************
+ * 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.apache.james.nntpserver;
+
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.api.kernel.LoaderService;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.james.nntpserver.repository.NNTPRepository;
+import org.apache.james.services.FileSystem;
+import org.apache.james.services.MailServer;
+import org.apache.james.socket.JamesConnectionManager;
+import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.util.ConfigurationAdapter;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
+public class AvalonNNTPServer implements GuiceInjected, Initializable,
Serviceable, Configurable, LogEnabled, NNTPServerMBean {
+
+ private FileSystem filesystem;
+ private MailServer mailserver;
+ private DNSService dns;
+ private Log logger;
+ private org.apache.commons.configuration.HierarchicalConfiguration config;
+ private Injector injector;
+ private UsersRepository userRepos;
+ private JamesConnectionManager connectionManager;
+ private SocketManager socketManager;
+ private NNTPServer nntpserver = new NNTPServer();
+ private NNTPRepository nntpRepos;
+ private ThreadManager threadManager;
+
+ public String getNetworkInterface() {
+ return nntpserver.getNetworkInterface();
+ }
+
+ public int getPort() {
+ return nntpserver.getPort();
+ }
+
+ public String getSocketType() {
+ return nntpserver.getSocketType();
+ }
+
+ public boolean isEnabled() {
+ return nntpserver.isEnabled();
+ }
+
+ /**
+ * @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ try {
+ this.config = new ConfigurationAdapter(config);
+ } catch (org.apache.commons.configuration.ConfigurationException e) {
+ throw new ConfigurationException("Unable to convert
configuration", e);
+ }
+ }
+
+ /**
+ * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ dns = (DNSService) manager.lookup(DNSService.ROLE);
+ mailserver = (MailServer) manager.lookup(MailServer.ROLE);
+ filesystem = (FileSystem) manager.lookup(FileSystem.ROLE);
+ userRepos = (UsersRepository) manager.lookup(UsersRepository.ROLE);
+ socketManager = (SocketManager) manager.lookup(SocketManager.ROLE);
+ connectionManager = (JamesConnectionManager)
manager.lookup(JamesConnectionManager.ROLE);
+ threadManager = (ThreadManager) manager.lookup(ThreadManager.ROLE);
+ nntpRepos = (NNTPRepository) manager.lookup(NNTPRepository.ROLE);
+ // thats needed because of used excalibur socket components
+ nntpserver.service(manager);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ injector = Guice.createInjector(new NNTPServerModule(), new
Jsr250Module());
+ injector.injectMembers(nntpserver);
+ }
+
+ /**
+ * @see
org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+ */
+ public void enableLogging(Logger logger) {
+ this.logger = new AvalonLogger(logger);
+ }
+
+ private final class NNTPServerModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+
bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns);
+
bind(MailServer.class).annotatedWith(Names.named("org.apache.james.services.MailServer")).toInstance(mailserver);
+
bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+
bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+
bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
+
bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
+
bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new
Provider<ProtocolHandlerFactory>() {
+
+ public ProtocolHandlerFactory get() {
+ return nntpserver;
+ }
+
+ });
+
bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
+
bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
+
bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);
+
bind(NNTPRepository.class).annotatedWith(Names.named("org.apache.james.nntpserver.repository.NNTPRepository")).toInstance(nntpRepos);
+ // we bind the LoaderService to an Provider to get sure everything
is there when the SMTPLoaderService get created.
+
bind(LoaderService.class).annotatedWith(Names.named("org.apache.james.LoaderService")).toProvider(new
Provider<LoaderService>() {
+
+ public LoaderService get() {
+ return new NNTPLoaderService();
+ }
+
+ // Mimic the loaderservice
+ class NNTPLoaderService implements LoaderService {
+ Injector injector = Guice.createInjector(new
NNTPServerModule(), new Jsr250Module());
+
+ public <T> T load(Class<T> type) {
+ return injector.getInstance(type);
+ }
+
+ }
+
+ });
+
+ }
+ }
+}
+
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPException.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPException.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPException.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPException.java
Mon Nov 2 13:38:23 2009
@@ -28,14 +28,10 @@
* Error Information is obtained by calling 'getMessage'
*
*/
+...@suppresswarnings("serial")
public class NNTPException extends RuntimeException {
/**
- * The encapsulated Throwable
- */
- private final Throwable t;
-
- /**
* Create an NNTPException with an error message and no
* encapsulated <code>Throwable</code>
*
@@ -43,7 +39,6 @@
*/
public NNTPException(String msg) {
super(msg);
- this.t = null;
}
/**
@@ -55,7 +50,6 @@
*/
public NNTPException(String msg,Throwable t) {
super(msg+((t!=null)?": "+t.toString():""));
- this.t = t;
}
/**
@@ -66,6 +60,5 @@
*/
public NNTPException(Throwable t) {
super(t.toString());
- this.t = t;
}
}
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
Mon Nov 2 13:38:23 2009
@@ -536,13 +536,13 @@
}
context.writeLoggedFlushedResponse("230 list of new articles by
message-id follows");
- Iterator groupIter =
theConfigData.getNNTPRepository().getMatchedGroups(wildmat);
+ Iterator<NNTPGroup> groupIter =
theConfigData.getNNTPRepository().getMatchedGroups(wildmat);
while ( groupIter.hasNext() ) {
- Iterator articleIter =
((NNTPGroup)(groupIter.next())).getArticlesSince(theDate);
+ Iterator<NNTPArticle> articleIter =
groupIter.next().getArticlesSince(theDate);
while (articleIter.hasNext()) {
StringBuilder iterBuffer =
new StringBuilder(64)
-
.append(((NNTPArticle)articleIter.next()).getUniqueID());
+ .append(articleIter.next().getUniqueID());
context.writeLoggedResponse(iterBuffer.toString());
}
}
@@ -575,7 +575,7 @@
context.writeLoggedFlushedResponse("501 Syntax error");
return;
}
- Iterator iter =
theConfigData.getNNTPRepository().getGroupsSince(theDate);
+ Iterator<NNTPGroup> iter =
theConfigData.getNNTPRepository().getGroupsSince(theDate);
context.writeLoggedFlushedResponse("231 list of new newsgroups
follows");
while ( iter.hasNext() ) {
NNTPGroup currentGroup = (NNTPGroup)iter.next();
@@ -687,10 +687,10 @@
}
}
- Iterator iter =
theConfigData.getNNTPRepository().getMatchedGroups(wildmat);
+ Iterator<NNTPGroup> iter =
theConfigData.getNNTPRepository().getMatchedGroups(wildmat);
context.writeLoggedFlushedResponse("215 list of newsgroups follows");
while ( iter.hasNext() ) {
- NNTPGroup theGroup = (NNTPGroup)iter.next();
+ NNTPGroup theGroup = iter.next();
if (isListNewsgroups) {
context.writeLoggedResponse(theGroup.getListNewsgroupsFormat());
} else {
@@ -1199,9 +1199,9 @@
context.writeLoggedFlushedResponse("211 list of article numbers
follow");
- Iterator iter = group.getArticles();
+ Iterator<NNTPArticle> iter = group.getArticles();
while (iter.hasNext()) {
- NNTPArticle article = (NNTPArticle)iter.next();
+ NNTPArticle article = iter.next();
context.writeLoggedResponse(article.getArticleNumber() + "");
}
context.writeLoggedFlushedResponse(".");
@@ -1472,7 +1472,7 @@
end = Integer.parseInt(range.substring(idx + 1));
}
}
- List list = new ArrayList();
+ List<NNTPArticle> list = new ArrayList<NNTPArticle>();
for ( int i = start ; i <= end ; i++ ) {
NNTPArticle article = group.getArticle(i);
if ( article != null ) {
Added:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/AvalonNNTPRepository.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/AvalonNNTPRepository.java?rev=831895&view=auto
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/AvalonNNTPRepository.java
(added)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/AvalonNNTPRepository.java
Mon Nov 2 13:38:23 2009
@@ -0,0 +1,115 @@
+/****************************************************************
+ * 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.apache.james.nntpserver.repository;
+
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.james.services.FileSystem;
+import org.apache.james.util.ConfigurationAdapter;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
+
+public class AvalonNNTPRepository implements NNTPRepository, GuiceInjected,
Configurable, Serviceable, LogEnabled, Initializable{
+
+ private NNTPRepository repos;
+ private FileSystem fs;
+ private AvalonLogger logger;
+ private ConfigurationAdapter config;
+
+ public void createArticle(InputStream in) {
+ repos.createArticle(in);
+ }
+
+ public NNTPArticle getArticleFromID(String id) {
+ return repos.getArticleFromID(id);
+ }
+
+ public Iterator<NNTPArticle> getArticlesSince(Date dt) {
+ return repos.getArticlesSince(dt);
+ }
+
+ public NNTPGroup getGroup(String groupName) {
+ return repos.getGroup(groupName);
+ }
+
+ public Iterator<NNTPGroup> getGroupsSince(Date dt) {
+ return repos.getGroupsSince(dt);
+ }
+
+ public Iterator<NNTPGroup> getMatchedGroups(String wildmat) {
+ return repos.getMatchedGroups(wildmat);
+ }
+
+ public String[] getOverviewFormat() {
+ return repos.getOverviewFormat();
+ }
+
+ public boolean isReadOnly() {
+ return repos.isReadOnly();
+ }
+
+ public void service(ServiceManager arg0) throws ServiceException {
+ fs = (FileSystem) arg0.lookup(FileSystem.ROLE);
+ }
+
+ public void enableLogging(Logger arg0) {
+ this.logger = new AvalonLogger(arg0);
+ }
+
+ public void initialize() throws Exception {
+ repos = Guice.createInjector(new Jsr250Module(), new AbstractModule() {
+
+ @Override
+ protected void configure() {
+
bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+
bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+
bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fs);
+ }
+ }).getInstance(NNTPRepositoryImpl.class);
+ }
+
+ /**
+ * @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ try {
+ this.config = new ConfigurationAdapter(config);
+ } catch (org.apache.commons.configuration.ConfigurationException e) {
+ throw new ConfigurationException("Unable to convert
configuration", e);
+ }
+ }
+
+}
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
Mon Nov 2 13:38:23 2009
@@ -150,7 +150,7 @@
FileInputStream fileStream = null;
try {
fileStream = new FileInputStream(articleFile);
- MailHeaders headers = new MailHeaders(fileStream);
+ //MailHeaders headers = new MailHeaders(fileStream);
byte[] readBuffer = new byte[1024];
int read = 0;
while ((read = fileStream.read(readBuffer)) > 0) {
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
Mon Nov 2 13:38:23 2009
@@ -21,28 +21,28 @@
package org.apache.james.nntpserver.repository;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.nntpserver.DateSinceFileFilter;
-import org.apache.james.util.io.AndFileFilter;
-import org.apache.james.util.io.ExtensionFileFilter;
-import org.apache.james.util.io.IOUtil;
-import org.apache.james.util.io.InvertedFileFilter;
-
import java.io.File;
import java.io.FileOutputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.james.nntpserver.DateSinceFileFilter;
+import org.apache.james.util.io.AndFileFilter;
+import org.apache.james.util.io.ExtensionFileFilter;
+import org.apache.james.util.io.IOUtil;
+import org.apache.james.util.io.InvertedFileFilter;
+
/**
* Group is represented by a directory.
* Articles are stored in files with the name of file == article number
*
*/
-class NNTPGroupImpl extends AbstractLogEnabled implements NNTPGroup {
+public class NNTPGroupImpl implements NNTPGroup {
/**
* The directory to which this group maps.
@@ -71,13 +71,16 @@
*/
private boolean articleRangeInfoCollected = false;
+ private Log logger;
+
/**
* The sole constructor for this particular NNTPGroupImpl.
*
* @param root the directory containing the articles
*/
- NNTPGroupImpl(File root) {
+ public NNTPGroupImpl(File root, Log logger) {
this.root = root;
+ this.logger = logger;
}
/**
@@ -234,8 +237,8 @@
lastArticle = artNum;
numOfArticles++;
}
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Copying message to:
"+articleFile.getAbsolutePath());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Copying message to: "+articleFile.getAbsolutePath());
}
FileOutputStream fout = null;
try {
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
Mon Nov 2 13:38:23 2009
@@ -21,15 +21,12 @@
package org.apache.james.nntpserver.repository;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.kernel.LoaderService;
+import org.apache.james.api.protocol.Configurable;
+import org.apache.james.api.protocol.LogEnabled;
import org.apache.james.nntpserver.DateSinceFileFilter;
import org.apache.james.nntpserver.NNTPException;
import org.apache.james.services.FileSystem;
@@ -48,16 +45,18 @@
import java.util.List;
import java.util.Set;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
/**
* NNTP Repository implementation.
*/
-public class NNTPRepositoryImpl extends AbstractLogEnabled
- implements NNTPRepository, Serviceable, Configurable, Initializable {
+public class NNTPRepositoryImpl implements NNTPRepository {
/**
* The configuration employed by this repository
*/
- private Configuration configuration;
+ private HierarchicalConfiguration configuration;
/**
* Whether the repository is read only
@@ -135,66 +134,87 @@
private HashMap<String,NNTPGroup> repositoryGroups = new
HashMap<String,NNTPGroup>();
/**
- * The service manager
- */
- private ServiceManager serviceManager;
-
- /**
* The fileSystem service
*/
private FileSystem fileSystem;
+ private Log logger;
+
+ private LoaderService loader;
+
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * Setter for the FileSystem dependency
+ *
+ * @param system filesystem service
+ */
+ @Resource(name="org.apache.james.services.FileSystem")
+ public void setFileSystem(FileSystem system) {
+ this.fileSystem = system;
+ }
+
+ @Resource(name="org.apache.james.LoaderService")
+ public void setLoaderService(LoaderService loader) {
+ this.loader = loader;
+ }
+
/**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
- public void configure( Configuration aConfiguration ) throws
ConfigurationException {
- configuration = aConfiguration;
- readOnly = configuration.getChild("readOnly").getValueAsBoolean(false);
- articleIDDomainSuffix = configuration.getChild("articleIDDomainSuffix")
- .getValue("foo.bar.sho.boo");
- rootPathString = configuration.getChild("rootPath").getValue(null);
+ @SuppressWarnings("unchecked")
+ private void configure() throws ConfigurationException {
+ readOnly = configuration.getBoolean("readOnly", false);
+ articleIDDomainSuffix =
configuration.getString("articleIDDomainSuffix", "foo.bar.sho.boo");
+ rootPathString = configuration.getString("rootPath", null);
if (rootPathString == null) {
throw new ConfigurationException("Root path URL is required.");
}
- tempPathString = configuration.getChild("tempPath").getValue(null);
+ tempPathString = configuration.getString("tempPath", null);
if (tempPathString == null) {
throw new ConfigurationException("Temp path URL is required.");
}
- articleIdPathString =
configuration.getChild("articleIDPath").getValue(null);
+ articleIdPathString = configuration.getString("articleIDPath", null);
if (articleIdPathString == null) {
throw new ConfigurationException("Article ID path URL is
required.");
}
- if (getLogger().isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
if (readOnly) {
- getLogger().debug("NNTP repository is read only.");
+ logger.debug("NNTP repository is read only.");
} else {
- getLogger().debug("NNTP repository is writeable.");
+ logger.debug("NNTP repository is writeable.");
}
- getLogger().debug("NNTP repository root path URL is " +
rootPathString);
- getLogger().debug("NNTP repository temp path URL is " +
tempPathString);
- getLogger().debug("NNTP repository article ID path URL is " +
articleIdPathString);
+ logger.debug("NNTP repository root path URL is " + rootPathString);
+ logger.debug("NNTP repository temp path URL is " + tempPathString);
+ logger.debug("NNTP repository article ID path URL is " +
articleIdPathString);
}
- Configuration newsgroupConfiguration =
configuration.getChild("newsgroups");
- definedGroupsOnly =
newsgroupConfiguration.getAttributeAsBoolean("only", false);
+ definedGroupsOnly = configuration.getBoolean("newsgroup...@only]",
false);
groupNameMap = new HashMap<String,String>();
- if ( newsgroupConfiguration != null ) {
- Configuration[] children =
newsgroupConfiguration.getChildren("newsgroup");
+ if ( configuration.getKeys("newsgroups").hasNext()) {
+ List<String> children =
configuration.getList("newsgroups.newsgroup");
if ( children != null ) {
- for ( int i = 0 ; i < children.length ; i++ ) {
- String groupName = children[i].getValue();
+ for ( int i = 0 ; i < children.size() ; i++ ) {
+ String groupName = children.get(i);
groupNameMap.put(groupName, groupName);
}
}
}
- getLogger().debug("Repository configuration done");
+ logger.debug("Repository configuration done");
}
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() throws Exception {
+ @PostConstruct
+ public void init() throws Exception {
- getLogger().debug("Starting initialize");
+ logger.debug("Starting initialize");
+ configure();
File articleIDPath = null;
try {
@@ -202,7 +222,7 @@
tempPath = fileSystem.getFile(tempPathString);
articleIDPath = fileSystem.getFile(articleIdPathString);
} catch (Exception e) {
- getLogger().fatalError(e.getMessage(), e);
+ logger.fatal(e.getMessage(), e);
throw e;
}
@@ -214,10 +234,10 @@
spool = createSpooler();
spool.setRepository(this);
spool.setArticleIDRepository(articleIDRepo);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("repository:readOnly=" + readOnly);
- getLogger().debug("repository:rootPath=" +
rootPath.getAbsolutePath());
- getLogger().debug("repository:tempPath=" +
tempPath.getAbsolutePath());
+ if (logger.isDebugEnabled()) {
+ logger.debug("repository:readOnly=" + readOnly);
+ logger.debug("repository:rootPath=" + rootPath.getAbsolutePath());
+ logger.debug("repository:tempPath=" + tempPath.getAbsolutePath());
}
if ( rootPath.exists() == false ) {
@@ -260,7 +280,7 @@
throw new ConfigurationException(errorBuffer.toString());
}
- getLogger().debug("repository initialization done");
+ logger.debug("repository initialization done");
}
/**
@@ -275,8 +295,8 @@
*/
public NNTPGroup getGroup(String groupName) {
if (definedGroupsOnly && groupNameMap.get(groupName) == null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(groupName + " is not a newsgroup hosted on
this server.");
+ if (logger.isDebugEnabled()) {
+ logger.debug(groupName + " is not a newsgroup hosted on this
server.");
}
return null;
}
@@ -286,12 +306,10 @@
groupToReturn = repositoryGroups.get(groupName);
if ((groupToReturn == null) && groupFile.exists() &&
groupFile.isDirectory() ) {
try {
- groupToReturn = new NNTPGroupImpl(groupFile);
- ContainerUtil.enableLogging(groupToReturn, getLogger());
- ContainerUtil.initialize(groupToReturn);
+ groupToReturn = new NNTPGroupImpl(groupFile, logger);
repositoryGroups.put(groupName, groupToReturn);
} catch (Exception e) {
- getLogger().error("Couldn't create group object.", e);
+ logger.error("Couldn't create group object.", e);
groupToReturn = null;
}
}
@@ -306,7 +324,7 @@
try {
return articleIDRepo.getArticle(this,id);
} catch(Exception ex) {
- getLogger().error("Couldn't get article " + id + ": ", ex);
+ logger.error("Couldn't get article " + id + ": ", ex);
return null;
}
}
@@ -351,8 +369,8 @@
class GroupFilter implements java.io.FilenameFilter {
public boolean accept(java.io.File dir, String name) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(((definedGroupsOnly ?
groupNameMap.containsKey(name) : true) ? "Accepting ": "Rejecting") + name);
+ if (logger.isDebugEnabled()) {
+ logger.debug(((definedGroupsOnly ?
groupNameMap.containsKey(name) : true) ? "Accepting ": "Rejecting") + name);
}
return definedGroupsOnly ? groupNameMap.containsKey(name) : true;
@@ -435,23 +453,7 @@
}
};
}
-
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager serviceManager) throws ServiceException
{
- this.serviceManager = serviceManager;
- setFileSystem((FileSystem) serviceManager.lookup(FileSystem.ROLE));
- }
-
- /**
- * Setter for the FileSystem dependency
- *
- * @param system filesystem service
- */
- public void setFileSystem(FileSystem system) {
- this.fileSystem = system;
- }
+
/**
* @see
org.apache.james.nntpserver.repository.NNTPRepository#getOverviewFormat()
@@ -463,24 +465,24 @@
/**
* Creates an instance of the spooler class.
*
- * TODO: This method doesn't properly implement the Avalon lifecycle.
*/
private NNTPSpooler createSpooler()
throws ConfigurationException {
String className = NNTPSpooler.class.getName();
- Configuration spoolerConfiguration = configuration.getChild("spool");
- try {
- // Must be a subclass of
org.apache.james.nntpserver.repository.NNTPSpooler
- className = spoolerConfiguration.getAttribute("class");
- } catch(ConfigurationException ce) {
- // Use the default class.
- }
+ HierarchicalConfiguration spoolerConfiguration =
configuration.configurationAt("spool");
+ // Must be a subclass of
org.apache.james.nntpserver.repository.NNTPSpooler
+ className = spoolerConfiguration.getString("[...@class]");
+
try {
- Object obj =
Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
- ContainerUtil.enableLogging(obj, getLogger());
- ContainerUtil.service(obj, serviceManager);
- ContainerUtil.configure(obj,
spoolerConfiguration.getChild("configuration"));
- ContainerUtil.initialize(obj);
+ Class<?> myClass =
Thread.currentThread().getContextClassLoader().loadClass(className);
+ Object obj = loader.load(myClass);
+ if (obj instanceof LogEnabled) {
+ ((LogEnabled) obj).setLog(logger);
+ }
+
+ if (obj instanceof Configurable) {
+ ((Configurable)
obj).configure(spoolerConfiguration.configurationAt("configuration"));
+ }
return (NNTPSpooler)obj;
} catch(ClassCastException cce) {
StringBuffer errorBuffer =
@@ -489,10 +491,10 @@
.append(className)
.append(" was not a subclass of
org.apache.james.nntpserver.repository.NNTPSpooler");
String errorString = errorBuffer.toString();
- getLogger().error(errorString, cce);
+ logger.error(errorString, cce);
throw new ConfigurationException(errorString, cce);
} catch(Exception ex) {
- getLogger().error("Spooler initialization failed",ex);
+ logger.error("Spooler initialization failed",ex);
throw new ConfigurationException("Spooler initialization
failed",ex);
}
}
Modified:
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
(original)
+++
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
Mon Nov 2 13:38:23 2009
@@ -21,19 +21,16 @@
package org.apache.james.nntpserver.repository;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.protocol.Configurable;
+import org.apache.james.api.protocol.LogEnabled;
import org.apache.james.services.FileSystem;
import org.apache.james.util.Lock;
import org.apache.james.util.io.IOUtil;
+import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;
import java.io.BufferedReader;
@@ -49,8 +46,7 @@
* Eats up inappropriate entries.
*
*/
-class NNTPSpooler extends AbstractLogEnabled
- implements Serviceable, Configurable, Initializable {
+public class NNTPSpooler implements Configurable, LogEnabled{
/**
* The array of spooler runnables, each associated with a Worker thread
@@ -77,23 +73,8 @@
*/
private FileSystem fileSystem;
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(final ServiceManager serviceManager)
- throws ServiceException {
- setFileSystem((FileSystem) serviceManager.lookup(FileSystem.ROLE));
- }
+ private Log logger;
- /**
- * @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure( Configuration configuration ) throws
ConfigurationException {
- int threadCount =
configuration.getChild("threadCount").getValueAsInteger(1);
- threadIdleTime =
configuration.getChild("threadIdleTime").getValueAsInteger(60 * 1000);
- spoolPathString = configuration.getChild("spoolPath").getValue();
- worker = new SpoolerRunnable[threadCount];
- }
/**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
@@ -114,13 +95,12 @@
throw new ConfigurationException(errorBuffer.toString());
}
} catch (Exception e) {
- getLogger().fatalError(e.getMessage(), e);
+ logger.fatal(e.getMessage(), e);
throw e;
}
for ( int i = 0 ; i < worker.length ; i++ ) {
- worker[i] = new SpoolerRunnable(threadIdleTime,spoolPath);
- ContainerUtil.enableLogging(worker[i], getLogger());
+ worker[i] = new SpoolerRunnable(threadIdleTime,spoolPath, logger);
}
// TODO: Replace this with a standard Avalon thread pool
@@ -165,7 +145,7 @@
* A static inner class that provides the body for the spool
* threads.
*/
- static class SpoolerRunnable extends AbstractLogEnabled implements
Runnable {
+ static class SpoolerRunnable implements Runnable {
private static final Lock lock = new Lock();
@@ -189,9 +169,12 @@
*/
private NNTPRepository repo;
- SpoolerRunnable(int threadIdleTime,File spoolPath) {
+ private Log logger;
+
+ SpoolerRunnable(int threadIdleTime,File spoolPath, Log logger) {
this.threadIdleTime = threadIdleTime;
this.spoolPath = spoolPath;
+ this.logger = logger;
}
/**
@@ -217,19 +200,19 @@
* if it loses it tries to lock and process the next article.
*/
public void run() {
- getLogger().debug(Thread.currentThread().getName() + " is the NNTP
spooler thread.");
+ logger.debug(Thread.currentThread().getName() + " is the NNTP
spooler thread.");
try {
while ( Thread.interrupted() == false ) {
String[] list = spoolPath.list();
- if (list.length > 0) getLogger().debug("Files to process:
"+list.length);
+ if (list.length > 0) logger.debug("Files to process:
"+list.length);
for ( int i = 0 ; i < list.length ; i++ ) {
if ( lock.lock(list[i]) ) {
File f = new
File(spoolPath,list[i]).getAbsoluteFile();
- getLogger().debug("Processing file:
"+f.getAbsolutePath());
+ logger.debug("Processing file:
"+f.getAbsolutePath());
try {
process(f);
} catch(Throwable ex) {
- getLogger().debug("Exception occured while
processing file: "+
+ logger.debug("Exception occured while
processing file: "+
f.getAbsolutePath(),ex);
} finally {
lock.unlock(list[i]);
@@ -262,7 +245,7 @@
.append(spoolFile.getAbsolutePath())
.append(",")
.append(spoolFile.getCanonicalPath());
- getLogger().debug(logBuffer.toString());
+ logger.debug(logBuffer.toString());
final MimeMessage msg;
String articleID;
// TODO: Why is this a block?
@@ -293,9 +276,9 @@
String[] idheader = msg.getHeader("Message-Id");
articleID = ((idheader != null && (idheader.length > 0))?
idheader[0] : null);
if ((articleID != null) && (
articleIDRepo.isExists(articleID))) {
- getLogger().debug("Message already exists: "+articleID);
+ logger.debug("Message already exists: "+articleID);
if (spoolFile.delete() == false)
- getLogger().error("Could not delete duplicate message
from spool: " + spoolFile.getAbsolutePath());
+ logger.error("Could not delete duplicate message from
spool: " + spoolFile.getAbsolutePath());
return;
}
if ( articleID == null || lineCount != null) {
@@ -319,10 +302,10 @@
StringTokenizer tokenizer = new
StringTokenizer(headers[i],",");
while ( tokenizer.hasMoreTokens() ) {
String groupName = tokenizer.nextToken().trim();
- getLogger().debug("Copying message to group:
"+groupName);
+ logger.debug("Copying message to group: "+groupName);
NNTPGroup group = repo.getGroup(groupName);
if ( group == null ) {
- getLogger().error("Couldn't add article with
article ID " + articleID + " to group " + groupName + " - group not found.");
+ logger.error("Couldn't add article with article ID
" + articleID + " to group " + groupName + " - group not found.");
continue;
}
@@ -339,7 +322,7 @@
articleIDRepo.addArticle(articleID,prop);
boolean delSuccess = spoolFile.delete();
if ( delSuccess == false ) {
- getLogger().error("Could not delete file: " +
spoolFile.getAbsolutePath());
+ logger.error("Could not delete file: " +
spoolFile.getAbsolutePath());
}
}
} // class SpoolerRunnable
@@ -349,7 +332,25 @@
*
* @param fileSystem fs
*/
+ @Resource(name="org.apache.james.services.FileSystem")
public void setFileSystem(FileSystem fileSystem) {
this.fileSystem = fileSystem;
}
+
+ /**
+ * @see
org.apache.james.api.protocol.Configurable#configure(org.apache.commons.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ int threadCount = config.getInt("threadCount", 1);
+ threadIdleTime = config.getInt("threadIdleTime", 60 * 1000);
+ spoolPathString = config.getString("spoolPath");
+ worker = new SpoolerRunnable[threadCount];
+ }
+
+ /**
+ * @see
org.apache.james.api.protocol.LogEnabled#setLog(org.apache.commons.logging.Log)
+ */
+ public void setLog(Log log) {
+ this.logger = log;
+ }
}
Added:
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/AvalonNNTPServerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/AvalonNNTPServerTest.java?rev=831895&view=auto
==============================================================================
---
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/AvalonNNTPServerTest.java
(added)
+++
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/AvalonNNTPServerTest.java
Mon Nov 2 13:38:23 2009
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.apache.james.nntpserver;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.test.mock.avalon.MockLogger;
+
+public class AvalonNNTPServerTest extends NNTPServerTest{
+
+ private AvalonNNTPServer server;
+ @Override
+ protected void setUp() throws Exception {
+ server = new AvalonNNTPServer();
+ setUpServiceManager();
+ ContainerUtil.enableLogging(server, new MockLogger());
+ ContainerUtil.service(server, serviceManager);
+ m_testConfiguration = new NNTPTestConfiguration(m_nntpListenerPort);
+ }
+
+ @Override
+ protected void finishSetUp(NNTPTestConfiguration testConfiguration)
+ throws Exception {
+ testConfiguration.init();
+ ContainerUtil.configure(server, testConfiguration);
+ ContainerUtil.initialize(server);
+ }
+
+ protected void tearDown() throws Exception {
+ if (m_nntpProtocol != null) {
+ m_nntpProtocol.sendCommand("quit");
+ m_nntpProtocol.disconnect();
+ }
+
+ ContainerUtil.dispose(m_mailServer);
+ }
+
+}
Modified:
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
---
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
(original)
+++
james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
Mon Nov 2 13:38:23 2009
@@ -55,17 +55,17 @@
import org.apache.james.util.ConfigurationAdapter;
public class NNTPServerTest extends TestCase {
- private int m_nntpListenerPort = Util.getNonPrivilegedPort();
+ protected int m_nntpListenerPort = Util.getNonPrivilegedPort();
private NNTPServer m_nntpServer;
- private FakeLoader serviceManager;
+ protected FakeLoader serviceManager;
private MockUsersRepository m_usersRepository;
- private NNTPTestConfiguration m_testConfiguration;
+ protected NNTPTestConfiguration m_testConfiguration;
private NNTPRepositoryImpl m_nntpRepos;
- private MockMailServer m_mailServer;
- private NNTPClient m_nntpProtocol;
+ protected MockMailServer m_mailServer;
+ protected NNTPClient m_nntpProtocol;
private SimpleConnectionManager connectionManager;
@@ -98,33 +98,36 @@
m_testConfiguration = new NNTPTestConfiguration(m_nntpListenerPort);
}
- private void finishSetUp(NNTPTestConfiguration testConfiguration)
+ protected void finishSetUp(NNTPTestConfiguration testConfiguration)
throws Exception {
testConfiguration.init();
m_nntpServer.setConfiguration(new
ConfigurationAdapter(testConfiguration));
m_nntpServer.init();
}
- private void setUpServiceManager() throws ServiceException {
+ protected void setUpServiceManager() throws ServiceException {
serviceManager = new FakeLoader();
m_usersRepository = new MockUsersRepository();
m_mailServer = new MockMailServer(m_usersRepository);
m_nntpRepos = new NNTPRepositoryImpl();
- m_nntpRepos.setFileSystem(new FileSystem() {
- private File base = new
File(System.getProperty("java.io.tmpdir"));
- public File getBasedir() throws FileNotFoundException {
- return base;
- }
-
- public File getFile(String fileURL) throws
FileNotFoundException {
- return null;
- }
-
- public InputStream getResource(String url) throws
IOException {
- return null;
- }
-
- });
+ FileSystem fs = new FileSystem() {
+ private File base = new File(System.getProperty("java.io.tmpdir"));
+ public File getBasedir() throws FileNotFoundException {
+ return base;
+ }
+
+ public File getFile(String fileURL) throws FileNotFoundException {
+ return null;
+ }
+
+ public InputStream getResource(String url) throws IOException {
+ return null;
+ }
+
+ };
+ serviceManager.put(FileSystem.ROLE, fs);
+
+ m_nntpRepos.setFileSystem(fs);
connectionManager = new SimpleConnectionManager();
ContainerUtil.enableLogging(connectionManager, new
MockLogger());
@@ -166,6 +169,7 @@
m_nntpProtocol.disconnect();
}
m_nntpServer.dispose();
+
ContainerUtil.dispose(m_mailServer);
super.tearDown();
Modified: james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml?rev=831895&r1=831894&r2=831895&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml Mon Nov
2 13:38:23 2009
@@ -185,7 +185,7 @@
</block>
<!-- NNTP Server -->
- <block name="nntpserver" class="org.apache.james.nntpserver.NNTPServer" >
+ <block name="nntpserver"
class="org.apache.james.nntpserver.AvalonNNTPServer" >
<provide name="localusersrepository"
role="org.apache.james.api.user.UsersRepository"/>
<provide name="sockets"
role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
@@ -202,7 +202,7 @@
</block>
<!-- NNTP Repository -->
- <block name="nntp-repository"
class="org.apache.james.nntpserver.repository.NNTPRepositoryImpl">
+ <block name="nntp-repository"
class="org.apache.james.nntpserver.repository.AvalonNNTPRepository">
<provide name="filesystem" role="org.apache.james.services.FileSystem" />
<proxy disable='true'/>
</block>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]